class Sing
Public Instance Methods
Source
# File plugins/sing.rb, line 37 def execute(m, query) command = self.class.parse_command(query) return unless command channel = reply_channel_key(m) if command[:action] == :stop result = self.class.stop_session(channel, sessions: sessions_store) flood_safe_reply(m, result[:message], with_progress: false) return end session = self.class.begin_session(channel, sessions: sessions_store) @sing_delivery = { channel: channel, token: session[:token] } sing_reply(m, lookup(command[:query])) ensure @sing_delivery = nil end
Source
# File plugins/sing.rb, line 31 def fetch_json(url) RabbotHttp.fetch(url, user_agent: USER_AGENT) rescue OpenURI::HTTPError => e e.io.read if e.io end
Source
# File plugins/sing.rb, line 27 def lookup(query, fetch: method(:fetch_json)) self.class.lookup(query, fetch: fetch) end
Source
# File plugins/sing.rb, line 56 def reply_channel_key(message) if message.channel message.channel.name else message.user.nick end end
Source
# File plugins/sing.rb, line 78 def safe_reply(message, text, with_progress: :auto, skip_prefix_lines: 0, line_byte_limit: nil) return super unless @sing_delivery target = reply_target(message) pieces = reply_pieces( text, message: target, with_progress: with_progress, skip_prefix_lines: skip_prefix_lines, line_byte_limit: line_byte_limit ) return if pieces.empty? channel = @sing_delivery[:channel] token = @sing_delivery[:token] pieces.each_with_index do |piece, index| delay = FloodSafe::CHUNK_DELAY_SEC * index if delay.zero? next if self.class.session_stopped?(channel, token, sessions: sessions_store) target.reply(piece) else Timer(delay, shots: 1) do next if self.class.session_stopped?(channel, token, sessions: sessions_store) target.reply(piece) end end end end
Calls superclass method
FloodSafe#safe_reply
Source
# File plugins/sing.rb, line 64 def sessions_store self.class.sessions_store end
Source
# File plugins/sing.rb, line 68 def sing_reply(message, text) flood_safe_reply( message, text, with_progress: :auto, skip_prefix_lines: 1, line_byte_limit: self.class.scaled_line_byte_limit(outgoing_line_limit(message)) ) end