Compare commits

...

16 Commits

  1. 24
      commands.go
  2. 2
      discordEvents.go
  3. 38
      discordMessage.go
  4. 51
      tools/listen.go
  5. 2
      tools/runFunction.go
  6. 1
      types.go

24
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", "wl"},
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,19 @@ func Status(b BotCommand) bool { @@ -281,3 +289,19 @@ func Status(b BotCommand) bool {
go runPurge(b.Session)
return true
}
func WhitelistURL(b BotCommand) bool {
defer log.PanicSafe()
newURL := strings.TrimSpace(
strings.ReplaceAll(
strings.ReplaceAll(b.Message.Content, b.Command, ""),
"<@688025671968096341>", ""),
)
if len(newURL) > 0 {
config.WhitelistURLs = append(config.WhitelistURLs, newURL)
}
domains := strings.Join(config.WhitelistURLs, "\n")
b.Session.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("Current whitelisted domains: %+v", domains))
log.LogDebug(fmt.Sprintf("Current whitelisted domains: %+v", domains))
return true
}

2
discordEvents.go

@ -36,8 +36,6 @@ func guildMemberAdd(s *discordgo.Session, m *discordgo.GuildMemberAdd) { @@ -36,8 +36,6 @@ func guildMemberAdd(s *discordgo.Session, m *discordgo.GuildMemberAdd) {
config.Probations[m.User.ID] = time.Now()
log.LogDebug("Giving user monitor role")
s.GuildMemberRoleAdd(config.GuildID, m.User.ID, config.MonitorRole)
log.LogDebug("Sending Monitored message")
s.ChannelMessageSend(config.MonitorChann, fmt.Sprintf("Welcome %+v, you may PM me your verification, or I will ban you in an hour!\nSay \"!rules\" in this channel, without quotes for the rules. You may private/direct message me for verification instructions.\n\nYou will not be able to read/see other channels or users until you verify.", m.User.Mention()))
log.LogDebug("Calling saveConfig")
saveConfig()
}

38
discordMessage.go

@ -24,13 +24,8 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { @@ -24,13 +24,8 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
Parts: strings.Split(m.Content, " ")[2:],
})
}
if strings.Contains(m.Embeds[0].Description, "Bump done!") {
log.LogDebug("Finding string %+v", m.Embeds[0].Description)
re := regexp.MustCompile("<@(.*)>")
match := re.FindStringSubmatch(m.Embeds[0].Description)
activeInteraction(s, match[1])
config.LastBumper = match[1]
} else {
go bumpTimer(s)
}
return
@ -38,10 +33,12 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { @@ -38,10 +33,12 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
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)
}
@ -59,25 +56,36 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { @@ -59,25 +56,36 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
activeInteraction(s, m.Author.ID)
}
}
if strings.HasPrefix(m.Content, "!d bump") {
if time.Since(config.BumpTime) < 2*time.Hour {
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("Sorry, <@%+v> already claimed the bump. Better luck next time!", config.LastBumper))
return
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)
channel, err := s.Channel(m.ChannelID)
if err != nil {
s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("DELETED %+v [%+v]: %+v", m.Author.Mention(), m.ChannelID, m.Content))
} else {
s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("DELETED %+v [%+v]: %+v", m.Author.Mention(), channel.Name, m.Content))
}
}
go bumpTimer(s)
return
}
parts := strings.Split(m.Content, " ")
if strings.Contains(m.Content, s.State.User.ID) {
b := BotCommand{
Session: s,
Message: m,
Parts: strings.Split(m.Content, " ")[2:],
Parts: parts[2:],
}
log.LogDebug("%+v", b.Parts)
for _, cmd := range commands {
for _, keyword := range cmd.Keywords {
log.LogDebug("Checking if %+v contains %+v", m.Content, keyword)
if strings.Contains(m.Content, keyword) {
if strings.Contains(parts[1], keyword) {
log.LogDebug("%+v found!", keyword)
b.Command = keyword
if !cmd.RequiresAdmin {

51
tools/listen.go

@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
package tools
import (
"encoding/json"
"flag"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"github.com/bwmarrin/discordgo"
)
var (
token string
dg *discordgo.Session
guild string
)
func init() {
flag.StringVar(&token, "t", "", "Bot Token")
flag.StringVar(&guild, "g", "", "Guild ID")
flag.Parse()
}
func main() {
if token == "" {
fmt.Printf("No token provided. Please run: disgord-thanos -t <bot token>")
}
dg, _ = discordgo.New("Bot " + token)
dg.AddHandler(messageCreate)
_ = dg.Open()
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sc
dg.Close()
}
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
if guild != "" {
if m.GuildID != guild {
return
}
}
jsonMsg, err := json.Marshal(m)
if err != nil {
jsonMsg = append(jsonMsg, '0')
}
log.Printf("----------\n%+v: %+v\n\n%+v\n------------------------------\n\n", m.Author.Username, m.Content, string(jsonMsg))
}

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