handlediscord: bridge guild delete
This commit is contained in:
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/rs/zerolog"
|
||||
"maunium.net/go/mautrix/bridgev2"
|
||||
"maunium.net/go/mautrix/bridgev2/networkid"
|
||||
"maunium.net/go/mautrix/bridgev2/simplevent"
|
||||
"maunium.net/go/mautrix/bridgev2/status"
|
||||
|
||||
"go.mau.fi/mautrix-discord/pkg/discordid"
|
||||
@@ -314,6 +315,22 @@ func (d *DiscordClient) syncGuilds(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// deleteGuildPortalSpace queues a remote event that deletes a guild space
|
||||
// (including children).
|
||||
func (d *DiscordClient) deleteGuildPortalSpace(ctx context.Context, guildID string) {
|
||||
log := zerolog.Ctx(ctx)
|
||||
log.Info().Msg("Unbridging guild by deleting the entire space")
|
||||
|
||||
d.connector.Bridge.QueueRemoteEvent(d.UserLogin, &simplevent.ChatDelete{
|
||||
EventMeta: simplevent.EventMeta{
|
||||
Type: bridgev2.RemoteEventChatDelete,
|
||||
PortalKey: d.guildPortalKeyFromID(guildID),
|
||||
},
|
||||
OnlyForMe: true,
|
||||
Children: true,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *DiscordClient) bridgeGuild(ctx context.Context, guildID string) error {
|
||||
log := zerolog.Ctx(ctx)
|
||||
|
||||
|
||||
@@ -242,6 +242,7 @@ func (d *DiscordClient) handleDiscordEvent(rawEvt any) {
|
||||
log := d.UserLogin.Log.With().Str("action", "handle discord event").
|
||||
Type("event_type", rawEvt).
|
||||
Logger()
|
||||
ctx := log.WithContext(d.UserLogin.Bridge.BackgroundCtx)
|
||||
|
||||
switch evt := rawEvt.(type) {
|
||||
case *discordgo.Ready:
|
||||
@@ -286,6 +287,13 @@ func (d *DiscordClient) handleDiscordEvent(rawEvt any) {
|
||||
// TODO case *discordgo.MessageReactionRemoveEmoji: (needs impl. in discordgo)
|
||||
case *discordgo.PresenceUpdate:
|
||||
return
|
||||
case *discordgo.GuildDelete:
|
||||
if evt.Unavailable {
|
||||
log.Warn().Str("guild_id", evt.ID).Msg("Guild became unavailable")
|
||||
// For now, leave the portals alone if the guild only went away due to an outage.
|
||||
return
|
||||
}
|
||||
d.deleteGuildPortalSpace(ctx, evt.ID)
|
||||
case *discordgo.Event:
|
||||
// For presently unknown reasons sometimes discordgo won't unmarshal
|
||||
// events into their proper corresponding structs.
|
||||
|
||||
Reference in New Issue
Block a user