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
2 changes: 2 additions & 0 deletions discord/commands/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ func OnDiscordMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
Archive(args, s, m)
case "unarchive":
Unarchive(args, s, m)
case "say":
Say(args, s, m)
default:
logger.SugarLogger.Infof("Unknown command: %s", command)
}
Expand Down
32 changes: 32 additions & 0 deletions discord/commands/say.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package commands

import (
"fmt"
"strings"

"github.com/bwmarrin/discordgo"
"github.com/gaucho-racing/sentinel/discord/config"
"github.com/gaucho-racing/sentinel/discord/pkg/logger"
"github.com/gaucho-racing/sentinel/discord/service"
)

// Say reposts a message as the bot, so announcements come from Sentinel
// rather than whoever typed them. The command message is always deleted,
// including when access is denied, so a failed attempt doesn't linger.
func Say(args []string, s *discordgo.Session, m *discordgo.MessageCreate) {
defer s.ChannelMessageDelete(m.ChannelID, m.ID)
if !requireGroupMembership(m, "say", []string{"Admins", "DevopsMembers"}) {
return
}
// Cut from the raw content rather than joining args, so line breaks and
// spacing in the announcement survive.
message := strings.TrimSpace(strings.TrimPrefix(m.Content, config.DiscordPrefix+"say"))
if message == "" {
service.SendDisappearingMessage(m.ChannelID, fmt.Sprintf("<@%s> usage: `%ssay <message>`", m.Author.ID, config.DiscordPrefix), commandReplyTTL)
return
}
if _, err := s.ChannelMessageSend(m.ChannelID, message); err != nil {
logger.SugarLogger.Errorf("say: failed to send in %s: %v", m.ChannelID, err)
service.SendDisappearingMessage(m.ChannelID, fmt.Sprintf("<@%s> couldn't send that message — check the logs.", m.Author.ID), commandReplyTTL)
}
}
Loading