Module: MadChatter
- Defined in:
- lib/mad_chatter.rb,
lib/mad_chatter/user.rb,
lib/mad_chatter/config.rb,
lib/mad_chatter/server.rb,
lib/mad_chatter/actions.rb,
lib/mad_chatter/channel.rb,
lib/mad_chatter/message.rb,
lib/mad_chatter/version.rb,
lib/mad_chatter/extension.rb,
lib/mad_chatter/message_history.rb,
lib/mad_chatter/servers/em_websocket.rb,
lib/mad_chatter/message_listeners/code.rb,
lib/mad_chatter/message_listeners/nick.rb,
lib/mad_chatter/message_listeners/image.rb,
lib/mad_chatter/message_listeners/video.rb,
lib/mad_chatter/message_listeners/markdown.rb,
lib/mad_chatter/message_listeners/channel_commands.rb
Defined Under Namespace
Modules: Actions, Config, MessageListeners, Servers
Classes: Channel, Extension, Message, MessageHistory, Server, User
Constant Summary
collapse
- VERSION =
'0.3.4'
Class Method Summary
collapse
Class Method Details
.channels ⇒ Object
48
49
50
|
# File 'lib/mad_chatter.rb', line 48
def channels
@channels ||= []
end
|
.channels=(array) ⇒ Object
52
53
54
|
# File 'lib/mad_chatter.rb', line 52
def channels=(array)
@channels = array
end
|
.channels_list ⇒ Object
118
119
120
121
122
123
124
125
126
|
# File 'lib/mad_chatter.rb', line 118
def channels_list
channels_hash = channels.collect do |c|
{:id => c.id, :name => c.name }
end
JSON.generate({
type: 'channels',
json: channels_hash,
})
end
|
.find_channel_by_id(id) ⇒ Object
56
57
58
59
60
61
|
# File 'lib/mad_chatter.rb', line 56
def find_channel_by_id(id)
channels.each do |channel|
return channel if channel.id == id
end
return nil
end
|
.find_channel_by_name(name) ⇒ Object
63
64
65
66
67
68
|
# File 'lib/mad_chatter.rb', line 63
def find_channel_by_name(name)
channels.each do |channel|
return channel if channel.name == name
end
return nil
end
|
.find_user_by_token(token) ⇒ Object
41
42
43
44
45
46
|
# File 'lib/mad_chatter.rb', line 41
def find_user_by_token(token)
users.each do |user|
return user if user.token == token
end
return nil
end
|
.message_listeners ⇒ Object
70
71
72
|
# File 'lib/mad_chatter.rb', line 70
def message_listeners
@message_listeners ||= []
end
|
.message_listeners=(array) ⇒ Object
74
75
76
|
# File 'lib/mad_chatter.rb', line 74
def message_listeners=(array)
@message_listeners = array
end
|
.message_received(json) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/mad_chatter.rb', line 84
def message_received(json)
msg = JSON.parse(json)
if msg['token'].nil?
return end
message = MadChatter::Message.new('message', msg['message'], msg['token'], msg['channel'])
begin
message_listeners.each do |listener|
listener.message = message if listener.respond_to?('message=')
listener.handle(message)
end
send_message(message)
rescue RuntimeError
end
end
|
.send_channels_list ⇒ Object
111
112
113
114
115
116
|
# File 'lib/mad_chatter.rb', line 111
def send_channels_list
json = channels_list
users.each do |user|
user.send(json)
end
end
|
.send_message(message) ⇒ Object
105
106
107
108
109
|
# File 'lib/mad_chatter.rb', line 105
def send_message(message)
channels.each do |channel|
channel.send_message(message) if channel.id == message.channel
end
end
|
.users ⇒ Object
33
34
35
|
# File 'lib/mad_chatter.rb', line 33
def users
@users ||= []
end
|
.users=(array) ⇒ Object
37
38
39
|
# File 'lib/mad_chatter.rb', line 37
def users=(array)
@users = array
end
|