diff --git a/config.go b/config.go index e818401..eeda11b 100644 --- a/config.go +++ b/config.go @@ -4,8 +4,8 @@ import ( "encoding/json" "fmt" "io/ioutil" - "time" "os" + "time" "github.com/bwmarrin/discordgo" ) @@ -117,7 +117,7 @@ func saveConfig() { err = ioutil.WriteFile(configFile, file, 0600) if err != nil { log.LogErrorType(err) - } + } } func setAdminChannel(s *discordgo.Session, m *discordgo.MessageCreate) { @@ -162,7 +162,7 @@ func purgeTimer(s *discordgo.Session) { for { runPurge(s) saveConfig() - if time.Since(lastActiveTime) > 4 * time.Hour && time.Since(startupTime) > 12 * time.Hour { + if time.Since(lastActiveTime) > 4*time.Hour && time.Since(startupTime) > 12*time.Hour { log.LogInfo("Restarting.") saveConfig() os.Exit(0) diff --git a/main.go b/main.go index e195a64..93f9c17 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,9 @@ package main import ( "flag" "fmt" + "io" "math/rand" + "net/http" "os" "os/signal" "strings" @@ -156,7 +158,7 @@ func runPurge(s *discordgo.Session) { func ready(s *discordgo.Session, event *discordgo.Ready) { // Set the playing status. - s.UpdateStatus(0, "DreamDaddy v0.6") + s.UpdateStatus(0, "DreamDaddy v0.7") } func guildMemberAdd(s *discordgo.Session, m *discordgo.GuildMemberAdd) { @@ -179,7 +181,7 @@ func guildMemberBanned(s *discordgo.Session, m *discordgo.GuildBanAdd) { func guildMemberRemove(s *discordgo.Session, m *discordgo.GuildMemberRemove) { defer log.PanicSafe() go runPurge(s) - banned:= false + banned := false for uid, join := range config.Probations { if time.Since(join) < 2*time.Hour { if m.User.ID == uid { @@ -277,6 +279,7 @@ func readReaction(s *discordgo.Session, m *discordgo.MessageReactionAdd) { } else if m.Emoji.Name == "👍" { verifyMember(s, user) verification.Status = "Accepted" + go storeVerification(verification.UserID, verification.Username, verification.Photo) } else if m.Emoji.Name == "👶" { requestAge(s, user) log.LogInfo(fmt.Sprintf("%+v has requested ASL for user %+v.", admin.User.Username, user.Username)) @@ -290,6 +293,21 @@ func readReaction(s *discordgo.Session, m *discordgo.MessageReactionAdd) { log.LogInfo(fmt.Sprintf("%+v", verification.prettyPrint())) delete(config.Verifications, m.MessageID) } +func storeVerification(id string, username string, url string) { + defer log.PanicSafe() + file, _ := os.Create(fmt.Sprintf("./verifications/%s-%s", id, username)) + client := http.Client{ + CheckRedirect: func(r *http.Request, via []*http.Request) error { + r.URL.Opaque = r.URL.Path + return nil + }, + } + resp, _ := client.Get(url) + defer resp.Body.Close() + defer file.Close() + _, _ = io.Copy(file, resp.Body) + +} func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { defer log.PanicSafe() @@ -300,7 +318,7 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { handlePM(s, m) return } - if m.ChannelID != config.MonitorChann && time.Since(config.BumpTime) > 2 * time.Hour && !strings.Contains(m.Content, "!d bump") { + if m.ChannelID != config.MonitorChann && time.Since(config.BumpTime) > 2*time.Hour && !strings.Contains(m.Content, "!d bump") { s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("%+v please say \"!d bump\" without the quotes to bump our server :)", m.Author.Mention())) } for role := range m.Member.Roles { @@ -318,7 +336,7 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { } } if strings.HasPrefix(m.Content, "!d bump") { - if time.Since(config.BumpTime) < 2 * time.Hour { + 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 } diff --git a/types.go b/types.go index 0abcaa7..6665801 100644 --- a/types.go +++ b/types.go @@ -11,7 +11,7 @@ type Config struct { MonitorChann string VerifiedRole string BumpTime time.Time - LastBumper string + LastBumper string Stats map[string]int Unverified map[string]time.Time Verifications map[string]Verification