From 71d168977617fb093f268b24438956de78fb9c41 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 27 Feb 2023 01:12:06 +0200 Subject: [PATCH] Adjust some calls for bot accounts --- portal.go | 4 ++++ thread.go | 7 ++++++- user.go | 25 ++++++++++++++----------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/portal.go b/portal.go index 735cbec..4ff569f 100644 --- a/portal.go +++ b/portal.go @@ -1548,6 +1548,10 @@ func (portal *Portal) HandleMatrixReadReceipt(brUser bridge.User, eventID id.Eve return } } + if !sender.Session.IsUser { + // Drop read receipts from bot users (after checking for the thread auto-join stuff) + return + } msg := portal.bridge.DB.Message.GetByMXID(portal.Key, eventID) if msg == nil { msg = portal.bridge.DB.Message.GetClosestBefore(portal.Key, discordThreadID, receipt.Timestamp) diff --git a/thread.go b/thread.go index 5b0437b..b775d9f 100644 --- a/thread.go +++ b/thread.go @@ -79,7 +79,12 @@ func (thread *Thread) Join(user *User) { return } user.log.Debugfln("Joining thread %s@%s", thread.ID, thread.ParentID) - err := user.Session.ThreadJoinWithLocation(thread.ID, discordgo.ThreadJoinLocationContextMenu) + var err error + if user.Session.IsUser { + err = user.Session.ThreadJoinWithLocation(thread.ID, discordgo.ThreadJoinLocationContextMenu) + } else { + err = user.Session.ThreadJoin(thread.ID) + } if err != nil { user.log.Errorfln("Error joining thread %s@%s: %v", thread.ID, thread.ParentID, err) } else { diff --git a/user.go b/user.go index 73b27d8..af4a50a 100644 --- a/user.go +++ b/user.go @@ -562,8 +562,6 @@ func (user *User) Connect() error { user.Session.AddHandler(user.interactionSuccessHandler) - user.Session.Identify.Presence.Status = "online" - return user.Session.Open() } @@ -637,6 +635,9 @@ func (user *User) readyHandler(_ *discordgo.Session, r *discordgo.Ready) { } func (user *User) subscribeGuilds(delay time.Duration) { + if !user.Session.IsUser { + return + } for _, guildMeta := range user.Session.State.Guilds { guild := user.bridge.GetGuildByID(guildMeta.ID, false) if guild != nil && guild.MXID != "" { @@ -1172,15 +1173,17 @@ func (user *User) bridgeGuild(guildID string, everything bool) error { } guild.Update() - user.log.Debugfln("Subscribing to guild %s after bridging", guild.ID) - err = user.Session.SubscribeGuild(discordgo.GuildSubscribeData{ - GuildID: guild.ID, - Typing: true, - Activities: true, - Threads: true, - }) - if err != nil { - user.log.Warnfln("Failed to subscribe to %s: %v", guild.ID, err) + if user.Session.IsUser { + user.log.Debugfln("Subscribing to guild %s after bridging", guild.ID) + err = user.Session.SubscribeGuild(discordgo.GuildSubscribeData{ + GuildID: guild.ID, + Typing: true, + Activities: true, + Threads: true, + }) + if err != nil { + user.log.Warnfln("Failed to subscribe to %s: %v", guild.ID, err) + } } return nil