go: Implement '!batchrole' command

Luther Wen Xu 2019-10-15 19:01:36 +07:00
parent e9c303c1da
commit b788849469
Signed by untrusted user: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
3 changed files with 33 additions and 0 deletions

@ -137,3 +137,6 @@ const VoteSuggestionUsage = "!votesuggest <种类custom> <内容>\n!votesugge
const VoteSuggestionUpcomingTitle = "准备中…… Preparing…"
const VoteSuggestionUpcomingDescription = "正在准备新的投票……\nPreparing for the next vote..."
const VoteSuggestionUpcomingColour = 0x000000
const BatchRoleUsage = "!batchrole <Discord编号>\n!batchrole <Discord ID>"
const BatchRoleSuccessMessage = "成功分发角色。 Distributed role successfully."

@ -99,3 +99,27 @@ var viewTrustLevel = adminOnly(func(s *discordgo.Session, m *discordgo.MessageCr
}
msg.Send(s, m.ChannelID)
})
var batchGiveRole = adminOnly(enforceDM(enforceArgumentCount(
config.BatchRoleUsage, 2,
func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
members, err := backend.GetAllMembers(s)
if err != nil {
message.AuditError(s, m.ChannelID, err)
return
}
for _, member := range members {
err := s.GuildMemberRoleAdd(
config.GuildID,
member.User.ID,
command[1],
)
if err != nil {
message.AuditError(s, m.ChannelID, err)
return
}
}
message.InitNewEmbed(config.SuccessTitle, config.BatchRoleSuccessMessage, config.SuccessColour).
Send(s, m.ChannelID)
},
)))

@ -17,6 +17,12 @@ type Command struct {
var Commands = []Command{
//Admin Commands
Command{
Name: "!batchrole",
Handler: batchGiveRole,
Usage: config.BatchRoleUsage,
Admin: true,
},
Command{
Name: "!editas",
Handler: editAs,