-
Notifications
You must be signed in to change notification settings - Fork 8
/
cmdRemovePlayer.go
66 lines (55 loc) · 1.78 KB
/
cmdRemovePlayer.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
package main
import (
"github.com/HeroesAwaken/GoAwaken/Log"
"github.com/bwmarrin/discordgo"
_ "github.com/go-sql-driver/mysql"
)
func (bot *AwakenBot) cmdRemovePlayer(s *discordgo.Session, c *discordgo.Channel, g *discordgo.Guild, m *discordgo.MessageCreate, args []string) {
// Find the member from the message
member, err := s.State.Member(g.ID, m.Author.ID)
if err != nil {
// Could not find member.
log.Errorln("Could not find member", err)
return
}
allowed := false
for _, value := range member.Roles {
if bot.rolesToIDMap[g.ID]["awokenlead"] == value ||
bot.rolesToIDMap[g.ID]["awokendev"] == value ||
bot.rolesToIDMap[g.ID]["staff"] == value ||
bot.rolesToIDMap[g.ID]["communitymanager"] == value {
allowed = true
break
}
}
if !allowed {
bot.send(member.User.ID, "You are not allowed to run this function", c, g, s)
return
}
if len(args) != 1 {
bot.send(member.User.ID, "Please use "+bot.prefix+" removePlayer USER", c, g, s)
return
}
userID, err := bot.getUserID(args[0], s, g)
if err != nil {
bot.send(member.User.ID, "Could not detect user. Please try again. "+err.Error(), c, g, s)
return
}
// Remove Role from website
// id 9 = tester
_, err = bot.RemoveRoleByID.Exec("9", userID)
if err != nil {
log.Errorln("Failed removing role from user", err.Error())
bot.send(member.User.ID, "Could remove from website. "+err.Error(), c, g, s)
}
var discordID string
err = bot.GetDiscordIDByID.QueryRow(userID).Scan(&discordID)
if err != nil {
log.Errorln("Could not find discordID")
bot.send(member.User.ID, "Could not find discordID. "+err.Error(), c, g, s)
return
}
// Remove discord role
s.GuildMemberRoleRemove(g.ID, discordID, bot.rolesToIDMap[g.ID]["tester"])
bot.send(member.User.ID, "Removed Player role from user.", c, g, s)
}