forked from botlabs-gg/yagpdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.go
83 lines (67 loc) · 2.14 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
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
package commands
//go:generate sqlboiler --no-hooks psql
//REMOVED: generate easyjson commands.go
import (
"github.com/jonas747/dcmd"
"github.com/jonas747/discordgo"
"github.com/jonas747/yagpdb/common"
"github.com/mediocregopher/radix.v3"
log "github.com/sirupsen/logrus"
)
type CtxKey int
const (
CtxKeyCmdSettings CtxKey = iota
CtxKeyChannelOverride
CtxKeyMS
)
type MessageFilterFunc func(msg *discordgo.Message) bool
// These functions are called on every message, and should return true if the message should be checked for commands, false otherwise
var MessageFilterFuncs []MessageFilterFunc
type Plugin struct{}
func RegisterPlugin() {
plugin := &Plugin{}
common.RegisterPlugin(plugin)
err := common.GORM.AutoMigrate(&common.LoggedExecutedCommand{}).Error
if err != nil {
log.WithError(err).Fatal("Failed migrating logged commands database")
}
common.ValidateSQLSchema(DBSchema)
_, err = common.PQ.Exec(DBSchema)
if err != nil {
log.WithError(err).Fatal("Failed setting up commands settings tables")
}
}
type CommandProvider interface {
// This is where you should register your commands, called on both the webserver and the bot
AddCommands()
}
func InitCommands() {
// Setup the command system
CommandSystem = &dcmd.System{
Root: &dcmd.Container{
HelpTitleEmoji: "ℹ️",
HelpColor: 0xbeff7a,
RunInDM: true,
IgnoreBots: true,
},
ResponseSender: &dcmd.StdResponseSender{LogErrors: true},
Prefix: &Plugin{},
}
// We have our own middleware before the argument parsing, this is to check for things such as wether the command is enabled at all
CommandSystem.Root.AddMidlewares(YAGCommandMiddleware, dcmd.ArgParserMW)
CommandSystem.Root.AddCommand(cmdHelp, cmdHelp.GetTrigger())
CommandSystem.Root.AddCommand(cmdPrefix, cmdPrefix.GetTrigger())
for _, v := range common.Plugins {
if adder, ok := v.(CommandProvider); ok {
adder.AddCommands()
}
}
}
func (p *Plugin) Name() string {
return "Commands"
}
func GetCommandPrefix(guild int64) (string, error) {
var prefix string
err := common.RedisPool.Do(radix.Cmd(&prefix, "GET", "command_prefix:"+discordgo.StrID(guild)))
return prefix, err
}