Skip to content
Merged
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
3 changes: 3 additions & 0 deletions discord/commands/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ func Archive(args []string, s *discordgo.Session, m *discordgo.MessageCreate) {
if !requireGroupMembership(m, "archive", allowedGroups) {
return
}
if !requireNotThread(s, m, "archive") {
return
}
if _, err := service.GetArchivedChannel(m.ChannelID); err == nil {
service.SendDisappearingMessage(m.ChannelID, fmt.Sprintf("<@%s> this channel is already archived.", m.Author.ID), commandReplyTTL)
return
Expand Down
19 changes: 19 additions & 0 deletions discord/commands/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ func requireGroupMembership(m *discordgo.MessageCreate, command string, allowedG
return false
}

// requireNotThread rejects commands run in a thread, forum post, or forum/media channel.
func requireNotThread(s *discordgo.Session, m *discordgo.MessageCreate, command string) bool {
channel, err := s.State.Channel(m.ChannelID)
if err != nil {
channel, err = s.Channel(m.ChannelID)
}
if err != nil {
logger.SugarLogger.Errorf("%s: failed to fetch channel %s: %v", command, m.ChannelID, err)
service.SendDisappearingMessage(m.ChannelID, fmt.Sprintf("<@%s> something went wrong, try again in a minute.", m.Author.ID), commandReplyTTL)
return false
}
switch channel.Type {
case discordgo.ChannelTypeGuildNewsThread, discordgo.ChannelTypeGuildPublicThread, discordgo.ChannelTypeGuildPrivateThread, discordgo.ChannelTypeGuildForum, discordgo.ChannelTypeGuildMedia:
service.SendDisappearingMessage(m.ChannelID, fmt.Sprintf("<@%s> `%s%s` can't be used in a thread.", m.Author.ID, config.DiscordPrefix, command), commandReplyTTL)
return false
}
return true
}

// readyOnce guards the startup sweep so a gateway reconnect (which also
// fires Ready) doesn't repeatedly kick the sweep. Subsequent reconnects
// are covered by the periodic cron + per-user event reconciles anyway.
Expand Down
3 changes: 3 additions & 0 deletions discord/commands/unarchive.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ func Unarchive(args []string, s *discordgo.Session, m *discordgo.MessageCreate)
if !requireGroupMembership(m, "unarchive", allowedGroups) {
return
}
if !requireNotThread(s, m, "unarchive") {
return
}

record, err := service.UnarchiveChannel(m.ChannelID)
if err != nil {
Expand Down
Loading