25 Commits

Author SHA1 Message Date
87939c32ef Update deps 2023-09-15 13:22:24 -04:00
fcc806eb77 Remove deprecated io/ioutil import and calls 2023-09-15 13:14:05 -04:00
dd433f44ad Formatting 2023-09-15 13:12:57 -04:00
99e6f7066b Formatting 2023-09-15 13:12:25 -04:00
139d378d1a Remove deprecated io/ioutil import and calls 2023-09-15 13:11:06 -04:00
bddd283127 Formatting 2023-09-15 13:10:01 -04:00
31ca1cb243 Formatting 2023-09-15 13:09:03 -04:00
5eb7920ed2 New reaction for admins 2022-12-12 17:33:16 -05:00
f79b842e17 Add mention when link is deleted 2022-09-15 16:59:09 -04:00
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
11 changed files with 153 additions and 40 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!", 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
}

View File

@ -4,7 +4,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
@ -16,7 +15,7 @@ import (
func loadConfig() { func loadConfig() {
var c Config var c Config
confFile, _ := ioutil.ReadFile(configFile) confFile, _ := os.ReadFile(configFile)
err := json.Unmarshal([]byte(confFile), &c) err := json.Unmarshal([]byte(confFile), &c)
if err != nil { if err != nil {
log.LogErrorType(err) log.LogErrorType(err)
@ -52,7 +51,7 @@ func saveConfig() {
if err != nil { if err != nil {
log.LogErrorType(err) log.LogErrorType(err)
} }
err = ioutil.WriteFile(configFile, file, 0600) err = os.WriteFile(configFile, file, 0600)
if err != nil { if err != nil {
log.LogErrorType(err) log.LogErrorType(err)
} }
@ -87,7 +86,7 @@ func activeInteraction(s *discordgo.Session, m string) {
func rebootBump() { func rebootBump() {
time.Sleep(time.Until(config.BumpTime.Add(2 * time.Hour))) time.Sleep(time.Until(config.BumpTime.Add(2 * time.Hour)))
dg.ChannelMessageSend(config.AdminChannel, "!d bump is ready") dg.ChannelMessageSend(config.AdminChannel, "/bump is ready")
} }
@ -98,7 +97,7 @@ func bumpTimer(s *discordgo.Session) {
bump = false bump = false
config.BumpTime = time.Now() config.BumpTime = time.Now()
time.Sleep(2 * time.Hour) time.Sleep(2 * time.Hour)
s.ChannelMessageSend(config.AdminChannel, "!d bump is ready.") s.ChannelMessageSend(config.AdminChannel, "/bump is ready.")
bump = true bump = true
} }

View File

@ -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()
} }
@ -112,8 +110,12 @@ func readReaction(s *discordgo.Session, m *discordgo.MessageReactionAdd) {
requestAge(s, user) requestAge(s, user)
log.LogInfo("%+v has requested ASL for user %+v.", admin.User.Username, user.Username) log.LogInfo("%+v has requested ASL for user %+v.", admin.User.Username, user.Username)
return 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 == "⛔" { } 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) s.GuildBanCreateWithReason(config.GuildID, user.ID, fmt.Sprintf("Underage, female, or too many failed verifications. %+v", admin.User.Username), 5)
verification.Status = "Banned" verification.Status = "Banned"
} else { } else {
return return

View File

@ -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, 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))
}
} }
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 {
@ -110,7 +118,7 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
func handlePM(s *discordgo.Session, m *discordgo.MessageCreate) { func handlePM(s *discordgo.Session, m *discordgo.MessageCreate) {
defer log.PanicSafe() defer log.PanicSafe()
if strings.Contains(m.Content, "Rule") || strings.Contains(m.Content, "rule") { 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.") 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 { for _, uid := range config.Verifications {
user := userFromID(uid.UserID) user := userFromID(uid.UserID)
@ -147,6 +155,7 @@ func handlePM(s *discordgo.Session, m *discordgo.MessageCreate) {
msg, _ := s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("%+v\n%+v", v.Username, v.Photo)) msg, _ := s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("%+v\n%+v", v.Username, v.Photo))
config.Verifications[msg.ID] = v 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, "👍")
s.MessageReactionAdd(config.AdminChannel, msg.ID, "👶") s.MessageReactionAdd(config.AdminChannel, msg.ID, "👶")
s.MessageReactionAdd(config.AdminChannel, msg.ID, "⛔") s.MessageReactionAdd(config.AdminChannel, msg.ID, "⛔")

12
go.mod
View File

@ -1,10 +1,18 @@
module git.nightmare.haus/rudi/disgord-thanos module git.nightmare.haus/rudi/disgord-thanos
go 1.15 go 1.21
require ( require (
github.com/bwmarrin/discordgo v0.23.2 github.com/bwmarrin/discordgo v0.27.1
github.com/gorilla/mux v1.8.0 github.com/gorilla/mux v1.8.0
github.com/gorilla/sessions v1.2.1 github.com/gorilla/sessions v1.2.1
github.com/rudi9719/loggy v0.0.0-20201031035735-9438c484de9a 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
)

24
go.sum
View File

@ -1,16 +1,26 @@
github.com/bwmarrin/discordgo v0.23.2 h1:BzrtTktixGHIu9Tt7dEE6diysEF9HWnXeHuoJEt2fH4= github.com/bwmarrin/discordgo v0.27.1 h1:ib9AIc/dom1E/fSIulrBwnez0CToJE113ZGt4HoliGY=
github.com/bwmarrin/discordgo v0.23.2/go.mod h1:c1WtWUGN6nREDmzIpyTp/iD3VYt4Fpx+bVyfBG7JE+M= 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 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= 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 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= 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 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI=
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= 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 h1:4rkaWoLCWOmra5Mw/dLAWjtDLT/+i5uTX1qhlMVL8WA=
github.com/rudi9719/loggy v0.0.0-20201031035735-9438c484de9a/go.mod h1:s1ANCN8bF6HwwTpJLR458MFVGua9oqKKDbph/2jptL4= github.com/rudi9719/loggy v0.0.0-20201031035735-9438c484de9a/go.mod h1:s1ANCN8bF6HwwTpJLR458MFVGua9oqKKDbph/2jptL4=
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16 h1:y6ce7gCWtnH+m3dCjzQ1PCuwl28DDIc3VNnvY29DlIA= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
samhofi.us/x/keybase v0.0.0-20200129212102-e05e93be9f3f h1:MHSEiuiRFrFi7BTw46lC22PMk3Fit8IvVRM4xANTt20= 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 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=

12
main.go
View File

@ -206,6 +206,16 @@ func requestAge(s *discordgo.Session, u discordgo.User) {
if err != nil { if err != nil {
log.LogErrorType(err) log.LogErrorType(err)
} }
s.ChannelMessageSend(st.ID, "What is your ASL? (Age/Sex/Language) Please note, this is NOT requesting your gender, but your biological sex. Gender is a social construct, sex is biology and in the context of pornographic images more important.") s.ChannelMessageSend(st.ID, "What is your ASL? (Age/Sex/Language) Please note, this is NOT requesting your gender, but your biological sex. Gender is a social construct, sex is measurable and in the context of pornographic images more important.")
} }
func requestReupload(s *discordgo.Session, u discordgo.User) {
defer log.PanicSafe()
st, err := s.UserChannelCreate(u.ID)
if err != nil {
log.LogErrorType(err)
}
s.ChannelMessageSend(st.ID, "Hello! Your verification has been denied because it failed to load. Please try again! The instructions will follow this message:")
rejectVerification(s, u)
}

View File

@ -3,7 +3,6 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
@ -20,7 +19,7 @@ var (
func topWrapper(r *http.Request) string { func topWrapper(r *http.Request) string {
defer log.PanicSafe() defer log.PanicSafe()
headerTemplate, err := ioutil.ReadFile("./static/header.tpl") headerTemplate, err := os.ReadFile("./static/header.tpl")
if err != nil { if err != nil {
log.LogError(fmt.Sprintf("Unable to open header template: ```%+v```", err)) log.LogError(fmt.Sprintf("Unable to open header template: ```%+v```", err))
return "" return ""
@ -37,7 +36,7 @@ func topWrapper(r *http.Request) string {
func bodyWrapper(r *http.Request, template string) string { func bodyWrapper(r *http.Request, template string) string {
defer log.PanicSafe() defer log.PanicSafe()
bodyTemplate, err := ioutil.ReadFile(fmt.Sprintf("./static/%+v.tpl", template)) bodyTemplate, err := os.ReadFile(fmt.Sprintf("./static/%+v.tpl", template))
if err != nil { if err != nil {
log.LogError(fmt.Sprintf("Attempt to load %s.tpl failed. ```%+v```", template, err)) log.LogError(fmt.Sprintf("Attempt to load %s.tpl failed. ```%+v```", template, err))
return bodyWrapper(r, "404") return bodyWrapper(r, "404")
@ -58,7 +57,7 @@ func greetUser(w http.ResponseWriter, r *http.Request) {
loggedIn, _ := detectUser(r, "Homepage") loggedIn, _ := detectUser(r, "Homepage")
if loggedIn { if loggedIn {
bodyTemplate, _ := ioutil.ReadFile("./static/index.html") bodyTemplate, _ := os.ReadFile("./static/index.html")
fmt.Fprint(w, string(bodyTemplate)) fmt.Fprint(w, string(bodyTemplate))
} else { } else {
fmt.Fprint(w, pageBuilder(r, "home")) fmt.Fprint(w, pageBuilder(r, "home"))
@ -103,7 +102,7 @@ func notFoundPage(w http.ResponseWriter, r *http.Request) {
} }
func card(title string, content string, footer string) string { func card(title string, content string, footer string) string {
defer log.PanicSafe() defer log.PanicSafe()
cardTemplate, err := ioutil.ReadFile("./static/card.tpl") cardTemplate, err := os.ReadFile("./static/card.tpl")
if err != nil { if err != nil {
log.LogError("Unable to open card template") log.LogError("Unable to open card template")
return "" return ""

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 ( import (
"flag" "flag"

View File

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