/
ghostping.go
155 lines (131 loc) · 4.59 KB
/
ghostping.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package slashcommands
import (
"github.com/bwmarrin/discordgo"
"github.com/zekroTJA/shinpuru/internal/services/database"
"github.com/zekroTJA/shinpuru/internal/services/permissions"
"github.com/zekroTJA/shinpuru/internal/util/static"
"github.com/zekrotja/ken"
"github.com/zekrotja/ken/middlewares/cmdhelp"
)
type Ghostping struct {
ken.EphemeralCommand
}
var (
_ ken.SlashCommand = (*Ghostping)(nil)
_ permissions.PermCommand = (*Ghostping)(nil)
_ cmdhelp.HelpProvider = (*Ghostping)(nil)
)
func (c *Ghostping) Name() string {
return "ghostping"
}
func (c *Ghostping) Description() string {
return "Setup the ghost ping system."
}
func (c *Ghostping) Version() string {
return "1.0.1"
}
func (c *Ghostping) Type() discordgo.ApplicationCommandType {
return discordgo.ChatApplicationCommand
}
func (c *Ghostping) Options() []*discordgo.ApplicationCommandOption {
return []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionSubCommand,
Name: "status",
Description: "Display the current status of the ghost ping settings.",
},
{
Type: discordgo.ApplicationCommandOptionSubCommand,
Name: "setup",
Description: "Setup ghostping messages.",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionString,
Name: "message",
Description: "The ghost ping message pattern. Use `/ghostping help` to get more info.",
Required: true,
},
},
},
{
Type: discordgo.ApplicationCommandOptionSubCommand,
Name: "disable",
Description: "Disable ghostping messages.",
},
{
Type: discordgo.ApplicationCommandOptionSubCommand,
Name: "help",
Description: "Display help about the message pattern which can be used.",
},
}
}
func (c *Ghostping) Help(ctx ken.SubCommandContext) (emb *discordgo.MessageEmbed, err error) {
emb = &discordgo.MessageEmbed{
Color: static.ColorEmbedDefault,
Description: "You can use patterns in the ghost ping message:\n" +
"- `{pinger}` - Username of the user who sent the message.\n" +
"- `{@pinger}` - Mention of the user who sent the message.\n" +
"- `{pinged}` - Username of the user who has been pinged.\n" +
"- `{@pinged}` - Mention of the user who has been pinged.\n" +
"- `{msg}` - The content of the original deleted message.\n" +
"\n" +
"If you want to use line breaks, use `\n` in the message parameter.",
}
return
}
func (c *Ghostping) Domain() string {
return "sp.guild.mod.ghostping"
}
func (c *Ghostping) SubDomains() []permissions.SubPermission {
return nil
}
func (c *Ghostping) Run(ctx ken.Context) (err error) {
if err = ctx.Defer(); err != nil {
return
}
err = ctx.HandleSubCommands(
ken.SubCommandHandler{"status", c.status},
ken.SubCommandHandler{"setup", c.setup},
ken.SubCommandHandler{"disable", c.disable},
)
return
}
func (c *Ghostping) status(ctx ken.SubCommandContext) (err error) {
db := ctx.Get(static.DiDatabase).(database.Database)
gpMsg, err := db.GetGuildGhostpingMsg(ctx.GetEvent().GuildID)
if err != nil && !database.IsErrDatabaseNotFound(err) {
return err
}
msg := "Ghostping is currently not set up.\n\n" +
"If you want to set up ghostping, use `/ghostping setup`. If you want to " +
"get info about the message pattern, enter `/ghostping help`."
if gpMsg != "" {
msg = "Ghostping is set up with the following message.\n" +
"```\n" + gpMsg + "\n```\n" +
"If you want to disable Ghostping, use the `/ghostping disable` command."
}
return ctx.FollowUpEmbed(&discordgo.MessageEmbed{
Description: msg,
}).Send().Error
}
func (c *Ghostping) setup(ctx ken.SubCommandContext) (err error) {
db := ctx.Get(static.DiDatabase).(database.Database)
message := ctx.Options().GetByName("message").StringValue()
if err = db.SetGuildGhostpingMsg(ctx.GetEvent().GuildID, message); err != nil {
return
}
return ctx.FollowUpEmbed(&discordgo.MessageEmbed{
Description: "Ghostping is now set up with the following message.\n" +
"```\n" + message + "\n```\n" +
"If you want to disable Ghostping, use the `/ghostping disable` command.",
}).Send().Error
}
func (c *Ghostping) disable(ctx ken.SubCommandContext) (err error) {
db := ctx.Get(static.DiDatabase).(database.Database)
if err = db.SetGuildGhostpingMsg(ctx.GetEvent().GuildID, ""); err != nil {
return
}
return ctx.FollowUpEmbed(&discordgo.MessageEmbed{
Description: "Ghostping is now disabled.",
}).Send().Error
}