@@ -48,6 +48,19 @@ class IrcBot extends Adapter
48
48
49
49
self .receive new LeaveMessage (null )
50
50
51
+ createUser : (channel , from ) ->
52
+ user = @ userForName from
53
+ unless user?
54
+ id = (new Date ().getTime () / 1000 ).toString ().replace (' .' ,' ' )
55
+ user = @ userForId id
56
+ user .name = from
57
+
58
+ if channel .match (/ ^ [&#] / )
59
+ user .room = channel
60
+ else
61
+ user .room = null
62
+ user
63
+
51
64
kick : (channel , client , message ) ->
52
65
@bot .emit ' raw' ,
53
66
command : ' KICK'
@@ -103,17 +116,10 @@ class IrcBot extends Adapter
103
116
bot .addListener ' message' , (from , to , message ) ->
104
117
console .log " From #{ from } to #{ to} : #{ message} "
105
118
106
- user = self .userForName from
107
- unless user?
108
- id = (new Date ().getTime () / 1000 ).toString ().replace (' .' ,' ' )
109
- user = self .userForId id
110
- user .name = from
111
-
112
- if to .match (/ ^ [&#] / )
113
- user .room = to
119
+ user = self .createUser to, from
120
+ if user .room
114
121
console .log " #{ to} <#{ from } > #{ message} "
115
122
else
116
- user .room = null
117
123
console .log " msg <#{ from } > #{ message} "
118
124
119
125
self .receive new TextMessage (user, message)
@@ -127,14 +133,14 @@ class IrcBot extends Adapter
127
133
bot .addListener ' join' , (channel , who ) ->
128
134
console .log (' %s has joined %s' , who, channel)
129
135
130
- user = self .userForName who
131
- self .receive new EnterMessage (user)
136
+ user = self .createUser channel, who
137
+ self .receive new Robot. EnterMessage (user)
132
138
133
139
bot .addListener ' part' , (channel , who , reason ) ->
134
140
console .log (' %s has left %s: %s' , who, channel, reason)
135
141
136
- user = self .userForName who
137
- self .receive new LeaveMessage (user)
142
+ user = self .createUser channel, who
143
+ self .receive new Robot. LeaveMessage (user)
138
144
139
145
bot .addListener ' kick' , (channel , who , _by , reason ) ->
140
146
console .log (' %s was kicked from %s by %s: %s' , who, channel, _by, reason)
@@ -153,4 +159,3 @@ class IrcResponse extends Response
153
159
154
160
exports .use = (robot ) ->
155
161
new IrcBot robot
156
-
0 commit comments