From ba3f1a9f3cb228ac83f353d95052059cafc14758 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Wed, 12 Feb 2020 20:11:38 -0700 Subject: [PATCH] join rooms upon bot_owner request --- main.go | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/main.go b/main.go index e53d183..fb6facb 100644 --- a/main.go +++ b/main.go @@ -13,7 +13,7 @@ import ( ) func main() { - var username, password, userID, accessToken, server, db, avatar string + var username, password, userID, accessToken, server, db, avatar, botOwner string var key, value, get string var setup, doc bool @@ -120,6 +120,7 @@ func main() { username, _ = store.Get("username") accessToken, _ = store.Get("access_token") userID, _ = store.Get("user_id") + botOwner, _ = store.Get("bot_owner") } cli.SetCredentials(userID, accessToken) @@ -128,25 +129,18 @@ func main() { cli.Client = http.DefaultClient cli.Syncer = syncer - /* - // TODO: Add ability to join / part rooms + syncer.OnEventType("m.room.member", func(ev *gomatrix.Event) { + if ev.Sender == username { + return + } - if _, err := cli.JoinRoom("!tmCVBJAeuKjCfihUjb:cobryce.com", "", nil); err != nil { - log.Fatalln(err) + if ev.Sender == botOwner && ev.Content["membership"] == "invite" { + log.Printf("Joining %s (invite from %s)\n", ev.RoomID, ev.Sender) + if _, err := cli.JoinRoom(ev.RoomID, "", nil); err != nil { + log.Fatalln(err) + } } - if _, err := cli.JoinRoom("!sFPUeGfHqjiItcjNIN:matrix.org", "", nil); err != nil { - log.Fatalln(err) - } - if _, err := cli.JoinRoom("!ALCZnrYadLGSySIFZr:matrix.org", "", nil); err != nil { - log.Fatalln(err) - } - if _, err := cli.JoinRoom("!LTxJpLHtShMVmlpwmZ:tapenet.org", "", nil); err != nil { - log.Fatalln(err) - } - if _, err := cli.JoinRoom("!TjjamgVanKpNiswkoJ:pintobyte.com", "", nil); err != nil { - log.Fatalln(err) - } - */ + }) syncer.OnEventType("m.room.message", func(ev *gomatrix.Event) { if ev.Sender == username {