diff --git a/commands.go b/commands.go index 6e59d51..1aaf904 100644 --- a/commands.go +++ b/commands.go @@ -92,6 +92,14 @@ func setupCommands() { Help: "List activity for the discord. Supply a number to get the top N users (5 would be top 5 users) or all for all users!", } commands = append(commands, activityReport) + urlWhitelist := Command{ + Name: "Whitelist URL", + RequiresAdmin: true, + Keywords: []string{"whitelist"}, + Exec: WhitelistURL, + Help: "Add a domain to the HTTP whitelist domains are in the format `thisvid.com` without the subdomain.", + } + commands = append(commands, urlWhitelist) } func Commands(b BotCommand) bool { @@ -281,3 +289,9 @@ func Status(b BotCommand) bool { go runPurge(b.Session) return true } + +func WhitelistURL(b BotCommand) bool { + defer log.PanicSafe() + config.WhitelistURLs = append(config.WhitelistURLs, strings.ReplaceAll(b.Message.Content, b.Command, "")) + return true; +} \ No newline at end of file diff --git a/discordMessage.go b/discordMessage.go index 0819771..5abc60a 100644 --- a/discordMessage.go +++ b/discordMessage.go @@ -25,21 +25,18 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { }) } - if strings.Contains(m.Embeds[0].Description, "Bump done!") { - log.LogDebug("Finding string %+v", m.Embeds[0].Description) - go bumpTimer() - return - } return } if m.Author.Bot || m.Author.ID == s.State.User.ID { return } + if m.GuildID == "" { handlePM(s, m) return } + if isAdmin(m.Member) { adminInteraction(s, m.Author.ID) } @@ -57,6 +54,18 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { activeInteraction(s, m.Author.ID) } } + if strings.Contains(m.Content, "http") { + safe := false + for _, testURL := range config.WhitelistURLs { + if strings.Contains(m.Content, testURL) { + safe = true + } + } + if !safe { + s.ChannelMessageSend(m.ChannelID, "That domain is not approved by the admins. Please contact Admins if the domain should be whitelisted.") + s.ChannelMessageDelete(m.ChannelID, m.ID) + } + } if strings.Contains(m.Content, s.State.User.ID) { b := BotCommand{ Session: s, diff --git a/tools/listen.go b/tools/listen.go index 75eec4f..0ea3f87 100644 --- a/tools/listen.go +++ b/tools/listen.go @@ -1,4 +1,4 @@ -package main +package tools import ( "encoding/json" diff --git a/tools/runFunction.go b/tools/runFunction.go index 7262c5f..d6e1969 100644 --- a/tools/runFunction.go +++ b/tools/runFunction.go @@ -1,4 +1,4 @@ -package main +package tools import ( "flag" diff --git a/types.go b/types.go index 95d911e..75e7956 100644 --- a/types.go +++ b/types.go @@ -42,6 +42,7 @@ type Config struct { Verifications map[string]Verification Probations map[string]time.Time LogOpts loggy.LogOpts + WhitelistURLs []string } // Verification struct used for storing and logging