package main
import (
"fmt"
"regexp"
"strings"
"time"
"github.com/bwmarrin/discordgo"
)
func messageCreate ( s * discordgo . Session , m * discordgo . MessageCreate ) {
defer log . PanicSafe ( )
if m . Author . ID == "302050872383242240" && len ( m . Embeds ) > 0 {
if strings . Contains ( m . Embeds [ 0 ] . Description , "minutes until the server can be bumped" ) {
log . LogDebug ( "Failed bump detected" )
re := regexp . MustCompile ( "Please wait another (.*) minutes until the server can be bumped" )
match := re . FindStringSubmatch ( m . Embeds [ 0 ] . Description )
m . Content = fmt . Sprintf ( "%+v bs %+v" , s . State . User . Mention ( ) , match [ 1 ] )
BumpSet ( BotCommand {
Message : m ,
Session : s ,
Parts : strings . Split ( m . Content , " " ) [ 2 : ] ,
} )
}
return
}
if m . Author . Bot || m . Author . ID == s . State . User . ID {
return
}
if m . GuildID == "" {
handlePM ( s , m )
return
}
if isAdmin ( m . Member ) {
adminInteraction ( s , m . Author . ID )
}
if m . ChannelID == config . MonitorChann && ! isAdmin ( m . Member ) {
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
}
if m . ChannelID != config . AdminChannel {
lastActiveTime = time . Now ( )
if len ( m . Attachments ) > 0 {
activeInteraction ( s , m . Author . ID )
}
}
if strings . Contains ( m . Content , "http" ) {
safe := false
for _ , testURL := range config . WhitelistURLs {
if strings . Contains ( m . Content , testURL ) {
safe = true
}
}
if ! safe {
s . ChannelMessageSend ( m . ChannelID , "That domain is not approved by the admins. Please contact Admins if the domain should be whitelisted." )
s . ChannelMessageDelete ( m . ChannelID , m . ID )
}
}
if strings . Contains ( m . Content , s . State . User . ID ) {
b := BotCommand {
Session : s ,
Message : m ,
Parts : strings . Split ( m . Content , " " ) [ 2 : ] ,
}
log . LogDebug ( "%+v" , b . Parts )
for _ , cmd := range commands {
for _ , keyword := range cmd . Keywords {
log . LogDebug ( "Checking if %+v contains %+v" , m . Content , keyword )
if strings . Contains ( m . Content , keyword ) {
log . LogDebug ( "%+v found!" , keyword )
b . Command = keyword
if ! cmd . RequiresAdmin {
log . LogDebug ( "%+v does not require admin, running!" , cmd . Name )
if ! cmd . Exec ( b ) {
s . ChannelMessageSend ( config . AdminChannel , fmt . Sprintf ( "There was an error running %+v\n%+v" , cmd . Name , cmd . Help ) )
} else {
log . LogInfo ( "Ran command %+v for %+v" , cmd . Name , m . Author . Username )
}
} else {
log . LogDebug ( "%+v does require admin, checking!" , cmd . Name )
if isAdmin ( m . Member ) {
if ! cmd . Exec ( b ) {
s . ChannelMessageSend ( config . AdminChannel , fmt . Sprintf ( "There was an error running %+v\n%+v" , cmd . Name , cmd . Help ) )
} else {
log . LogInfo ( "Ran command %+v for %+v" , cmd . Name , m . Author . Username )
}
} else {
log . LogInfo ( "%+v tried to run an admin command (%+v) but isn't an admin." , m . Author . Username , keyword )
}
}
return
}
}
}
}
}
func handlePM ( s * discordgo . Session , m * discordgo . MessageCreate ) {
defer log . PanicSafe ( )
if strings . Contains ( m . Content , "Rule" ) || strings . Contains ( m . Content , "rule" ) {
s . ChannelMessageSend ( m . ChannelID , "I specifically said to say \"!rules\" without quotes in the _unverified_ channel for the rules." )
}
for _ , uid := range config . Verifications {
user := userFromID ( uid . UserID )
if m . Author . ID == user . ID {
s . ChannelMessageSend ( m . ChannelID , "Your verification is pending. An admin will respond to it when they are available." )
s . ChannelMessageSend ( config . AdminChannel , fmt . Sprintf ( "%+v said: %+v" , m . Author . Mention ( ) , m . Content ) )
return
}
}
if len ( m . Attachments ) != 1 {
s . ChannelMessageSend ( m . ChannelID , "```I am a bot and this is an autoreply.\n\nUntil you send a verification, I will always say the following message:```\nYou may only send me your verification (and nothing else) to be passed to the admins (and no one else). Verification is a clear full face pic, with your pinky finger held to the corner of your mouth." )
s . ChannelMessageSend ( config . AdminChannel , fmt . Sprintf ( "%+v said: %+v" , m . Author . Mention ( ) , m . Content ) )
return
}
if strings . HasSuffix ( strings . ToUpper ( m . Attachments [ 0 ] . ProxyURL ) , "HEIC" ) {
s . ChannelMessageSend ( m . ChannelID , "You have tried to send an unsupported file (HEIC). Please try again using an image (jpeg, jpg, png, etc)." )
return
}
if strings . HasSuffix ( strings . ToUpper ( m . Attachments [ 0 ] . ProxyURL ) , "MP4" ) {
s . ChannelMessageSend ( m . ChannelID , "You have tried to send an unsupported file (MP4 Video). Please try again using an image (jpeg, jpg, png, etc)." )
return
}
if strings . HasSuffix ( strings . ToUpper ( m . Attachments [ 0 ] . ProxyURL ) , "MP3" ) {
s . ChannelMessageSend ( m . ChannelID , "You have tried to send an unsupported file (MP3 Audio). Please try again using an image (jpeg, jpg, png, etc)." )
return
}
delete ( config . Unverified , m . Author . ID )
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 , "👍" )
s . MessageReactionAdd ( config . AdminChannel , msg . ID , "👶" )
s . MessageReactionAdd ( config . AdminChannel , msg . ID , "⛔" )
}