-
Notifications
You must be signed in to change notification settings - Fork 0
/
Commander.go
43 lines (37 loc) · 1.04 KB
/
Commander.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
package main
import (
"fmt"
"example.com/main/command"
discord "github.com/bwmarrin/discordgo"
)
type Commander struct {
commands map[string]command.Command // usabble command
}
// CommandHandler constructor
func NewCommander(commands map[string]command.Command) *Commander {
return &Commander{
commands,
}
}
// handling content as command
func (commander Commander) Handle(args []string, msg *discord.MessageCreate) {
command_name := args[0]
fmt.Println(command_name)
var bot *discord.Session = GetBot()
var coolDownCounter *CoolDownCounter = NewCoolDownCounter()
if coolDownCounter.Handle(msg) {
bot.ChannelMessageSend(msg.ChannelID, "at cooldown")
return
}
var command command.Command = commander.commands[command_name]
// fmt.Println(name)
err := command.ToArguments(args)
if err != nil {
bot.ChannelMessageSend(msg.ChannelID, fmt.Sprintf("%v", err))
}
err = command.Handle(GetBot(), msg)
if err != nil {
bot.ChannelMessageSend(msg.ChannelID, fmt.Sprintf("%v", err))
}
fmt.Println(GetSettings().Prefix + command_name)
}