package main
import (
"fmt"
"time"
"github.com/bwmarrin/discordgo"
)
func ready ( s * discordgo . Session , event * discordgo . Ready ) {
// Set the playing status.
s . UpdateGameStatus ( 0 , fmt . Sprintf ( "DreamDaddy rev %+v" , gitCommit ) )
}
func guildMemberUpdate ( s * discordgo . Session , m * discordgo . GuildMemberUpdate ) {
defer log . PanicSafe ( )
log . LogDebug ( "Member %+v has been updated" , m . User . Username )
for _ , role := range m . Roles {
if fmt . Sprintf ( "%+v" , role ) == config . MonitorRole {
log . LogDebug ( "Role found, Monitor Role" )
s . ChannelMessageSend ( config . AdminChannel , "New unverified user detected." )
s . ChannelMessageSend ( config . MonitorChann , fmt . Sprintf ( "Welcome %+v, you may PM me your verification, or I will ban you in an hour!\nSay \"!rules\" in this channel, without quotes for the rules. You may private/direct message me for verification instructions.\n\nYou will not be able to read/see other channels or users until you verify." , m . User . Mention ( ) ) )
config . Unverified [ m . User . ID ] = time . Now ( )
config . Probations [ m . User . ID ] = time . Now ( )
saveConfig ( )
return
}
log . LogDebug ( "Monitor Role not found: %+v != %+v" , fmt . Sprintf ( "%+v" , role ) , config . MonitorRole )
}
}
func guildMemberAdd ( s * discordgo . Session , m * discordgo . GuildMemberAdd ) {
defer log . PanicSafe ( )
log . LogDebug ( "Adding user to Unverified and Probations" )
config . Unverified [ m . User . ID ] = time . Now ( )
config . Probations [ m . User . ID ] = time . Now ( )
log . LogDebug ( "Giving user monitor role" )
s . GuildMemberRoleAdd ( config . GuildID , m . User . ID , config . MonitorRole )
log . LogDebug ( "Sending Monitored message" )
s . ChannelMessageSend ( config . MonitorChann , fmt . Sprintf ( "Welcome %+v, you may PM me your verification, or I will ban you in an hour!\nSay \"!rules\" in this channel, without quotes for the rules. You may private/direct message me for verification instructions.\n\nYou will not be able to read/see other channels or users until you verify." , m . User . Mention ( ) ) )
log . LogDebug ( "Calling saveConfig" )
saveConfig ( )
}
func guildMemberBanned ( s * discordgo . Session , m * discordgo . GuildBanAdd ) {
defer log . PanicSafe ( )
for uid := range config . Probations {
if m . User . Email == uid {
delete ( config . Probations , uid )
s . ChannelMessageDelete ( config . IntroChann , introMsg [ uid ] )
}
}
saveConfig ( )
}
func guildMemberRemove ( s * discordgo . Session , m * discordgo . GuildMemberRemove ) {
defer log . PanicSafe ( )
go runPurge ( s )
banned := false
for uid , join := range config . Probations {
if time . Since ( join ) < 2 * time . Hour {
if m . User . ID == uid {
banned = true
s . GuildBanCreateWithReason ( config . GuildID , m . User . ID , fmt . Sprintf ( "Left within 2 hours of joining. %+v" , time . Since ( join ) ) , 0 )
delete ( config . Probations , uid )
s . ChannelMessageDelete ( config . IntroChann , introMsg [ uid ] )
}
} else {
delete ( config . Probations , uid )
s . ChannelMessageDelete ( config . IntroChann , introMsg [ uid ] )
}
}
s . ChannelMessageSend ( config . AdminChannel , fmt . Sprintf ( "%+v (@%+v) has left, ban: %+v" , m . User . ID , m . User . Username , banned ) )
delete ( config . Unverified , m . User . ID )
for msg , v := range config . Verifications {
if v . UserID == m . User . ID {
delete ( config . Verifications , msg )
s . ChannelMessageDelete ( config . IntroChann , introMsg [ m . User . ID ] )
}
}
saveConfig ( )
}
func readReaction ( s * discordgo . Session , m * discordgo . MessageReactionAdd ) {
defer log . PanicSafe ( )
if m . ChannelID != config . AdminChannel || m . UserID == s . State . User . ID {
return
}
admin , _ := s . GuildMember ( config . GuildID , m . UserID )
adminInteraction ( s , admin . User . ID )
verification , ok := config . Verifications [ m . MessageID ]
if ! ok {
return
}
verification . Admin = admin . User . Username
verification . Closed = time . Now ( )
user := userFromID ( verification . UserID )
if user . ID == "" {
s . ChannelMessageSend ( config . AdminChannel , fmt . Sprintf ( "%+v, that user was not found, they might have left." , admin . Mention ( ) ) )
delete ( config . Verifications , m . MessageID )
return
}
if m . Emoji . Name == "👎" {
rejectVerification ( s , user )
verification . Status = "Rejected"
} else if m . Emoji . Name == "👍" {
verifyMember ( s , user )
verification . Status = "Accepted"
go storeVerification ( verification )
} else if m . Emoji . Name == "👶" {
requestAge ( s , user )
log . LogInfo ( "%+v has requested ASL for user %+v." , admin . User . Username , user . Username )
return
} else if m . Emoji . Name == "⛔" {
s . GuildBanCreateWithReason ( config . GuildID , user . ID , fmt . Sprintf ( "Underage female or too many failed verifications. %+v" , admin . User . Username ) , 5 )
verification . Status = "Banned"
} else {
return
}
log . LogInfo ( "%+v" , verification . prettyPrint ( ) )
delete ( config . Verifications , m . MessageID )
}