From b7888494698549e89d6ba6598c3eb610c3e250ac Mon Sep 17 00:00:00 2001 From: Luther Wen Xu Date: Tue, 15 Oct 2019 19:01:36 +0800 Subject: [PATCH] go: Implement '!batchrole' command --- GoBot/discord/config/translate.go | 3 +++ GoBot/discord/modules/admin.go | 24 ++++++++++++++++++++++++ GoBot/discord/modules/commands.go | 6 ++++++ 3 files changed, 33 insertions(+) diff --git a/GoBot/discord/config/translate.go b/GoBot/discord/config/translate.go index 2d93f43..6b1a5d5 100644 --- a/GoBot/discord/config/translate.go +++ b/GoBot/discord/config/translate.go @@ -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 \n!batchrole " +const BatchRoleSuccessMessage = "成功分发角色。 Distributed role successfully." diff --git a/GoBot/discord/modules/admin.go b/GoBot/discord/modules/admin.go index 637abb3..87f03f3 100644 --- a/GoBot/discord/modules/admin.go +++ b/GoBot/discord/modules/admin.go @@ -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) + }, +))) diff --git a/GoBot/discord/modules/commands.go b/GoBot/discord/modules/commands.go index e67ce05..f9e475b 100644 --- a/GoBot/discord/modules/commands.go +++ b/GoBot/discord/modules/commands.go @@ -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,