-
Notifications
You must be signed in to change notification settings - Fork 2
/
commands.go
50 lines (43 loc) · 1.83 KB
/
commands.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
package main
import (
"github.com/bwmarrin/discordgo"
"strings"
)
var (
commMap = make(map[string]Command)
help = Command{"help", "Displays all commands. Also can display specific information using `$help` and a command after, for example, `$help role`.", helpCommand}
role = Command{"role", "Lets you add either a lane role or a rank role to yourself. `$role jungle` for example.", roleCommand}
roles = Command{"roles", "Displays list of all roles available to add to yourself.", rolesCommand}
bug = Command{"bug", "Sends a bug report to the creator of Dark Star Bot.", bugCommand}
github = Command{"github", "Displays a link to the github of the bot", githubCommand}
mute = Command{"mute", "Mutes a member until `$mute`'d again. Ex. `$mute @JohnDoe#1234`", muteCommand}
muted = Command{"muted", "Displays all muted members [who has `Muted` role]", mutedCommand}
members = Command{"members", "Displays amount of members in the discord", membersCommand}
)
// Command : Every command is made into a struct to make it simpler to work with and eliminate if statements
type Command struct {
name string
description string
exec func(*discordgo.Session, *discordgo.MessageCreate)
}
func loadCommands() {
commMap[help.name] = help
commMap[role.name] = role
commMap[roles.name] = roles
commMap[bug.name] = bug
commMap[github.name] = github
commMap[mute.name] = mute
commMap[muted.name] = muted
commMap[members.name] = members
}
func parseCommand(s *discordgo.Session, m *discordgo.MessageCreate, command string) {
if len(command) > 1 {
if strings.Contains(string(command[0]), "$") { // If the first word of the message starts with `$`
command = string(command[1:]) // Remove the `$` from the command
if command == strings.ToLower(commMap[command].name) {
commMap[command].exec(s, m)
}
}
}
return
}