Compare commits

..

16 Commits

Author SHA1 Message Date
bd493223ca Clean up welcome messages 2022-08-12 17:04:12 -04:00
bdbc2a1196 Reconnect bumpTimer 2022-08-11 07:45:53 -04:00
5ae7a96c3e Show channel + author mention for removed messages 2022-08-11 07:41:30 -04:00
f5c59af2b4 Log deleted link 2022-08-09 13:57:40 -04:00
8af3e9656d No blank links 2022-08-09 13:49:46 -04:00
c2646ad280 Cleaning up commandwork 2022-08-09 13:45:38 -04:00
a93d4a727b Only look for commands directly after @Thanos 2022-08-09 13:31:46 -04:00
706c2b516b trim domain 2022-08-09 13:27:12 -04:00
efbe429824 trim domain 2022-08-09 13:26:53 -04:00
d68f027f42 Add domains to output 2022-08-09 13:24:05 -04:00
59926b6b9b Add domains to output 2022-08-09 13:19:25 -04:00
dc0bf186ae Add URL Whitelisting to Thanos since @MEE6 wants us to pay for it 2022-08-09 13:17:22 -04:00
d24ff86d68 Add URL Whitelisting to Thanos since @MEE6 wants us to pay for it 2022-08-09 13:13:19 -04:00
27d5cf3a62 Don't look for user in bump response 2022-05-13 07:30:39 -04:00
0c3f4ce74a Allow filtering by guild 2022-05-12 22:17:04 -04:00
6d42e0fa54 Add utility to listen to DiscordGo for debugging 2022-05-12 22:11:42 -04:00
6 changed files with 100 additions and 18 deletions

View File

@ -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 {
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
}

View File

@ -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()
}

View File

@ -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) {
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) {
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
}
go bumpTimer(s)
return
}
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))
}
}
}
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 Normal file
View File

@ -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))
}

View File

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

View File

@ -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