From 82a2db8dfa3a4b862221da703d4feb4a7214f1dc Mon Sep 17 00:00:00 2001 From: chotee Date: Sat, 20 Oct 2018 10:27:56 +0200 Subject: [PATCH 1/2] Renamed IRC message json field to 'msg' from 'who'. --- mqtt.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mqtt.go b/mqtt.go index 5d1855c..09a2046 100644 --- a/mqtt.go +++ b/mqtt.go @@ -54,7 +54,7 @@ func MqttSay(message, nick string) error { func MqttIrc(src, msg string) error { payload := map[string]interface{}{ "user": src, - "who": msg, + "msg": msg, } j, err := json.Marshal(payload) if err != nil { From f37b82dc200b1880cf2262e1d2223ee54a24027f Mon Sep 17 00:00:00 2001 From: chotee Date: Sat, 20 Oct 2018 10:36:28 +0200 Subject: [PATCH 2/2] added IRC quit event to MQTT output --- mqtt.go | 18 ++++++++++++++++++ simple.go | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/mqtt.go b/mqtt.go index 09a2046..d0e2e26 100644 --- a/mqtt.go +++ b/mqtt.go @@ -106,6 +106,24 @@ func MqttIrcPart(who string) error { }) } +func MqttIrcQuit(who string) error { + payload := map[string]interface{}{ + "quit": who, + } + j, err := json.Marshal(payload) + if err != nil { + return err + } + + // Publish a message. + return mqttcli.Publish(&client.PublishOptions{ + QoS: mqtt.QoS0, + // TODO: Channel hardcoded, should not relay privmsg and so on + TopicName: []byte("irc/techinc"), + Message: j, + }) +} + func MqttStop() { defer mqttcli.Terminate() } diff --git a/simple.go b/simple.go index 7e58b00..ce58e2c 100644 --- a/simple.go +++ b/simple.go @@ -234,6 +234,11 @@ func part(e *irc.Event) { go MqttIrcPart(e.Nick) } +func quit(e *irc.Event) { + // TODO CHANNEL + go MqttIrcQuit(e.Nick) +} + func privmsg(e *irc.Event) { user_or_chan := e.Arguments[0] @@ -291,6 +296,7 @@ func main() { irccon.AddCallback("PRIVMSG", privmsg) irccon.AddCallback("JOIN", join) irccon.AddCallback("PART", part) + irccon.AddCallback("QUIT", quit) err := irccon.Connect(serverssl) if err != nil { fmt.Printf("Err %s", err)