-
Notifications
You must be signed in to change notification settings - Fork 0
/
dsmessage.go
63 lines (53 loc) · 1.22 KB
/
dsmessage.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package discord
import (
"fmt"
"regexp"
"github.com/bwmarrin/discordgo"
"github.com/nelsonleduc/calmanbot/config"
)
type dsMessage struct {
*discordgo.Message
session *discordgo.Session
processedText *string
}
func (d dsMessage) GroupID() string {
return "discord"
}
func (d dsMessage) UserName() string {
return d.Author.Username
}
func (d dsMessage) UserID() string {
return d.Author.ID
}
func (d dsMessage) MessageID() string {
return d.ID
}
func (d dsMessage) Text() string {
if d.processedText != nil {
return *d.processedText
}
verboseLog := config.Configuration().VerboseMode()
modifiedText := d.Content
if verboseLog {
fmt.Printf("Parsing discord text: \"%s\"\n", modifiedText)
}
for _, mention := range d.Mentions {
re := regexp.MustCompile("<@.?" + mention.ID + ">")
modifiedText = re.ReplaceAllString(modifiedText, "@"+mention.Username)
if verboseLog {
fmt.Printf("Replacing \"%v\" with \"%v\"\n", mention.ID, mention.Username)
}
}
if verboseLog {
fmt.Printf("Final discord text: \"%s\"\n", modifiedText)
}
d.processedText = &modifiedText
return modifiedText
}
func (d dsMessage) UserType() string {
if d.Type == discordgo.MessageTypeDefault {
return "user"
} else {
return "other"
}
}