From bf031199a4c19f7e900352014bbb3755d4cccd10 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Thu, 29 Oct 2020 21:58:39 -0400 Subject: [PATCH] Cleaning and v1.0 bump --- main.go | 44 +++++++++++++++++++++----------------------- types.go | 2 +- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/main.go b/main.go index aed61f7..67a9f1a 100644 --- a/main.go +++ b/main.go @@ -55,7 +55,6 @@ func main() { if token == "" { log.LogPanic("No token provided. Please run: disgord-thanos -t ") } - defer log.PanicSafe() if configFile == "" { configFile = "config.json" } else { @@ -160,7 +159,7 @@ func runPurge(s *discordgo.Session) { func ready(s *discordgo.Session, event *discordgo.Ready) { // Set the playing status. - s.UpdateStatus(0, "DreamDaddy v0.11") + s.UpdateStatus(0, "DreamDaddy v1.0") } func guildMemberUpdate(s *discordgo.Session, m *discordgo.GuildMemberUpdate) { @@ -261,13 +260,13 @@ func handlePM(s *discordgo.Session, m *discordgo.MessageCreate) { return } delete(config.Unverified, m.Author.ID) - msg, _ := s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("%+v\n%+v", m.Author.Username, m.Attachments[0].ProxyURL)) 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, "👍") @@ -300,7 +299,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) + go storeVerification(verification) } else if m.Emoji.Name == "👶" { requestAge(s, user) log.LogInfo(fmt.Sprintf("%+v has requested ASL for user %+v.", admin.User.Username, user.Username)) @@ -314,28 +313,30 @@ 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, verificationURL string) { +func storeVerification(v Verification) { defer log.PanicSafe() - fileURL, _ := url.Parse(verificationURL) + fileURL, _ := url.Parse(v.Photo) path := fileURL.Path segments := strings.Split(path, "/") fileName := segments[len(segments)-1] - file, _ := os.Create(fmt.Sprintf("./verifications/%s-%s-%s", id, username, fileName)) + file, _ := os.Create(fmt.Sprintf("./verifications/%s-%s-%s", v.UserID, v.Username, fileName)) client := http.Client{ CheckRedirect: func(r *http.Request, via []*http.Request) error { r.URL.Opaque = r.URL.Path return nil }, } - resp, err := client.Get(verificationURL) + resp, err := client.Get(v.Photo) if err != nil { - log.LogError(fmt.Sprintf("Unable to store verification %s-%s-%s", id, username, fileName)) + log.LogError(fmt.Sprintf("Unable to download verification %s-%s-%s", v.UserID, v.Username, fileName)) } defer resp.Body.Close() defer file.Close() - _, _ = io.Copy(file, resp.Body) - + _, err = io.Copy(file, resp.Body) + if err != nil { + log.LogError(fmt.Sprintf("Unable to store verification %s-%s-%s", v.UserID, v.Username, fileName)) + } } func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { @@ -347,8 +348,11 @@ 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") { - s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("%+v please say \"!d bump\" without the quotes to bump our server :)", m.Author.Mention())) + if m.ChannelID == config.MonitorChann { + 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 } for role := range m.Member.Roles { if fmt.Sprintf("%+v", role) == config.AdminRole { @@ -359,11 +363,6 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { lastActiveChan = m.ChannelID lastActiveTime = time.Now() } - if m.ChannelID == config.MonitorChann { - 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())) - } - } if strings.HasPrefix(m.Content, "!d bump") { 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)) @@ -373,24 +372,23 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { go bumpTimer(s) return } + if time.Since(config.BumpTime) > 2*time.Hour { + s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("%+v please say \"!d bump\" without the quotes to bump our server :)", m.Author.Mention())) + } if m.ChannelID == config.AdminChannel { if strings.HasPrefix(m.Content, rebootToken) { exit(s) } if strings.HasPrefix(m.Content, "!quote") { quotes = append(quotes, strings.ReplaceAll(m.Content, "!quote", "")) - pmChann, _ := s.UserChannelCreate(m.Author.ID) - s.ChannelMessageSend(pmChann.ID, fmt.Sprintf("Your quote was added.\n %+v", quotes)) - return } if strings.HasPrefix(m.Content, "!snap") || strings.HasPrefix(m.Content, "!purge") { go runPurge(s) s.ChannelMessageSend(config.AdminChannel, quotes[rand.Intn(len(quotes))]) - return } if strings.HasPrefix(m.Content, "!st") { go status(s) saveConfig() } } -} +} \ No newline at end of file diff --git a/types.go b/types.go index 02989db..0269c08 100644 --- a/types.go +++ b/types.go @@ -8,7 +8,7 @@ type Config struct { AdminChannel string AdminRole string MonitorRole string - IntroChann string + IntroChann string MonitorChann string VerifiedRole string BumpTime time.Time