Skip to content

Bug/irc messages #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
6 changes: 6 additions & 0 deletions simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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)
Expand Down