-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefix.go
63 lines (52 loc) · 1.33 KB
/
prefix.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
package cmd
import (
"fmt"
"github.com/Necroforger/dgrouter/exrouter"
"github.com/bwmarrin/discordgo"
"github.com/darenliang/MikuBotGo/framework"
)
// Prefix command
func Prefix(ctx *exrouter.Context) {
prefix := framework.PDB.GetPrefix(ctx.Msg.GuildID)
// Direct messages
if ctx.Msg.GuildID == "" {
ctx.Reply(":information_source: You can't set a prefix in a DM.")
return
}
admin := false
// Fetch guild
guild, err := ctx.Ses.State.Guild(ctx.Msg.GuildID)
if err != nil {
guild, err = ctx.Ses.Guild(ctx.Msg.GuildID)
if err != nil {
ctx.Reply(":cry: An error has occurred.")
return
}
ctx.Ses.State.GuildAdd(guild)
}
// Check owner
if ctx.Msg.Author.ID == guild.OwnerID {
admin = true
}
// Check admin
if !admin {
for _, role := range ctx.Msg.Member.Roles {
r, _ := ctx.Ses.State.Role(ctx.Msg.GuildID, role)
if r.Permissions&discordgo.PermissionAdministrator > 0 {
admin = true
break
}
}
}
if !admin {
ctx.Reply(":information_source: You do not have administrator permissions to change prefix.")
return
}
newPrefix := ctx.Args.After(1)
if newPrefix == "" {
ctx.Reply(fmt.Sprintf(":information_source: Usage: `%sprefix <prefix>`", prefix))
return
}
framework.PDB.UpdateGuild(ctx.Msg.GuildID, newPrefix)
ctx.Reply(":information_source: Set the new prefix to " + newPrefix)
}