Skip to content
Open
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
4 changes: 4 additions & 0 deletions discord/commands/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func OnDiscordMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
logger.SugarLogger.Errorf("Failed to persist discord message: %v", err)
}

if enforceVerificationChannel(s, m) {
return
}
Comment thread
austeyen marked this conversation as resolved.

if !strings.HasPrefix(m.Content, config.DiscordPrefix) {
return
}
Expand Down
20 changes: 20 additions & 0 deletions discord/commands/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"fmt"
"net/url"
"strings"
"time"

"github.com/bwmarrin/discordgo"
Expand All @@ -13,6 +14,25 @@ import (

const verifyReplyTTL = 5 * time.Second

// enforceVerificationChannel deletes non-verification messages in
// DISCORD_VERIFICATION_CHANNEL and posts a disappearing reminder.
func enforceVerificationChannel(s *discordgo.Session, m *discordgo.MessageCreate) bool {
if config.DiscordVerificationChannel == "" || m.ChannelID != config.DiscordVerificationChannel {
return false
}
if strings.Contains(m.Content, "!verify") {
return false
}

_ = s.ChannelMessageDelete(m.ChannelID, m.ID)
service.SendDisappearingMessage(
m.ChannelID,
fmt.Sprintf("<@%s> please run `%sverify` to verify.", m.Author.ID, config.DiscordPrefix),
verifyReplyTTL,
)
return true
}
Comment thread
austeyen marked this conversation as resolved.

func Verify(args []string, s *discordgo.Session, m *discordgo.MessageCreate) {
defer s.ChannelMessageDelete(m.ChannelID, m.ID)

Expand Down
1 change: 1 addition & 0 deletions discord/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var DatabaseName = os.Getenv("DATABASE_NAME")
var DiscordToken = os.Getenv("DISCORD_TOKEN")
var DiscordGuild = os.Getenv("DISCORD_GUILD")
var DiscordPrefix = os.Getenv("DISCORD_PREFIX")
var DiscordVerificationChannel = os.Getenv("DISCORD_VERIFICATION_CHANNEL")

var WebBaseURL = os.Getenv("WEB_BASE_URL")

Expand Down
5 changes: 5 additions & 0 deletions discord/config/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ func Verify() {
DiscordPrefix = "d!"
logger.SugarLogger.Infof("DISCORD_PREFIX is not set, defaulting to %s", DiscordPrefix)
}
if DiscordVerificationChannel == "" {
logger.SugarLogger.Infoln("DISCORD_VERIFICATION_CHANNEL is not set — verification channel gate disabled")
} else {
logger.SugarLogger.Infof("DISCORD_VERIFICATION_CHANNEL set to %s", DiscordVerificationChannel)
}
if WebBaseURL == "" {
WebBaseURL = "http://localhost:10310"
logger.SugarLogger.Infof("WEB_BASE_URL is not set, defaulting to %s", WebBaseURL)
Expand Down
Loading