grim/wasdead
Clone
Summary
Browse
Changes
Graph
Move the commands back to kong (again)
draft
2019-05-11, Gary Kramlich
b81ba75f65cb
Move the commands back to kong (again)
package
discord
import
(
"regexp"
"strings"
"github.com/bwmarrin/discordgo"
log
"github.com/sirupsen/logrus"
)
var
splitRegex
=
regexp
.
MustCompile
(
`\s+`
)
func
(
c
*
DiscordClient
)
messageHandler
(
s
*
discordgo
.
Session
,
m
*
discordgo
.
MessageCreate
)
{
// ignore messages for ourselves
if
m
.
Author
.
ID
==
s
.
State
.
User
.
ID
{
return
}
if
!
strings
.
HasPrefix
(
m
.
Content
,
c
.
mentionString
)
{
return
}
args
:=
splitRegex
.
Split
(
m
.
Content
,
-
1
)[
1
:]
// call parse commands
err
:=
c
.
processCommand
(
args
,
m
)
if
err
!=
nil
{
log
.
Warnf
(
"error processing %#v: %v"
,
m
.
Content
,
err
)
c
.
sendChannel
(
m
.
ChannelID
,
err
.
Error
())
}
}