Cleaning and v1.0 bump
This commit is contained in:
42
main.go
42
main.go
@ -55,7 +55,6 @@ func main() {
|
|||||||
if token == "" {
|
if token == "" {
|
||||||
log.LogPanic("No token provided. Please run: disgord-thanos -t <bot token>")
|
log.LogPanic("No token provided. Please run: disgord-thanos -t <bot token>")
|
||||||
}
|
}
|
||||||
defer log.PanicSafe()
|
|
||||||
if configFile == "" {
|
if configFile == "" {
|
||||||
configFile = "config.json"
|
configFile = "config.json"
|
||||||
} else {
|
} else {
|
||||||
@ -160,7 +159,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.11")
|
s.UpdateStatus(0, "DreamDaddy v1.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
func guildMemberUpdate(s *discordgo.Session, m *discordgo.GuildMemberUpdate) {
|
func guildMemberUpdate(s *discordgo.Session, m *discordgo.GuildMemberUpdate) {
|
||||||
@ -261,13 +260,13 @@ func handlePM(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
delete(config.Unverified, m.Author.ID)
|
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
|
var v Verification
|
||||||
v.Submitted = time.Now()
|
v.Submitted = time.Now()
|
||||||
v.UserID = m.Author.ID
|
v.UserID = m.Author.ID
|
||||||
v.Username = m.Author.Username
|
v.Username = m.Author.Username
|
||||||
v.Photo = m.Attachments[0].ProxyURL
|
v.Photo = m.Attachments[0].ProxyURL
|
||||||
v.Status = "Submitted"
|
v.Status = "Submitted"
|
||||||
|
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, "👍")
|
||||||
@ -300,7 +299,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)
|
go storeVerification(verification)
|
||||||
} 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))
|
||||||
@ -314,28 +313,30 @@ 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, verificationURL string) {
|
func storeVerification(v Verification) {
|
||||||
defer log.PanicSafe()
|
defer log.PanicSafe()
|
||||||
fileURL, _ := url.Parse(verificationURL)
|
fileURL, _ := url.Parse(v.Photo)
|
||||||
path := fileURL.Path
|
path := fileURL.Path
|
||||||
segments := strings.Split(path, "/")
|
segments := strings.Split(path, "/")
|
||||||
|
|
||||||
fileName := segments[len(segments)-1]
|
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{
|
client := http.Client{
|
||||||
CheckRedirect: func(r *http.Request, via []*http.Request) error {
|
CheckRedirect: func(r *http.Request, via []*http.Request) error {
|
||||||
r.URL.Opaque = r.URL.Path
|
r.URL.Opaque = r.URL.Path
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
resp, err := client.Get(verificationURL)
|
resp, err := client.Get(v.Photo)
|
||||||
if err != nil {
|
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 resp.Body.Close()
|
||||||
defer file.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) {
|
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
@ -347,8 +348,11 @@ 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 {
|
||||||
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("%+v please say \"!d bump\" without the quotes to bump our server :)", m.Author.Mention()))
|
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 {
|
for role := range m.Member.Roles {
|
||||||
if fmt.Sprintf("%+v", role) == config.AdminRole {
|
if fmt.Sprintf("%+v", role) == config.AdminRole {
|
||||||
@ -359,11 +363,6 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||||||
lastActiveChan = m.ChannelID
|
lastActiveChan = m.ChannelID
|
||||||
lastActiveTime = time.Now()
|
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 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))
|
||||||
@ -373,20 +372,19 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||||||
go bumpTimer(s)
|
go bumpTimer(s)
|
||||||
return
|
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 m.ChannelID == config.AdminChannel {
|
||||||
if strings.HasPrefix(m.Content, rebootToken) {
|
if strings.HasPrefix(m.Content, rebootToken) {
|
||||||
exit(s)
|
exit(s)
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(m.Content, "!quote") {
|
if strings.HasPrefix(m.Content, "!quote") {
|
||||||
quotes = append(quotes, strings.ReplaceAll(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") {
|
if strings.HasPrefix(m.Content, "!snap") || strings.HasPrefix(m.Content, "!purge") {
|
||||||
go runPurge(s)
|
go runPurge(s)
|
||||||
s.ChannelMessageSend(config.AdminChannel, quotes[rand.Intn(len(quotes))])
|
s.ChannelMessageSend(config.AdminChannel, quotes[rand.Intn(len(quotes))])
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(m.Content, "!st") {
|
if strings.HasPrefix(m.Content, "!st") {
|
||||||
go status(s)
|
go status(s)
|
||||||
|
|||||||
Reference in New Issue
Block a user