Skip to content

Commit df2b01d

Browse files
committed
Use the bees CreateEvent method in ircbee.go
Another example for the usage of the new CreateEvent method which comes in pretty handy.
1 parent ec9d479 commit df2b01d

1 file changed

Lines changed: 12 additions & 43 deletions

File tree

‎bees/ircbee/ircbee.go‎

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*
1717
* Authors:
1818
* Christian Muehlhaeuser <muesli@gmail.com>
19+
* Nicolas Martin <penguwin@penguwin.eu>
1920
*/
2021

2122
// Package ircbee is a Bee that can connect to an IRC server.
@@ -153,23 +154,12 @@ func (mod *IrcBee) statusChange(eventChan chan bees.Event, conn *irc.Conn, line
153154

154155
channel := line.Args[0]
155156
user := line.Src[:strings.Index(line.Src, "!")]
156-
ev := bees.Event{
157-
Bee: mod.Name(),
158-
Name: strings.ToLower(line.Cmd),
159-
Options: []bees.Placeholder{
160-
{
161-
Name: "channel",
162-
Type: "string",
163-
Value: channel,
164-
},
165-
{
166-
Name: "user",
167-
Type: "string",
168-
Value: user,
169-
},
170-
},
157+
158+
properties := map[string]interface{}{
159+
"channel": channel,
160+
"user": user,
171161
}
172-
eventChan <- ev
162+
eventChan <- mod.CreateEvent(strings.ToLower(line.Cmd), properties)
173163
}
174164

175165
// Run executes the Bee's event loop.
@@ -226,33 +216,12 @@ func (mod *IrcBee) Run(eventChan chan bees.Event) {
226216
user := line.Src[:strings.Index(line.Src, "!")]
227217
hostmask := line.Src[strings.Index(line.Src, "!")+2:]
228218

229-
ev := bees.Event{
230-
Bee: mod.Name(),
231-
Name: "message",
232-
Options: []bees.Placeholder{
233-
{
234-
Name: "channel",
235-
Type: "string",
236-
Value: channel,
237-
},
238-
{
239-
Name: "user",
240-
Type: "string",
241-
Value: user,
242-
},
243-
{
244-
Name: "hostmask",
245-
Type: "string",
246-
Value: hostmask,
247-
},
248-
{
249-
Name: "text",
250-
Type: "string",
251-
Value: msg,
252-
},
253-
},
254-
}
255-
eventChan <- ev
219+
eventChan <- mod.CreateEvent("message", map[string]interface{}{
220+
"channel": channel,
221+
"user": user,
222+
"hostmask": hostmask,
223+
"text": msg,
224+
})
256225
})
257226

258227
waitForDisconnect := false

0 commit comments

Comments
 (0)