Add bulk delete

This commit is contained in:
Ben Visness 2021-08-26 19:58:41 -05:00
parent 719c0d230c
commit 042e9166fd
3 changed files with 36 additions and 3 deletions

View File

@ -559,6 +559,15 @@ func (bot *botInstance) processEventMsg(ctx context.Context, msg *GatewayMessage
} }
case "MESSAGE_DELETE": case "MESSAGE_DELETE":
bot.messageDelete(ctx, MessageDeleteFromMap(msg.Data)) bot.messageDelete(ctx, MessageDeleteFromMap(msg.Data))
case "MESSAGE_BULK_DELETE":
bulkDelete := MessageBulkDeleteFromMap(msg.Data)
for _, id := range bulkDelete.IDs {
bot.messageDelete(ctx, MessageDelete{
ID: id,
ChannelID: bulkDelete.ChannelID,
GuildID: bulkDelete.GuildID,
})
}
} }
return nil return nil

View File

@ -127,6 +127,29 @@ func MessageDeleteFromMap(m interface{}) MessageDelete {
} }
} }
// https://discord.com/developers/docs/topics/gateway#message-delete
type MessageBulkDelete struct {
IDs []string `json:"ids"`
ChannelID string `json:"channel_id"`
GuildID string `json:"guild_id"`
}
func MessageBulkDeleteFromMap(m interface{}) MessageBulkDelete {
mmap := m.(map[string]interface{})
iids := mmap["ids"].([]interface{})
ids := make([]string, len(iids))
for i, iid := range iids {
ids[i] = iid.(string)
}
return MessageBulkDelete{
IDs: ids,
ChannelID: mmap["channel_id"].(string),
GuildID: maybeString(mmap, "guild_id"),
}
}
type ChannelType int type ChannelType int
// https://discord.com/developers/docs/resources/channel#channel-object-channel-types // https://discord.com/developers/docs/resources/channel#channel-object-channel-types

View File

@ -16,7 +16,7 @@ stuff we need to worry about:
- ryan used to post everything in #projects for some reason - ryan used to post everything in #projects for some reason
real-time stuff: real-time stuff:
✔ - on new showcase message ✔ - on new showcase message
- always save the lightweight record - always save the lightweight record
- if we have permission, create a snippet - if we have permission, create a snippet
@ -24,10 +24,11 @@ real-time stuff:
- re-save the lightweight record and content as if it was new - re-save the lightweight record and content as if it was new
- create snippet, unconditionally???? (bug??) - create snippet, unconditionally???? (bug??)
- update snippet contents if the edit makes sense - update snippet contents if the edit makes sense
- on delete - on delete
- delete snippet if the user so desires - delete snippet if the user so desires
- delete the message records - delete the message records
✔ - on bulk delete
- same stuff
background stuff: background stuff:
- watch mode - watch mode