Class: MadChatter::MessageListeners::ChannelCommands
- Inherits:
-
Object
- Object
- MadChatter::MessageListeners::ChannelCommands
show all
- Includes:
- Actions
- Defined in:
- lib/mad_chatter/message_listeners/channel_commands.rb
Instance Method Summary
collapse
Methods included from Actions
#send_action, #send_message, #send_status_message, #stop_message_handling
Instance Method Details
#handle(message) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/mad_chatter/message_listeners/channel_commands.rb', line 7
def handle(message)
@message = message
case @message.text
when '/join'
join_channel
stop_message_handling
when %r{^/channel create}
create_channel
stop_message_handling
when %r{^/channel rename}
rename_channel
stop_message_handling
end
end
|
#join_channel ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/mad_chatter/message_listeners/channel_commands.rb', line 22
def join_channel
user = MadChatter.find_user_by_token(@message.token)
unless user && @message.channel
stop_message_handling end
channel = MadChatter.find_channel_by_id(@message.channel)
unless channel
stop_message_handling end
channel.add_user(user)
end
|
#rename_channel ⇒ Object
44
45
46
47
48
49
|
# File 'lib/mad_chatter/message_listeners/channel_commands.rb', line 44
def rename_channel
channel_name = %r{^/channel rename (.+)}.match(@message.text).captures[0]
channel = MadChatter.find_channel_by_id(@message.channel)
channel.name = channel_name
MadChatter.send_channels_list
end
|