-
Notifications
You must be signed in to change notification settings - Fork 939
/
commands.go
114 lines (96 loc) · 3.28 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
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
package cah
import (
"strings"
"github.com/jonas747/cardsagainstdiscord"
"github.com/jonas747/dcmd"
"github.com/jonas747/yagpdb/bot"
"github.com/jonas747/yagpdb/commands"
"github.com/sirupsen/logrus"
)
func (p *Plugin) AddCommands() {
cmdCreate := &commands.YAGCommand{
Name: "Create",
CmdCategory: commands.CategoryFun,
Aliases: []string{"c"},
Description: "Creates a Cards Against Humanity game in this channel, add packs after commands, or * for all packs. (-v for vote mode without a card czar).",
Arguments: []*dcmd.ArgDef{
&dcmd.ArgDef{Name: "packs", Type: dcmd.String, Default: "main", Help: "Packs seperated by space, or * for all of them."},
},
ArgSwitches: []*dcmd.ArgDef{
{Switch: "v", Name: "Vote mode - players vote instead of having a card czar."},
},
RunFunc: func(data *dcmd.Data) (interface{}, error) {
voteMode := data.Switch("v").Bool()
pStr := data.Args[0].Str()
packs := strings.Fields(pStr)
_, err := p.Manager.CreateGame(data.GS.ID, data.CS.ID, data.Msg.Author.ID, data.Msg.Author.Username, voteMode, packs...)
if err == nil {
logrus.Info("[cah] Created a new game in ", data.CS.ID, ":", data.GS.ID)
return "", nil
}
if cahErr := cardsagainstdiscord.HumanizeError(err); cahErr != "" {
return cahErr, nil
}
return "", err
},
}
cmdEnd := &commands.YAGCommand{
Name: "End",
CmdCategory: commands.CategoryFun,
Description: "Ends a Cards Against Humanity game that is ongoing in this channel.",
RunFunc: func(data *dcmd.Data) (interface{}, error) {
isAdmin, err := bot.AdminOrPerm(0, data.Msg.Author.ID, data.CS.ID)
if err == nil && isAdmin {
err = p.Manager.RemoveGame(data.CS.ID)
} else {
err = p.Manager.TryAdminRemoveGame(data.Msg.Author.ID)
}
if err != nil {
if cahErr := cardsagainstdiscord.HumanizeError(err); cahErr != "" {
return cahErr, nil
}
return "", err
}
return "Stopped the game", nil
},
}
cmdKick := &commands.YAGCommand{
Name: "Kick",
CmdCategory: commands.CategoryFun,
RequiredArgs: 1,
Arguments: []*dcmd.ArgDef{
&dcmd.ArgDef{Name: "user", Type: dcmd.UserID},
},
Description: "Kicks a player from the ongoing Cards Against Humanity game in this channel.",
RunFunc: func(data *dcmd.Data) (interface{}, error) {
userID := data.Args[0].Int64()
err := p.Manager.AdminKickUser(data.Msg.Author.ID, userID)
if err != nil {
if cahErr := cardsagainstdiscord.HumanizeError(err); cahErr != "" {
return cahErr, nil
}
return "", err
}
return "User removed", nil
},
}
cmdPacks := &commands.YAGCommand{
Name: "Packs",
CmdCategory: commands.CategoryFun,
RequiredArgs: 0,
Description: "Lists all available packs.",
RunFunc: func(data *dcmd.Data) (interface{}, error) {
resp := "Available packs: \n\n"
for _, v := range cardsagainstdiscord.Packs {
resp += "`" + v.Name + "` - " + v.Description + "\n"
}
return resp, nil
},
}
container := commands.CommandSystem.Root.Sub("cah")
container.NotFound = commands.CommonContainerNotFoundHandler(container, "")
container.AddCommand(cmdCreate, cmdCreate.GetTrigger())
container.AddCommand(cmdEnd, cmdEnd.GetTrigger())
container.AddCommand(cmdKick, cmdKick.GetTrigger())
container.AddCommand(cmdPacks, cmdPacks.GetTrigger())
}