This repository has been archived by the owner on Sep 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
guildsettings.go
134 lines (107 loc) · 2.16 KB
/
guildsettings.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package main
import (
"github.com/diamondburned/discordgo"
)
func messagePingable(m *discordgo.Message, gID int64) bool {
c, err := d.State.Channel(m.ChannelID)
if err != nil {
return false
}
if c.GuildID == 0 {
if m.Author.ID != d.State.User.ID {
return true
}
return false
}
s := getGuildFromSettings(c.GuildID)
if m.MentionEveryone {
//log.Println(2)
return settingGuildAllowEveryone(s)
}
for _, mention := range m.Mentions {
if mention.ID == d.State.User.ID {
//log.Println(4)
return true
}
}
/* if s == nil {
switch g.DefaultMessageNotifications {
case 0:
log.Println(3)
return true
case 2:
default:
}
} else {
var notify = s.MessageNotifications
if c := getChannelFromGuildSettings(m.ChannelID, s); c != nil {
notify = c.MessageNotifications
}
switch notify {
case 0: // all messages
log.Println(3)
return true
case 2:
return false
default: // case 1 - mentions only
}
for _, mention := range m.Mentions {
if mention.ID == d.State.User.ID {
log.Println(4)
return true
}
}
}
*/
return false
}
func getGuildFromSettings(guildID int64) *discordgo.UserGuildSettings {
for _, ugs := range d.State.UserGuildSettings {
if ugs.GuildID == guildID {
return ugs
}
}
return nil
}
func settingGuildIsMuted(s *discordgo.UserGuildSettings) bool {
if s == nil {
return false
}
return s.Muted
}
func settingGuildAllowEveryone(s *discordgo.UserGuildSettings) bool {
if s == nil {
return true
}
return !s.SupressEveryone
}
func getChannelFromGuildSettings(chID int64, s *discordgo.UserGuildSettings,
) *discordgo.UserGuildSettingsChannelOverride {
if s == nil {
return nil
}
for _, c := range s.ChannelOverrides {
if c.ChannelID == chID {
return c
}
}
return nil
}
func settingChannelIsMuted(
cho *discordgo.UserGuildSettingsChannelOverride,
s *discordgo.UserGuildSettings) (m bool) {
if cho == nil {
return false
}
m = cho.Muted
c, err := d.State.Channel(cho.ChannelID)
if err != nil {
return
}
if c.ParentID != 0 {
if cs := getChannelFromGuildSettings(c.ParentID, s); cs != nil {
return cs.Muted
}
}
return
}