-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_evs.go
82 lines (66 loc) · 1.61 KB
/
user_evs.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"github.com/RumbleFrog/discordgo"
"github.com/davecgh/go-spew/spew"
)
// redundant for now because of ID check
// todo: refer to README
func presenceUpdate(s *discordgo.Session, presence *discordgo.PresenceUpdate) {
if presence.User.ID != d.State.User.ID {
return
}
UserSettings.Status = presence.Status
GetElementByCSS("#self-avatar").SetStyle(
"border-color",
ReflectStatusColor(presence.Status),
)
}
// redundant for now because of ID check
func presencesReplace(s *discordgo.Session, pReplace *discordgo.PresencesReplace) {
for _, presence := range *pReplace {
if presence.User.ID != d.State.User.ID {
return
}
UserSettings.Status = presence.Status
GetElementByCSS("#self-avatar").SetStyle(
"border-color",
ReflectStatusColor(presence.Status),
)
}
}
func userSettingsUpdate(s *discordgo.Session, settings *discordgo.UserSettingsUpdate) {
go spew.Dump(settings) // verbose debugging
if settings == nil {
return
}
_settings := *settings
if status, ok := _settings["status"]; ok {
if str, ok := status.(string); ok {
st := discordgo.Status(str)
UserSettings.Status = st
GetElementByCSS("#self-avatar").SetStyle(
"border-color",
ReflectStatusColor(st),
)
}
}
}
func userisBusy() bool {
if UserSettings == nil {
return false
}
switch UserSettings.Status {
case discordgo.StatusDoNotDisturb:
return true
default:
return false
}
}
// Made to prevent messages with nil pointer for author name
// returns username
func safeAuthor(m *discordgo.Message) string {
if m.Author != nil {
return m.Author.Username
}
return "invalid user"
}