@@ -47,6 +47,19 @@ class IrcBot extends Adapter
47
47
@bot .part channel, () ->
48
48
console .log (' left %s' , channel)
49
49
50
+ createUser : (channel , from ) ->
51
+ user = @ userForName from
52
+ unless user?
53
+ id = (new Date ().getTime () / 1000 ).toString ().replace (' .' ,' ' )
54
+ user = @ userForId id
55
+ user .name = from
56
+
57
+ if channel .match (/ ^ [&#] / )
58
+ user .room = channel
59
+ else
60
+ user .room = null
61
+ user
62
+
50
63
run : ->
51
64
self = @
52
65
@@ -92,18 +105,11 @@ class IrcBot extends Adapter
92
105
93
106
bot .addListener ' message' , (from , to , message ) ->
94
107
console .log " From #{ from } to #{ to} : #{ message} "
95
-
96
- user = self .userForName from
97
- unless user?
98
- id = (new Date ().getTime () / 1000 ).toString ().replace (' .' ,' ' )
99
- user = self .userForId id
100
- user .name = from
101
108
102
- if to . match ( / ^ [&#] / )
103
- user .room = to
109
+ user = self . createUser to, from
110
+ if user .room
104
111
console .log " #{ to} <#{ from } > #{ message} "
105
112
else
106
- user .room = null
107
113
console .log " msg <#{ from } > #{ message} "
108
114
109
115
self .receive new Robot.TextMessage (user, message)
@@ -116,6 +122,8 @@ class IrcBot extends Adapter
116
122
117
123
bot .addListener ' join' , (channel , who ) ->
118
124
console .log (' %s has joined %s' , who, channel)
125
+ user = self .createUser channel, who
126
+ self .receive new Robot.EnterMessage (user)
119
127
120
128
bot .addListener ' part' , (channel , who , reason ) ->
121
129
console .log (' %s has left %s: %s' , who, channel, reason)
@@ -137,4 +145,3 @@ class IrcResponse extends Robot.Response
137
145
138
146
exports .use = (robot ) ->
139
147
new IrcBot robot
140
-
0 commit comments