class FuckBot::MessageResolver
Constants
- BAD_WORD_RESPONSE
Public Class Methods
new(data, client)
click to toggle source
# File lib/fuck_bot/message_resolver.rb, line 8 def initialize(data, client) @data = data @client = client end
Public Instance Methods
bad()
click to toggle source
# File lib/fuck_bot/message_resolver.rb, line 13 def bad found_bad_word = find_bad_word return unless found_bad_word @client.store.increment(@data['user']).save send_response( format(BAD_WORD_RESPONSE, @data['user'], found_bad_word) ) end
call()
click to toggle source
# File lib/fuck_bot/message_resolver.rb, line 37 def call return unless text_message? && !self? rules.each do |rule| break if public_send(rule) end end
ping()
click to toggle source
# File lib/fuck_bot/message_resolver.rb, line 31 def ping return unless ping? send_response(:pong) end
stats()
click to toggle source
# File lib/fuck_bot/message_resolver.rb, line 25 def stats return unless stats? send_response(@client.store.to_stats) end
Private Instance Methods
find_bad_word()
click to toggle source
# File lib/fuck_bot/message_resolver.rb, line 67 def find_bad_word text = @data['text'].mb_chars.downcase.to_s FuckBot::Dictionary.instance.words.find do |word| text.include?(word) end end
generate_id()
click to toggle source
# File lib/fuck_bot/message_resolver.rb, line 86 def generate_id (Time.now.to_f * 100_000).to_i end
ping?()
click to toggle source
# File lib/fuck_bot/message_resolver.rb, line 59 def ping? @data['text'] == "<@#{@client.user['id']}>: ping" end
rules()
click to toggle source
# File lib/fuck_bot/message_resolver.rb, line 47 def rules self.class.instance_methods(false) - [:call] end
self?()
click to toggle source
# File lib/fuck_bot/message_resolver.rb, line 63 def self? @data['user'] == @client.user['id'] end
send_response(text)
click to toggle source
# File lib/fuck_bot/message_resolver.rb, line 75 def send_response(text) @client.ws.send( Oj.dump( id: generate_id, type: :message, channel: @data['channel'], text: text ) ) end
stats?()
click to toggle source
# File lib/fuck_bot/message_resolver.rb, line 55 def stats? @data['text'] == "<@#{@client.user['id']}>: stats" end
text_message?()
click to toggle source
# File lib/fuck_bot/message_resolver.rb, line 51 def text_message? @data['type'] == 'message' && !@data['text'].to_s.empty? end