-
Notifications
You must be signed in to change notification settings - Fork 1
/
events.go
38 lines (30 loc) · 921 Bytes
/
events.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"fmt"
"regexp"
"github.com/bwmarrin/discordgo"
)
func userMessageHandler(s *discordgo.Session, m *discordgo.Message) {
duckMatch, _ := regexp.MatchString(".*[Qq][Uu][Aa][Cc][Kk]*.", m.Content)
if duckMatch {
handleQuack(s, m)
}
pointsData := extractPlusMinusEventData(m.Content)
if pointsData != nil {
item := pointsData[0]
operation := pointsData[1]
if operation == "++" || operation == "--" {
handlePlusMinus(item, operation, s, m)
}
return
}
}
func handleQuack(s *discordgo.Session, m *discordgo.Message) {
s.ChannelMessageSend(m.ChannelID, "Quack!")
return
}
func handlePlusMinus(item string, operation string, s *discordgo.Session, m *discordgo.Message) {
println("Updating Score for" + item)
recordID := updateScore(item, operation, m.GuildID)
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("<@%[1]s> has %[2]d points", item, getPointsByID(recordID[0])))
}