Class: FuckBot::MessageResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/fuck_bot/message_resolver.rb

Constant Summary collapse

BAD_WORD_RESPONSE =
"Watch your language, <@%s>! «%s» is a bad word!".freeze

Instance Method Summary collapse

Constructor Details

#initialize(data, client) ⇒ MessageResolver

Returns a new instance of MessageResolver.



8
9
10
11
# File 'lib/fuck_bot/message_resolver.rb', line 8

def initialize(data, client)
  @data = data
  @client = client
end

Instance Method Details

#badObject



13
14
15
16
17
18
19
20
21
22
23
# 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

#callObject



37
38
39
40
41
42
43
# 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

#pingObject



31
32
33
34
35
# File 'lib/fuck_bot/message_resolver.rb', line 31

def ping
  return unless ping?

  send_response(:pong)
end

#statsObject



25
26
27
28
29
# File 'lib/fuck_bot/message_resolver.rb', line 25

def stats
  return unless stats?

  send_response(@client.store.to_stats)
end