Download long term verifications
This commit is contained in:
@ -4,8 +4,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"time"
|
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
@ -162,7 +162,7 @@ func purgeTimer(s *discordgo.Session) {
|
|||||||
for {
|
for {
|
||||||
runPurge(s)
|
runPurge(s)
|
||||||
saveConfig()
|
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.")
|
log.LogInfo("Restarting.")
|
||||||
saveConfig()
|
saveConfig()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
|||||||
26
main.go
26
main.go
@ -3,7 +3,9 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strings"
|
"strings"
|
||||||
@ -156,7 +158,7 @@ func runPurge(s *discordgo.Session) {
|
|||||||
|
|
||||||
func ready(s *discordgo.Session, event *discordgo.Ready) {
|
func ready(s *discordgo.Session, event *discordgo.Ready) {
|
||||||
// Set the playing status.
|
// Set the playing status.
|
||||||
s.UpdateStatus(0, "DreamDaddy v0.6")
|
s.UpdateStatus(0, "DreamDaddy v0.7")
|
||||||
}
|
}
|
||||||
|
|
||||||
func guildMemberAdd(s *discordgo.Session, m *discordgo.GuildMemberAdd) {
|
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) {
|
func guildMemberRemove(s *discordgo.Session, m *discordgo.GuildMemberRemove) {
|
||||||
defer log.PanicSafe()
|
defer log.PanicSafe()
|
||||||
go runPurge(s)
|
go runPurge(s)
|
||||||
banned:= false
|
banned := false
|
||||||
for uid, join := range config.Probations {
|
for uid, join := range config.Probations {
|
||||||
if time.Since(join) < 2*time.Hour {
|
if time.Since(join) < 2*time.Hour {
|
||||||
if m.User.ID == uid {
|
if m.User.ID == uid {
|
||||||
@ -277,6 +279,7 @@ func readReaction(s *discordgo.Session, m *discordgo.MessageReactionAdd) {
|
|||||||
} else if m.Emoji.Name == "👍" {
|
} else if m.Emoji.Name == "👍" {
|
||||||
verifyMember(s, user)
|
verifyMember(s, user)
|
||||||
verification.Status = "Accepted"
|
verification.Status = "Accepted"
|
||||||
|
go storeVerification(verification.UserID, verification.Username, verification.Photo)
|
||||||
} else if m.Emoji.Name == "👶" {
|
} else if m.Emoji.Name == "👶" {
|
||||||
requestAge(s, user)
|
requestAge(s, user)
|
||||||
log.LogInfo(fmt.Sprintf("%+v has requested ASL for user %+v.", admin.User.Username, user.Username))
|
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()))
|
log.LogInfo(fmt.Sprintf("%+v", verification.prettyPrint()))
|
||||||
delete(config.Verifications, m.MessageID)
|
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) {
|
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
defer log.PanicSafe()
|
defer log.PanicSafe()
|
||||||
@ -300,7 +318,7 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||||||
handlePM(s, m)
|
handlePM(s, m)
|
||||||
return
|
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()))
|
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 {
|
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 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))
|
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("Sorry, <@%+v> already claimed the bump. Better luck next time!", config.LastBumper))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
2
types.go
2
types.go
@ -11,7 +11,7 @@ type Config struct {
|
|||||||
MonitorChann string
|
MonitorChann string
|
||||||
VerifiedRole string
|
VerifiedRole string
|
||||||
BumpTime time.Time
|
BumpTime time.Time
|
||||||
LastBumper string
|
LastBumper string
|
||||||
Stats map[string]int
|
Stats map[string]int
|
||||||
Unverified map[string]time.Time
|
Unverified map[string]time.Time
|
||||||
Verifications map[string]Verification
|
Verifications map[string]Verification
|
||||||
|
|||||||
Reference in New Issue
Block a user