@ -27,6 +27,7 @@ type Command struct {
DeleteInput bool // defaults to false
DMOnly bool // defaults to false
AdminOnly bool // defaults to false
IgnoreCase bool // defaults to false
// for custom commands that go beyond prints and deletions
Function func ( * discordgo . Session , * discordgo . MessageCreate )
}
@ -37,6 +38,9 @@ func registerCommand(command Command) {
fmt . Println ( "Cannot register a command with no trigger. Skipping." )
return
}
if command . IgnoreCase {
command . Trigger = strings . ToLower ( command . Trigger )
}
commands = append ( commands , command )
}
@ -47,28 +51,32 @@ func evaluateMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
}
fmt . Println ( m . Content )
for _ , command := range commands {
content := m . Content
if command . IgnoreCase {
content = strings . ToLower ( content )
}
if command . RequiresMention {
command . Trigger = fmt . Sprintf ( command . Trigger , s . State . User . ID )
}
switch command . Type {
case CommandTypePrefix :
if strings . HasPrefix ( m. C ontent, command . Trigger ) {
if strings . HasPrefix ( c ontent, command . Trigger ) {
executeCommand ( s , m , command )
return
}
case CommandTypeFullMatch :
if m. C ontent == command . Trigger {
if c ontent == command . Trigger {
executeCommand ( s , m , command )
return
}
case CommandTypeRegex :
match , _ := regexp . MatchString ( command . Trigger , m. C ontent)
match , _ := regexp . MatchString ( command . Trigger , c ontent)
if match {
executeCommand ( s , m , command )
return
}
case CommandTypeContains :
if strings . Contains ( m. C ontent, command . Trigger ) {
if strings . Contains ( c ontent, command . Trigger ) {
executeCommand ( s , m , command )
return
}
@ -118,3 +126,6 @@ func redirectComplaint(s *discordgo.Session, m *discordgo.MessageCreate) {
s . ChannelMessageSendEmbed ( config . ModChannel , embed )
}
func echoMessage ( s * discordgo . Session , m * discordgo . MessageCreate ) {
s . ChannelMessageSend ( m . ChannelID , m . Content )
}