-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
132 lines (117 loc) · 3.69 KB
/
handler.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
package main
import (
"fmt"
"log"
"github.com/bwmarrin/discordgo"
)
// MessageCommandHandler is a function that handles a newly created user message
type MessageCommandHandler func(*discordgo.Session, *discordgo.MessageCreate, string, string, string)
// MessageCommandMiddleware is a wrapper fucntion
type MessageCommandMiddleware func(MessageCommandHandler) MessageCommandHandler
// AdminMessageCreateMiddleware is a wrapper that wraps around specific handler functions in order to deny access to non-admin users.
func AdminMessageCreateMiddleware(next MessageCommandHandler) MessageCommandHandler {
return func(s *discordgo.Session, m *discordgo.MessageCreate, author, command, args string) {
if config.DiscordAdmin == "" || m.Author.String() != config.DiscordAdmin {
s.ChannelMessageSend(m.ChannelID, "you are not allowed to access this command.")
return
}
next(s, m, author, command, args)
}
}
// ModeratorCommandsHandler handles all moderator commands
func ModeratorCommandsHandler(s *discordgo.Session, m *discordgo.MessageCreate, author, cmd, args string) {
addr, ok := config.GetAddressByChannelID(m.ChannelID)
if !ok {
log.Printf("Request from invalid channel by user %s", author)
return
}
if cmd == "" {
return
}
// check if moderator has access to these commands
if !config.DiscordModeratorCommands.Contains(cmd) {
s.ChannelMessageSend(m.ChannelID, "invalid command: "+cmd)
return
}
switch cmd {
case "help":
HelpHandler(s, m, author, args)
case "status":
StatusHandler(s, m, author, args)
case "bans":
BansHandler(s, m, author, args)
case "multiban":
MultiBanHandler(s, m, author, args)
case "multiunban":
MultiUnbanHandler(s, m, author, args)
case "notify":
NotifyHandler(s, m, author, args)
case "unnotify":
UnnotifyHandler(s, m, author, args)
case "whois":
WhoisHandler(s, m, author, args)
default:
// other command sprefixed with ? and that moderators
//have access to are directly passed to the external console
config.DiscordCommandQueue[addr] <- command{Author: author, Command: fmt.Sprintf("%s %s", cmd, args)}
}
}
// AdminCommandsHandler handles the commands of the admin.
func AdminCommandsHandler(s *discordgo.Session, m *discordgo.MessageCreate, author, cmd, args string) {
addr, ok := config.GetAddressByChannelID(m.ChannelID)
if !ok && cmd != "moderate" {
log.Printf("Request from invalid channel by user %s", author)
return
}
if cmd == "" {
return
}
switch cmd {
case "help":
HelpHandler(s, m, author, args)
case "status":
StatusHandler(s, m, author, args)
case "bans":
BansHandler(s, m, author, args)
case "multiban":
MultiBanHandler(s, m, author, args)
case "multiunban":
MultiUnbanHandler(s, m, author, args)
case "notify":
NotifyHandler(s, m, author, args)
case "unnotify":
UnnotifyHandler(s, m, author, args)
case "whois":
WhoisHandler(s, m, author, args)
case "ips":
IPsHandler(s, m, author, args)
case "announce":
AnnounceHandler(s, m, author, args)
case "unannounce":
UnannounceHandler(s, m, author, args)
case "announcements":
AnnouncementsHandler(s, m, author, args)
case "add":
AddHandler(s, m, author, args)
case "remove":
RemoveHandler(s, m, author, args)
case "purge":
PurgeHandler(s, m, author, args)
case "clean":
CleanHandler(s, m, author, args)
case "moderate":
ModerateHandler(s, m, author, args)
case "spy":
SpyHandler(s, m, author, args)
case "unspy":
UnspyHandler(s, m, author, args)
case "purgespy":
PurgeSpyHandler(s, m, author, args)
case "execute":
ExecuteHandler(s, m, author, args)
case "bulkmultiban":
BulkMultibanHandler(s, m, author, args)
default:
config.DiscordCommandQueue[addr] <- command{Author: author, Command: fmt.Sprintf("%s %s", cmd, args)}
}
}