Browse Source

Add URL Whitelisting to Thanos since @MEE6 wants us to pay for it

master
Gregory Rudolph 2 years ago
parent
commit
d24ff86d68
Signed by: rudi
GPG Key ID: EF64F3CBD1A1EBDD
  1. 14
      commands.go
  2. 19
      discordMessage.go
  3. 2
      tools/listen.go
  4. 2
      tools/runFunction.go
  5. 1
      types.go

14
commands.go

@ -92,6 +92,14 @@ func setupCommands() { @@ -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 { @@ -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;
}

19
discordMessage.go

@ -25,21 +25,18 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { @@ -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) { @@ -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,

2
tools/listen.go

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
package main
package tools
import (
"encoding/json"

2
tools/runFunction.go

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
package main
package tools
import (
"flag"

1
types.go

@ -42,6 +42,7 @@ type Config struct { @@ -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

Loading…
Cancel
Save