Compare commits
16 Commits
6e1c27ca27
...
bd493223ca
| Author | SHA1 | Date | |
|---|---|---|---|
|
bd493223ca
|
|||
|
bdbc2a1196
|
|||
|
5ae7a96c3e
|
|||
|
f5c59af2b4
|
|||
|
8af3e9656d
|
|||
|
c2646ad280
|
|||
|
a93d4a727b
|
|||
|
706c2b516b
|
|||
|
efbe429824
|
|||
|
d68f027f42
|
|||
|
59926b6b9b
|
|||
|
dc0bf186ae
|
|||
|
d24ff86d68
|
|||
|
27d5cf3a62
|
|||
|
0c3f4ce74a
|
|||
|
6d42e0fa54
|
24
commands.go
24
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!",
|
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)
|
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 {
|
func Commands(b BotCommand) bool {
|
||||||
@ -281,3 +289,19 @@ func Status(b BotCommand) bool {
|
|||||||
go runPurge(b.Session)
|
go runPurge(b.Session)
|
||||||
return true
|
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
|
||||||
|
}
|
||||||
|
|||||||
@ -36,8 +36,6 @@ func guildMemberAdd(s *discordgo.Session, m *discordgo.GuildMemberAdd) {
|
|||||||
config.Probations[m.User.ID] = time.Now()
|
config.Probations[m.User.ID] = time.Now()
|
||||||
log.LogDebug("Giving user monitor role")
|
log.LogDebug("Giving user monitor role")
|
||||||
s.GuildMemberRoleAdd(config.GuildID, m.User.ID, config.MonitorRole)
|
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")
|
log.LogDebug("Calling saveConfig")
|
||||||
saveConfig()
|
saveConfig()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,13 +24,8 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||||||
Parts: strings.Split(m.Content, " ")[2:],
|
Parts: strings.Split(m.Content, " ")[2:],
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
} else {
|
||||||
if strings.Contains(m.Embeds[0].Description, "Bump done!") {
|
go bumpTimer(s)
|
||||||
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]
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -38,10 +33,12 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||||||
if m.Author.Bot || m.Author.ID == s.State.User.ID {
|
if m.Author.Bot || m.Author.ID == s.State.User.ID {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.GuildID == "" {
|
if m.GuildID == "" {
|
||||||
handlePM(s, m)
|
handlePM(s, m)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if isAdmin(m.Member) {
|
if isAdmin(m.Member) {
|
||||||
adminInteraction(s, m.Author.ID)
|
adminInteraction(s, m.Author.ID)
|
||||||
}
|
}
|
||||||
@ -59,25 +56,36 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||||||
activeInteraction(s, m.Author.ID)
|
activeInteraction(s, m.Author.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(m.Content, "!d bump") {
|
if strings.Contains(m.Content, "http") {
|
||||||
if time.Since(config.BumpTime) < 2*time.Hour {
|
safe := false
|
||||||
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("Sorry, <@%+v> already claimed the bump. Better luck next time!", config.LastBumper))
|
for _, testURL := range config.WhitelistURLs {
|
||||||
return
|
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) {
|
if strings.Contains(m.Content, s.State.User.ID) {
|
||||||
b := BotCommand{
|
b := BotCommand{
|
||||||
Session: s,
|
Session: s,
|
||||||
Message: m,
|
Message: m,
|
||||||
Parts: strings.Split(m.Content, " ")[2:],
|
Parts: parts[2:],
|
||||||
}
|
}
|
||||||
log.LogDebug("%+v", b.Parts)
|
log.LogDebug("%+v", b.Parts)
|
||||||
for _, cmd := range commands {
|
for _, cmd := range commands {
|
||||||
for _, keyword := range cmd.Keywords {
|
for _, keyword := range cmd.Keywords {
|
||||||
log.LogDebug("Checking if %+v contains %+v", m.Content, keyword)
|
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)
|
log.LogDebug("%+v found!", keyword)
|
||||||
b.Command = keyword
|
b.Command = keyword
|
||||||
if !cmd.RequiresAdmin {
|
if !cmd.RequiresAdmin {
|
||||||
|
|||||||
51
tools/listen.go
Normal file
51
tools/listen.go
Normal 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))
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package main
|
package tools
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
|||||||
1
types.go
1
types.go
@ -42,6 +42,7 @@ type Config struct {
|
|||||||
Verifications map[string]Verification
|
Verifications map[string]Verification
|
||||||
Probations map[string]time.Time
|
Probations map[string]time.Time
|
||||||
LogOpts loggy.LogOpts
|
LogOpts loggy.LogOpts
|
||||||
|
WhitelistURLs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verification struct used for storing and logging
|
// Verification struct used for storing and logging
|
||||||
|
|||||||
Reference in New Issue
Block a user