diff --git a/Gemfile.lock b/Gemfile.lock index c31a65e..f5234eb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,11 +11,12 @@ GEM minitest (>= 5.1) mutex_m tzinfo (~> 2.0) - async (2.4.0) + async (2.8.0) console (~> 1.10) + fiber-annotation io-event (~> 1.1) timers (~> 4.1) - async-io (1.34.3) + async-io (1.41.0) async async-websocket (0.8.0) async-io @@ -27,7 +28,8 @@ GEM deep_merge (~> 1.2, >= 1.2.1) dry-validation (~> 1.0, >= 1.0.0) connection_pool (2.4.1) - console (1.16.2) + console (1.23.3) + fiber-annotation fiber-local deep_merge (1.2.2) dotenv (2.8.1) @@ -53,7 +55,8 @@ GEM dry-logic (>= 1.4, < 2) dry-types (>= 1.7, < 2) zeitwerk (~> 2.6) - dry-types (1.7.1) + dry-types (1.7.2) + bigdecimal (~> 3.0) concurrent-ruby (~> 1.0) dry-core (~> 1.0) dry-inflector (~> 1.0) @@ -66,23 +69,23 @@ GEM dry-schema (>= 1.12, < 2) zeitwerk (~> 2.6) event_stream_parser (1.0.0) - faraday (2.7.12) - base64 - faraday-net_http (>= 2.0, < 3.1) - ruby2_keywords (>= 0.0.4) + faraday (2.9.0) + faraday-net_http (>= 2.0, < 3.2) faraday-mashify (0.1.1) faraday (~> 2.0) hashie faraday-multipart (1.0.4) multipart-post (~> 2) - faraday-net_http (3.0.2) + faraday-net_http (3.1.0) + net-http + fiber-annotation (0.2.0) fiber-local (1.0.0) foreman (0.87.2) gli (2.21.1) hashie (5.0.0) i18n (1.14.1) concurrent-ruby (~> 1.0) - io-event (1.1.6) + io-event (1.4.2) kgio (2.11.4) minitest (5.21.2) multi_json (1.15.0) @@ -90,6 +93,8 @@ GEM mustermann (3.0.0) ruby2_keywords (~> 0.0.1) mutex_m (0.2.0) + net-http (0.4.1) + uri rack (3.0.8) rack-protection (4.0.0) base64 (>= 0.1.0) @@ -99,7 +104,7 @@ GEM raindrops (0.20.1) redis (5.0.8) redis-client (>= 0.17.0) - redis-client (0.17.1) + redis-client (0.19.1) connection_pool ruby-openai (6.3.1) event_stream_parser (>= 0.3.0, < 2.0.0) @@ -134,11 +139,12 @@ GEM timers (4.3.5) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) unicorn (6.1.0) kgio (~> 2.6) raindrops (~> 0.7) - websocket-driver (0.7.5) + uri (0.13.0) + websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) zeitwerk (2.6.12) diff --git a/bot.rb b/bot.rb index ed2afe0..f7ca4bb 100644 --- a/bot.rb +++ b/bot.rb @@ -1,14 +1,14 @@ require 'slack-ruby-bot' require './app' - server = SlackRubyBot::Server.new( token: ENV['SLACK_API_TOKEN'], hook_handlers: { - message: [->(client, data) { - return if data.subtype == "channel_join" - return if data.subtype == "bot_message" + message: [lambda { |client, data| + return if data.subtype == 'channel_join' + return if data.subtype == 'bot_message' return if data.text =~ /\+\+|is up to [0-9]+ points!/ - entries = RedisConnection.pool.lrange("registered", 0, -1) + + entries = RedisConnection.pool.lrange('registered', 0, -1) uids = entries.select do |entry| data.text =~ /<@#{entry}>/ end @@ -18,40 +18,37 @@ uids.each do |uid| message = RedisConnection.pool.get(uid) - if message && c.fetch('enable', 1) == 1 - user_presence = App::Model::Store.get(uid) - user_presence["mention_histotry"] ||= [] - user_presence["mention_histotry"] = [] if user_presence["mention_histotry"].is_a?(Hash) - user_presence["mention_histotry"] << { - channel: data.channel, - user: data.user, - text: data.text && data.text.gsub(/<@#{uid}>/, ''), - event_ts: data.event_ts - } - App::Model::Store.set(uid, user_presence) + next unless message && c.fetch('enable', 1) == 1 - client.say(text: "自動応答: #{message}", channel: data.channel, - thread_ts: data.thread_ts - ) - end + user_presence = App::Model::Store.get(uid) + user_presence['mention_histotry'] ||= [] + user_presence['mention_histotry'] = [] if user_presence['mention_histotry'].is_a?(Hash) + user_presence['mention_histotry'] << { + channel: data.channel, + user: data.user, + text: data.text && data.text.gsub(/<@#{uid}>/, ''), + event_ts: data.event_ts + } + App::Model::Store.set(uid, user_presence) + + client.say(text: "自動応答: #{message}", channel: data.channel, + thread_ts: data.thread_ts) end }], - ping: [->(client, data) { - }], - pong: [->(client, data) { + ping: [lambda { |client, data| }], + pong: [lambda { |client, data| + }] } ) Thread.new do server = TCPServer.new('0.0.0.0', 1234) loop do - begin - sock = server.accept - line = sock.gets - sock.write("HTTP/1.0 200 OK\n\nok") - sock.close - end + sock = server.accept + line = sock.gets + sock.write("HTTP/1.0 200 OK\n\nok") + sock.close end end diff --git a/config.ru b/config.ru index 2f5b737..1ff550e 100644 --- a/config.ru +++ b/config.ru @@ -1,5 +1,5 @@ require 'sinatra' require_relative 'app' require_relative 'app/api' - +use Rack::RewindableInput::Middleware run App::Api