Compare commits
2 Commits
master
...
hkremer/re
Author | SHA1 | Date |
---|---|---|
Hopper Kremer | 5b8b01e31a | 4 years ago |
Hopper Kremer | 03bcca77f4 | 4 years ago |
15 changed files with 469 additions and 1008 deletions
@ -1,307 +0,0 @@ |
|||||||
package main |
|
||||||
|
|
||||||
import ( |
|
||||||
"fmt" |
|
||||||
"math/rand" |
|
||||||
"os" |
|
||||||
"path/filepath" |
|
||||||
"sort" |
|
||||||
"strconv" |
|
||||||
"strings" |
|
||||||
"time" |
|
||||||
|
|
||||||
"github.com/rudi9719/loggy" |
|
||||||
) |
|
||||||
|
|
||||||
func setupCommands() { |
|
||||||
reboot := Command{ |
|
||||||
Name: "Reboot", |
|
||||||
RequiresAdmin: true, |
|
||||||
Help: "Reboot me, requires token from logs.", |
|
||||||
Keywords: []string{"reboot", "re", "restart"}, |
|
||||||
Exec: Reboot, |
|
||||||
} |
|
||||||
commands = append(commands, reboot) |
|
||||||
|
|
||||||
bumpset := Command{ |
|
||||||
Name: "BumpSet", |
|
||||||
RequiresAdmin: true, |
|
||||||
Help: "Set the bump timer (requires time in minutes until next bump).", |
|
||||||
Keywords: []string{"bs", "bumpset", "bumps"}, |
|
||||||
Exec: BumpSet, |
|
||||||
} |
|
||||||
commands = append(commands, bumpset) |
|
||||||
|
|
||||||
retrieveVerification := Command{ |
|
||||||
Name: "Retrieve Verification", |
|
||||||
RequiresAdmin: true, |
|
||||||
Help: "Retrieve verification either by discord ID or by nickname", |
|
||||||
Keywords: []string{"veri", "verification", "retrieve"}, |
|
||||||
Exec: RetrieveVerification, |
|
||||||
} |
|
||||||
commands = append(commands, retrieveVerification) |
|
||||||
|
|
||||||
addQuote := Command{ |
|
||||||
Name: "Add Quote", |
|
||||||
RequiresAdmin: true, |
|
||||||
Keywords: []string{"quote", "addq", "q"}, |
|
||||||
Exec: AddQuote, |
|
||||||
} |
|
||||||
commands = append(commands, addQuote) |
|
||||||
|
|
||||||
snap := Command{ |
|
||||||
Name: "Snap", |
|
||||||
Help: "Trigger a purge!", |
|
||||||
RequiresAdmin: false, |
|
||||||
Keywords: []string{"snap", "purge", "sn"}, |
|
||||||
Exec: Snap, |
|
||||||
} |
|
||||||
commands = append(commands, snap) |
|
||||||
|
|
||||||
status := Command{ |
|
||||||
Name: "Status", |
|
||||||
RequiresAdmin: true, |
|
||||||
Help: "Show the current status of Thanos/Verifications and probations", |
|
||||||
Keywords: []string{"st", "status", "stats"}, |
|
||||||
Exec: Status, |
|
||||||
} |
|
||||||
commands = append(commands, status) |
|
||||||
|
|
||||||
listCommands := Command{ |
|
||||||
Name: "List Commands", |
|
||||||
RequiresAdmin: false, |
|
||||||
Keywords: []string{"help", "commands", "cmd", "cmds"}, |
|
||||||
Exec: Commands, |
|
||||||
} |
|
||||||
commands = append(commands, listCommands) |
|
||||||
|
|
||||||
debugLevel := Command{ |
|
||||||
Name: "Debug Level", |
|
||||||
RequiresAdmin: true, |
|
||||||
Keywords: []string{"debug"}, |
|
||||||
Exec: Debug, |
|
||||||
Help: "Set the log level for loggy", |
|
||||||
} |
|
||||||
commands = append(commands, debugLevel) |
|
||||||
|
|
||||||
activityReport := Command{ |
|
||||||
Name: "Activity Report", |
|
||||||
RequiresAdmin: false, |
|
||||||
Keywords: []string{"activity", "active", "list"}, |
|
||||||
Exec: ActivityReport, |
|
||||||
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 { |
|
||||||
defer log.PanicSafe() |
|
||||||
print := "Available commands:\n" |
|
||||||
for _, cmd := range commands { |
|
||||||
if cmd.RequiresAdmin { |
|
||||||
if isAdmin(b.Message.Member) { |
|
||||||
print += fmt.Sprintf("```%+v\n%+v\n%+v```\n", cmd.Name, cmd.Keywords, cmd.Help) |
|
||||||
} |
|
||||||
} else { |
|
||||||
print += fmt.Sprintf("```%+v\n%+v\n%+v```\n", cmd.Name, cmd.Keywords, cmd.Help) |
|
||||||
} |
|
||||||
} |
|
||||||
b.Session.ChannelMessageSend(b.Message.ChannelID, print) |
|
||||||
return true |
|
||||||
} |
|
||||||
|
|
||||||
func Debug(b BotCommand) bool { |
|
||||||
defer log.PanicSafe() |
|
||||||
level, err := strconv.Atoi(b.Parts[0]) |
|
||||||
if err != nil { |
|
||||||
return false |
|
||||||
} |
|
||||||
config.LogOpts.Level = loggy.LogLevel(level) |
|
||||||
log = loggy.NewLogger(config.LogOpts) |
|
||||||
return true |
|
||||||
} |
|
||||||
|
|
||||||
func Reboot(b BotCommand) bool { |
|
||||||
defer log.PanicSafe() |
|
||||||
if strings.Contains(b.Message.Content, rebootToken) { |
|
||||||
exit(b.Session) |
|
||||||
return true |
|
||||||
} |
|
||||||
return false |
|
||||||
} |
|
||||||
|
|
||||||
func ActivityReport(b BotCommand) bool { |
|
||||||
useCounter := true |
|
||||||
counterStop := 4 |
|
||||||
if len(b.Parts) > 0 { |
|
||||||
test, err := strconv.Atoi(b.Parts[0]) |
|
||||||
if err == nil { |
|
||||||
counterStop = test |
|
||||||
} else { |
|
||||||
useCounter = false |
|
||||||
} |
|
||||||
} |
|
||||||
statistics := "```" |
|
||||||
n := map[int][]string{} |
|
||||||
counter := 0 |
|
||||||
var a []int |
|
||||||
for k, v := range config.Activity { |
|
||||||
n[v] = append(n[v], k) |
|
||||||
} |
|
||||||
for k := range n { |
|
||||||
a = append(a, k) |
|
||||||
} |
|
||||||
sort.Sort(sort.Reverse(sort.IntSlice(a))) |
|
||||||
for _, k := range a { |
|
||||||
for _, s := range n[k] { |
|
||||||
if useCounter && counter == counterStop-1 { |
|
||||||
return true |
|
||||||
} |
|
||||||
user, err := b.Session.GuildMember(config.GuildID, s) |
|
||||||
if err == nil { |
|
||||||
statistics += fmt.Sprintf("\n%+v: %+v", user.User.Username, k) |
|
||||||
counter++ |
|
||||||
} else { |
|
||||||
log.LogErrorType(err) |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
statistics += "\n```" |
|
||||||
return true |
|
||||||
} |
|
||||||
|
|
||||||
func BumpSet(b BotCommand) bool { |
|
||||||
defer log.PanicSafe() |
|
||||||
bump = false |
|
||||||
timer, err := strconv.Atoi(b.Parts[0]) |
|
||||||
if err != nil { |
|
||||||
b.Session.ChannelMessageSend(b.Message.ChannelID, fmt.Sprintf("Unable to decode timer: %+v", b.Parts[0])) |
|
||||||
return false |
|
||||||
} |
|
||||||
config.BumpTime = time.Now().Add(time.Duration(timer) * time.Minute).Add(-2 * time.Hour) |
|
||||||
b.Session.ChannelMessageSend(b.Message.ChannelID, fmt.Sprintf("New last bump time: <t:%+v:t>, expecting next bump at <t:%+v:t>", config.BumpTime.Unix(), config.BumpTime.Add(2*time.Hour).Unix())) |
|
||||||
return true |
|
||||||
} |
|
||||||
|
|
||||||
func RetrieveVerification(b BotCommand) bool { |
|
||||||
defer log.PanicSafe() |
|
||||||
discordId := b.Parts[0] |
|
||||||
_, err := strconv.Atoi(discordId) |
|
||||||
if err != nil { |
|
||||||
discordId = idFromUsername(discordId) |
|
||||||
} |
|
||||||
user, err := b.Session.GuildMember(config.GuildID, discordId) |
|
||||||
if err != nil { |
|
||||||
log.LogErrorType(err) |
|
||||||
return false |
|
||||||
} |
|
||||||
|
|
||||||
matches, err := filepath.Glob(fmt.Sprintf("./verifications/*%+v*", discordId)) |
|
||||||
if err != nil { |
|
||||||
log.LogErrorType(err) |
|
||||||
return false |
|
||||||
} |
|
||||||
if len(matches) != 1 { |
|
||||||
b.Session.ChannelMessageSend(b.Message.ChannelID, fmt.Sprintf("Error finding verification for ID %+v", discordId)) |
|
||||||
return false |
|
||||||
} |
|
||||||
|
|
||||||
verificationImage, err := os.Open(matches[0]) |
|
||||||
if err != nil { |
|
||||||
log.LogErrorType(err) |
|
||||||
return false |
|
||||||
} |
|
||||||
msg := fmt.Sprintf("``` %+v\nJoined: %+v\n```", user.User.Username, user.JoinedAt) |
|
||||||
b.Session.ChannelFileSendWithMessage(b.Message.ChannelID, msg, matches[0], verificationImage) |
|
||||||
return true |
|
||||||
} |
|
||||||
|
|
||||||
func AddQuote(b BotCommand) bool { |
|
||||||
defer log.PanicSafe() |
|
||||||
quotes = append(quotes, strings.ReplaceAll(b.Message.Content, b.Command, "")) |
|
||||||
return true |
|
||||||
} |
|
||||||
|
|
||||||
func Snap(b BotCommand) bool { |
|
||||||
defer log.PanicSafe() |
|
||||||
go runPurge(b.Session) |
|
||||||
b.Session.ChannelMessageSend(config.AdminChannel, quotes[rand.Intn(len(quotes))]) |
|
||||||
return true |
|
||||||
} |
|
||||||
|
|
||||||
func Status(b BotCommand) bool { |
|
||||||
defer log.PanicSafe() |
|
||||||
status := fmt.Sprintf("Uptime: %+v\n", time.Since(startupTime)) |
|
||||||
status += fmt.Sprintf("Last active time: %+v\n", time.Since(lastActiveTime)) |
|
||||||
status += fmt.Sprintf("Last bump: <t:%+v:t>\n", config.BumpTime.Unix()) |
|
||||||
status += fmt.Sprintf("Last bumper: %+v\n", userFromID(config.LastBumper).Username) |
|
||||||
status += fmt.Sprintf("Bump needed: %+v\n", bump) |
|
||||||
if len(config.Unverified) > 0 { |
|
||||||
status += "Unverified users:\n" |
|
||||||
for k, v := range config.Unverified { |
|
||||||
uvUser := userFromID(k) |
|
||||||
status += fmt.Sprintf("\n%+v will be removed at <t:%+v:t>", uvUser.Username, v.Add(1*time.Hour).Unix()) |
|
||||||
} |
|
||||||
status += "\n" |
|
||||||
} else { |
|
||||||
status += "There are no unverified users.\n" |
|
||||||
} |
|
||||||
if len(config.Verifications) > 0 { |
|
||||||
status += "Pending verifications:\n" |
|
||||||
for _, v := range config.Verifications { |
|
||||||
status += fmt.Sprintf("%+v has submitted a verification.", v.Username) |
|
||||||
} |
|
||||||
status += "\n" |
|
||||||
} else { |
|
||||||
status += "There are no pending verifications.\n" |
|
||||||
} |
|
||||||
if len(config.Probations) > 0 { |
|
||||||
status += "\nThe following users are on probation: \n" |
|
||||||
for uid, join := range config.Probations { |
|
||||||
probationUser := userFromID(uid) |
|
||||||
status += fmt.Sprintf("%+v for until <t:%+v:t>\n", probationUser.Username, join.Add(2*time.Hour).Unix()) |
|
||||||
} |
|
||||||
status += "\n" |
|
||||||
} else { |
|
||||||
status += "There are no users on probation.\n" |
|
||||||
} |
|
||||||
b.Session.ChannelMessageSend(config.AdminChannel, status) |
|
||||||
statistics := "```" |
|
||||||
for k, v := range config.Stats { |
|
||||||
adminUser, err := b.Session.GuildMember(config.GuildID, k) |
|
||||||
if err == nil { |
|
||||||
statistics += fmt.Sprintf("\n%+v: %+v", adminUser.User.Username, v+1) |
|
||||||
} else { |
|
||||||
log.LogErrorType(err) |
|
||||||
} |
|
||||||
} |
|
||||||
statistics += "\n```" |
|
||||||
log.LogInfo("Private statistics: %+v", statistics) |
|
||||||
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 |
|
||||||
} |
|
@ -1,125 +0,0 @@ |
|||||||
package main |
|
||||||
|
|
||||||
import ( |
|
||||||
"fmt" |
|
||||||
"time" |
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo" |
|
||||||
) |
|
||||||
|
|
||||||
func ready(s *discordgo.Session, event *discordgo.Ready) { |
|
||||||
// Set the playing status.
|
|
||||||
s.UpdateGameStatus(0, fmt.Sprintf("DreamDaddy rev %+v", gitCommit)) |
|
||||||
} |
|
||||||
|
|
||||||
func guildMemberUpdate(s *discordgo.Session, m *discordgo.GuildMemberUpdate) { |
|
||||||
defer log.PanicSafe() |
|
||||||
log.LogDebug("Member %+v has been updated", m.User.Username) |
|
||||||
for _, role := range m.Roles { |
|
||||||
if fmt.Sprintf("%+v", role) == config.MonitorRole { |
|
||||||
log.LogDebug("Role found, Monitor Role") |
|
||||||
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())) |
|
||||||
config.Unverified[m.User.ID] = time.Now() |
|
||||||
config.Probations[m.User.ID] = time.Now() |
|
||||||
saveConfig() |
|
||||||
return |
|
||||||
} |
|
||||||
log.LogDebug("Monitor Role not found: %+v != %+v", fmt.Sprintf("%+v", role), config.MonitorRole) |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
func guildMemberAdd(s *discordgo.Session, m *discordgo.GuildMemberAdd) { |
|
||||||
defer log.PanicSafe() |
|
||||||
log.LogDebug("Adding user to Unverified and Probations") |
|
||||||
config.Unverified[m.User.ID] = time.Now() |
|
||||||
config.Probations[m.User.ID] = time.Now() |
|
||||||
log.LogDebug("Giving user monitor role") |
|
||||||
s.GuildMemberRoleAdd(config.GuildID, m.User.ID, config.MonitorRole) |
|
||||||
log.LogDebug("Calling saveConfig") |
|
||||||
saveConfig() |
|
||||||
} |
|
||||||
|
|
||||||
func guildMemberBanned(s *discordgo.Session, m *discordgo.GuildBanAdd) { |
|
||||||
defer log.PanicSafe() |
|
||||||
for uid := range config.Probations { |
|
||||||
if m.User.Email == uid { |
|
||||||
delete(config.Probations, uid) |
|
||||||
s.ChannelMessageDelete(config.IntroChann, introMsg[uid]) |
|
||||||
} |
|
||||||
} |
|
||||||
saveConfig() |
|
||||||
} |
|
||||||
|
|
||||||
func guildMemberRemove(s *discordgo.Session, m *discordgo.GuildMemberRemove) { |
|
||||||
defer log.PanicSafe() |
|
||||||
go runPurge(s) |
|
||||||
banned := false |
|
||||||
for uid, join := range config.Probations { |
|
||||||
if time.Since(join) < 2*time.Hour { |
|
||||||
if m.User.ID == uid { |
|
||||||
banned = true |
|
||||||
s.GuildBanCreateWithReason(config.GuildID, m.User.ID, fmt.Sprintf("Left within 2 hours of joining. %+v", time.Since(join)), 0) |
|
||||||
delete(config.Probations, uid) |
|
||||||
s.ChannelMessageDelete(config.IntroChann, introMsg[uid]) |
|
||||||
} |
|
||||||
} else { |
|
||||||
delete(config.Probations, uid) |
|
||||||
s.ChannelMessageDelete(config.IntroChann, introMsg[uid]) |
|
||||||
} |
|
||||||
} |
|
||||||
s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("%+v (@%+v) has left, ban: %+v", m.User.ID, m.User.Username, banned)) |
|
||||||
delete(config.Unverified, m.User.ID) |
|
||||||
for msg, v := range config.Verifications { |
|
||||||
if v.UserID == m.User.ID { |
|
||||||
delete(config.Verifications, msg) |
|
||||||
s.ChannelMessageDelete(config.IntroChann, introMsg[m.User.ID]) |
|
||||||
} |
|
||||||
} |
|
||||||
saveConfig() |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
func readReaction(s *discordgo.Session, m *discordgo.MessageReactionAdd) { |
|
||||||
defer log.PanicSafe() |
|
||||||
if m.ChannelID != config.AdminChannel || m.UserID == s.State.User.ID { |
|
||||||
return |
|
||||||
} |
|
||||||
admin, _ := s.GuildMember(config.GuildID, m.UserID) |
|
||||||
adminInteraction(s, admin.User.ID) |
|
||||||
verification, ok := config.Verifications[m.MessageID] |
|
||||||
if !ok { |
|
||||||
return |
|
||||||
} |
|
||||||
verification.Admin = admin.User.Username |
|
||||||
verification.Closed = time.Now() |
|
||||||
user := userFromID(verification.UserID) |
|
||||||
if user.ID == "" { |
|
||||||
s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("%+v, that user was not found, they might have left.", admin.Mention())) |
|
||||||
delete(config.Verifications, m.MessageID) |
|
||||||
return |
|
||||||
} |
|
||||||
if m.Emoji.Name == "👎" { |
|
||||||
rejectVerification(s, user) |
|
||||||
verification.Status = "Rejected" |
|
||||||
} else if m.Emoji.Name == "👍" { |
|
||||||
verifyMember(s, user) |
|
||||||
verification.Status = "Accepted" |
|
||||||
go storeVerification(verification) |
|
||||||
} else if m.Emoji.Name == "👶" { |
|
||||||
requestAge(s, user) |
|
||||||
log.LogInfo("%+v has requested ASL for user %+v.", admin.User.Username, user.Username) |
|
||||||
return |
|
||||||
} else if m.Emoji.Name == "🔄" { |
|
||||||
requestReupload(s, user) |
|
||||||
log.LogInfo("%+v has requested reupload for user %+v.", admin.User.Username, user.Username) |
|
||||||
return |
|
||||||
} else if m.Emoji.Name == "⛔" { |
|
||||||
s.GuildBanCreateWithReason(config.GuildID, user.ID, fmt.Sprintf("Underage, female, or too many failed verifications. %+v", admin.User.Username), 5) |
|
||||||
verification.Status = "Banned" |
|
||||||
} else { |
|
||||||
return |
|
||||||
} |
|
||||||
log.LogInfo("%+v", verification.prettyPrint()) |
|
||||||
delete(config.Verifications, m.MessageID) |
|
||||||
} |
|
@ -1,162 +0,0 @@ |
|||||||
package main |
|
||||||
|
|
||||||
import ( |
|
||||||
"fmt" |
|
||||||
"regexp" |
|
||||||
"strings" |
|
||||||
"time" |
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo" |
|
||||||
) |
|
||||||
|
|
||||||
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { |
|
||||||
defer log.PanicSafe() |
|
||||||
|
|
||||||
if m.Author.ID == "302050872383242240" && len(m.Embeds) > 0 { |
|
||||||
if strings.Contains(m.Embeds[0].Description, "minutes until the server can be bumped") { |
|
||||||
log.LogDebug("Failed bump detected") |
|
||||||
re := regexp.MustCompile("Please wait another (.*) minutes until the server can be bumped") |
|
||||||
match := re.FindStringSubmatch(m.Embeds[0].Description) |
|
||||||
m.Content = fmt.Sprintf("%+v bs %+v", s.State.User.Mention(), match[1]) |
|
||||||
BumpSet(BotCommand{ |
|
||||||
Message: m, |
|
||||||
Session: s, |
|
||||||
Parts: strings.Split(m.Content, " ")[2:], |
|
||||||
}) |
|
||||||
|
|
||||||
} else { |
|
||||||
go bumpTimer(s) |
|
||||||
} |
|
||||||
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) |
|
||||||
} |
|
||||||
|
|
||||||
if m.ChannelID == config.MonitorChann && !isAdmin(m.Member) { |
|
||||||
if strings.Contains(m.Content, "erif") && !m.Author.Bot { |
|
||||||
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("%+v send me a private message for verification.", m.Author.Mention())) |
|
||||||
} |
|
||||||
return |
|
||||||
} |
|
||||||
|
|
||||||
if m.ChannelID != config.AdminChannel { |
|
||||||
lastActiveTime = time.Now() |
|
||||||
if len(m.Attachments) > 0 { |
|
||||||
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, fmt.Sprintf("%+v: That domain is not approved by the admins. Please contact Admins if the domain should be whitelisted.", m.Author.Mention())) |
|
||||||
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: 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(parts[1], keyword) { |
|
||||||
log.LogDebug("%+v found!", keyword) |
|
||||||
b.Command = keyword |
|
||||||
if !cmd.RequiresAdmin { |
|
||||||
log.LogDebug("%+v does not require admin, running!", cmd.Name) |
|
||||||
if !cmd.Exec(b) { |
|
||||||
s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("There was an error running %+v\n%+v", cmd.Name, cmd.Help)) |
|
||||||
} else { |
|
||||||
log.LogInfo("Ran command %+v for %+v", cmd.Name, m.Author.Username) |
|
||||||
} |
|
||||||
} else { |
|
||||||
log.LogDebug("%+v does require admin, checking!", cmd.Name) |
|
||||||
if isAdmin(m.Member) { |
|
||||||
if !cmd.Exec(b) { |
|
||||||
s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("There was an error running %+v\n%+v", cmd.Name, cmd.Help)) |
|
||||||
} else { |
|
||||||
log.LogInfo("Ran command %+v for %+v", cmd.Name, m.Author.Username) |
|
||||||
} |
|
||||||
} else { |
|
||||||
log.LogInfo("%+v tried to run an admin command (%+v) but isn't an admin.", m.Author.Username, keyword) |
|
||||||
} |
|
||||||
} |
|
||||||
return |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
func handlePM(s *discordgo.Session, m *discordgo.MessageCreate) { |
|
||||||
defer log.PanicSafe() |
|
||||||
if strings.Contains(m.Content, "Rule") || strings.Contains(m.Content, "rule") { |
|
||||||
s.ChannelMessageSend(m.ChannelID, "I specifically said to say \"!rules\" (without quotes) in the _unverified_ channel for the rules - this is a PM :) .") |
|
||||||
} |
|
||||||
for _, uid := range config.Verifications { |
|
||||||
user := userFromID(uid.UserID) |
|
||||||
if m.Author.ID == user.ID { |
|
||||||
s.ChannelMessageSend(m.ChannelID, "Your verification is pending. An admin will respond to it when they are available.") |
|
||||||
s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("%+v said: %+v", m.Author.Mention(), m.Content)) |
|
||||||
return |
|
||||||
} |
|
||||||
} |
|
||||||
if len(m.Attachments) != 1 { |
|
||||||
s.ChannelMessageSend(m.ChannelID, "```I am a bot and this is an autoreply.\n\nUntil you send a verification, I will always say the following message:```\nYou may only send me your verification (and nothing else) to be passed to the admins (and no one else). Verification is a clear full face pic, with your pinky finger held to the corner of your mouth.") |
|
||||||
s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("%+v said: %+v", m.Author.Mention(), m.Content)) |
|
||||||
return |
|
||||||
} |
|
||||||
if strings.HasSuffix(strings.ToUpper(m.Attachments[0].ProxyURL), "HEIC") { |
|
||||||
s.ChannelMessageSend(m.ChannelID, "You have tried to send an unsupported file (HEIC). Please try again using an image (jpeg, jpg, png, etc).") |
|
||||||
return |
|
||||||
} |
|
||||||
if strings.HasSuffix(strings.ToUpper(m.Attachments[0].ProxyURL), "MP4") { |
|
||||||
s.ChannelMessageSend(m.ChannelID, "You have tried to send an unsupported file (MP4 Video). Please try again using an image (jpeg, jpg, png, etc).") |
|
||||||
return |
|
||||||
} |
|
||||||
if strings.HasSuffix(strings.ToUpper(m.Attachments[0].ProxyURL), "MP3") { |
|
||||||
s.ChannelMessageSend(m.ChannelID, "You have tried to send an unsupported file (MP3 Audio). Please try again using an image (jpeg, jpg, png, etc).") |
|
||||||
return |
|
||||||
} |
|
||||||
delete(config.Unverified, m.Author.ID) |
|
||||||
var v Verification |
|
||||||
v.Submitted = time.Now() |
|
||||||
v.UserID = m.Author.ID |
|
||||||
v.Username = m.Author.Username |
|
||||||
v.Photo = m.Attachments[0].ProxyURL |
|
||||||
v.Status = "Submitted" |
|
||||||
msg, _ := s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("%+v\n%+v", v.Username, v.Photo)) |
|
||||||
config.Verifications[msg.ID] = v |
|
||||||
s.MessageReactionAdd(config.AdminChannel, msg.ID, "👎") |
|
||||||
s.MessageReactionAdd(config.AdminChannel, msg.ID, "🔄") |
|
||||||
s.MessageReactionAdd(config.AdminChannel, msg.ID, "👍") |
|
||||||
s.MessageReactionAdd(config.AdminChannel, msg.ID, "👶") |
|
||||||
s.MessageReactionAdd(config.AdminChannel, msg.ID, "⛔") |
|
||||||
} |
|
@ -1,18 +0,0 @@ |
|||||||
module git.nightmare.haus/rudi/disgord-thanos |
|
||||||
|
|
||||||
go 1.21 |
|
||||||
|
|
||||||
require ( |
|
||||||
github.com/bwmarrin/discordgo v0.27.1 |
|
||||||
github.com/gorilla/mux v1.8.0 |
|
||||||
github.com/gorilla/sessions v1.2.1 |
|
||||||
github.com/rudi9719/loggy v0.0.0-20201031035735-9438c484de9a |
|
||||||
) |
|
||||||
|
|
||||||
require ( |
|
||||||
github.com/gorilla/securecookie v1.1.1 // indirect |
|
||||||
github.com/gorilla/websocket v1.5.0 // indirect |
|
||||||
golang.org/x/crypto v0.13.0 // indirect |
|
||||||
golang.org/x/sys v0.12.0 // indirect |
|
||||||
samhofi.us/x/keybase v1.0.0 // indirect |
|
||||||
) |
|
@ -1,26 +0,0 @@ |
|||||||
github.com/bwmarrin/discordgo v0.27.1 h1:ib9AIc/dom1E/fSIulrBwnez0CToJE113ZGt4HoliGY= |
|
||||||
github.com/bwmarrin/discordgo v0.27.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY= |
|
||||||
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= |
|
||||||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= |
|
||||||
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= |
|
||||||
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= |
|
||||||
github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI= |
|
||||||
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= |
|
||||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= |
|
||||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= |
|
||||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= |
|
||||||
github.com/rudi9719/loggy v0.0.0-20201031035735-9438c484de9a h1:4rkaWoLCWOmra5Mw/dLAWjtDLT/+i5uTX1qhlMVL8WA= |
|
||||||
github.com/rudi9719/loggy v0.0.0-20201031035735-9438c484de9a/go.mod h1:s1ANCN8bF6HwwTpJLR458MFVGua9oqKKDbph/2jptL4= |
|
||||||
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= |
|
||||||
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= |
|
||||||
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= |
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= |
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
|
||||||
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= |
|
||||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= |
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= |
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= |
|
||||||
samhofi.us/x/keybase v0.0.0-20200129212102-e05e93be9f3f/go.mod h1:fcva80IUFyWcHtV4bBSzgKg07K6Rvuvi3GtGCLNGkyE= |
|
||||||
samhofi.us/x/keybase v1.0.0 h1:ht//EtYMS/hQeZCznA1ibQ515JCKaEkvTD/tarw/9k8= |
|
||||||
samhofi.us/x/keybase v1.0.0/go.mod h1:fcva80IUFyWcHtV4bBSzgKg07K6Rvuvi3GtGCLNGkyE= |
|
@ -1,51 +0,0 @@ |
|||||||
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)) |
|
||||||
} |
|
Loading…
Reference in new issue