grim/wasdead

9c111fecaf67
Parents de3d9d1a3960
Children a3c034479912
Make the bot only look at messages that mention it
--- a/discord/commands.go Sun Apr 07 01:33:21 2019 -0500
+++ b/discord/commands.go Sun Apr 07 02:05:16 2019 -0500
@@ -29,9 +29,16 @@
return
}
+ if !strings.HasPrefix(m.Content, c.mentionString) {
+ return
+ }
+
+ log.Debugf("message contents: '%s'", m.Content)
+ log.Debugf("our user id: %s", c.userID)
+
parts := strings.Split(m.Content, " ")
- command := strings.ToLower(parts[0])
+ command := strings.ToLower(parts[1])
if handler, found := commands[command]; found {
err := handler(c, m)
@@ -60,16 +67,18 @@
func isLiveCommand(c *DiscordClient, m *discordgo.MessageCreate) error {
args := strings.Split(m.Content, " ")
- if len(args) != 2 {
+ if len(args) != 3 {
return fmt.Errorf("invalid arguments")
}
uri := ""
- user := args[1]
- if len(m.Mentions) > 0 {
+ user := args[2]
+ if len(m.Mentions) > 1 {
member := m.Mentions[0]
+ log.Debugf("getting presence on %s for %s", m.GuildID, member.ID)
p := c.getPresence(m.GuildID, member.ID)
+ log.Debugf("presences: %#v", p)
if p == nil {
return fmt.Errorf("no presence data found")
}
--- a/discord/discord.go Sun Apr 07 01:33:21 2019 -0500
+++ b/discord/discord.go Sun Apr 07 02:05:16 2019 -0500
@@ -15,6 +15,9 @@
client *discordgo.Session
db database.Database
started time.Time
+
+ userID string
+ mentionString string
}
func New(token string, db database.Database) (*DiscordClient, error) {
@@ -41,6 +44,9 @@
errChan <- err
return
}
+
+ c.userID = c.client.State.Ready.User.ID
+ c.mentionString = "<@" + c.userID + "> "
}
func (c *DiscordClient) Shutdown() error {