From 3d7b395463b4a9482982f728c830475ea0d088c5 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Fri, 28 Aug 2020 17:28:36 -0400 Subject: [PATCH] updated filenames for verification storage --- main.go | 19 ++++++++++++++----- types.go | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 8a0ef5e..1a97d76 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "io" "math/rand" "net/http" + "net/url" "os" "os/signal" "strings" @@ -139,7 +140,7 @@ func runPurge(s *discordgo.Session) { messages, _ := s.ChannelMessages(config.MonitorChann, 100, "", "", "") for _, message := range messages { found := false - for user, _ := range config.Unverified { + for user := range config.Unverified { if message.Author.ID == user { found = true } @@ -171,7 +172,7 @@ func guildMemberAdd(s *discordgo.Session, m *discordgo.GuildMemberAdd) { func guildMemberBanned(s *discordgo.Session, m *discordgo.GuildBanAdd) { defer log.PanicSafe() - for uid, _ := range config.Probations { + for uid := range config.Probations { if m.User.Email == uid { delete(config.Probations, uid) } @@ -293,16 +294,24 @@ 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) { +func storeVerification(id string, username string, verificationURL string) { defer log.PanicSafe() - file, _ := os.Create(fmt.Sprintf("./verifications/%s-%s", id, username)) + fileURL, _ := url.Parse(verificationURL) + path := fileURL.Path + segments := strings.Split(path, "/") + + fileName := segments[len(segments)-1] + file, _ := os.Create(fmt.Sprintf("./verifications/%s-%s-%s", id, username, fileName)) client := http.Client{ CheckRedirect: func(r *http.Request, via []*http.Request) error { r.URL.Opaque = r.URL.Path return nil }, } - resp, _ := client.Get(url) + resp, err := client.Get(verificationURL) + if err != nil { + log.LogError(fmt.Sprintf("Unable to store verification %s-%s-%s", id, username, fileName)) + } defer resp.Body.Close() defer file.Close() _, _ = io.Copy(file, resp.Body) diff --git a/types.go b/types.go index 6665801..c574d72 100644 --- a/types.go +++ b/types.go @@ -18,6 +18,7 @@ type Config struct { Probations map[string]time.Time } +// Verification struct used for storing and logging type Verification struct { UserID string Username string