From 6e9b6d0efb0dbdd591664f5739a670262634c386 Mon Sep 17 00:00:00 2001 From: Nicolas Martin Date: Thu, 20 Feb 2020 18:57:48 +0100 Subject: [PATCH] Use the bees CreateEvent method in ircbee.go Another example for the usage of the new CreateEvent method which comes in pretty handy. --- bees/ircbee/ircbee.go | 55 ++++++++++--------------------------------- 1 file changed, 12 insertions(+), 43 deletions(-) diff --git a/bees/ircbee/ircbee.go b/bees/ircbee/ircbee.go index 0a2ac4a5..5e360ca6 100644 --- a/bees/ircbee/ircbee.go +++ b/bees/ircbee/ircbee.go @@ -16,6 +16,7 @@ * * Authors: * Christian Muehlhaeuser + * Nicolas Martin */ // 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 channel := line.Args[0] user := line.Src[:strings.Index(line.Src, "!")] - ev := bees.Event{ - Bee: mod.Name(), - Name: strings.ToLower(line.Cmd), - Options: []bees.Placeholder{ - { - Name: "channel", - Type: "string", - Value: channel, - }, - { - Name: "user", - Type: "string", - Value: user, - }, - }, + + properties := map[string]interface{}{ + "channel": channel, + "user": user, } - eventChan <- ev + eventChan <- mod.CreateEvent(strings.ToLower(line.Cmd), properties) } // Run executes the Bee's event loop. @@ -226,33 +216,12 @@ func (mod *IrcBee) Run(eventChan chan bees.Event) { user := line.Src[:strings.Index(line.Src, "!")] hostmask := line.Src[strings.Index(line.Src, "!")+2:] - ev := bees.Event{ - Bee: mod.Name(), - Name: "message", - Options: []bees.Placeholder{ - { - Name: "channel", - Type: "string", - Value: channel, - }, - { - Name: "user", - Type: "string", - Value: user, - }, - { - Name: "hostmask", - Type: "string", - Value: hostmask, - }, - { - Name: "text", - Type: "string", - Value: msg, - }, - }, - } - eventChan <- ev + eventChan <- mod.CreateEvent("message", map[string]interface{}{ + "channel": channel, + "user": user, + "hostmask": hostmask, + "text": msg, + }) }) waitForDisconnect := false