This repository has been archived by the owner on Mar 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
65 lines (57 loc) · 1.66 KB
/
utils.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
package ashrouter
import (
"log"
"github.com/bwmarrin/discordgo"
)
func WaitForMessage(s *discordgo.Session) chan *discordgo.MessageCreate {
channel := make(chan *discordgo.MessageCreate)
s.AddHandlerOnce(func(_ *discordgo.Session, e *discordgo.MessageCreate) {
channel <- e
})
return channel
}
func WaitForUserMessage(s *discordgo.Session, userID string) chan *discordgo.MessageCreate {
channel := make(chan *discordgo.MessageCreate)
s.AddHandlerOnce(func(_ *discordgo.Session, e *discordgo.MessageCreate) {
if e.Author.ID == userID {
channel <- e
}
})
return channel
}
func WaitForUserReact(s *discordgo.Session, userID string) chan *discordgo.MessageReactionAdd {
channel := make(chan *discordgo.MessageReactionAdd)
s.AddHandler(func(_ *discordgo.Session, e *discordgo.MessageReactionAdd) {
if e.UserID == userID {
channel <- e
}
})
return channel
}
func HasPerm(userPerms, hasPerm int64) bool {
return userPerms&hasPerm != 0
}
func IsChannelAdmin(s *discordgo.Session, channelID, userID string) bool {
p, err := s.UserChannelPermissions(userID, channelID)
if err != nil {
log.Printf("Error retrieving user channel permissions: %s", err)
return false
}
if HasPerm(p, discordgo.PermissionAdministrator) {
return true
}
return false
}
func CanBan(s *discordgo.Session, guildID string, m *discordgo.Member) bool {
for _, r := range m.Roles {
role, err := s.State.Role(guildID, r)
if err != nil {
log.Printf("Error retrieving '%s' role: %s", r, err)
return false
}
if HasPerm(role.Permissions, discordgo.PermissionBanMembers) || HasPerm(role.Permissions, discordgo.PermissionAdministrator) {
return true
}
}
return false
}