Class: MadChatter::Actions::Rename

Inherits:
Base
  • Object
show all
Defined in:
lib/mad_chatter/actions/rename.rb

Constant Summary collapse

@@regex =
/\/nick (.+)/

Instance Method Summary collapse

Methods inherited from Base

inherited, #initialize

Methods included from Dsl

#on_message, #send_action, #send_json, #send_message, #send_status_message, #send_users_list, #stop_message_handling

Constructor Details

This class inherits a constructor from MadChatter::Actions::Base

Instance Method Details

#handle(message) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/mad_chatter/actions/rename.rb', line 7

def handle(message)
  if message.filtered_text =~ @@regex
    old_username = message.username
    username = parse_username(message.filtered_text)
    MadChatter::Users.update(message.token, username)
    send_status_message "#{old_username} is now known as #{username}"
    send_users_list
    stop_message_handling
  end
end

#parse_username(text) ⇒ Object



18
19
20
# File 'lib/mad_chatter/actions/rename.rb', line 18

def parse_username(text)
  @@regex.match(text).captures[0]
end