From 29b06567bd5935b29d2a0265382090f9c9c83159 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Mon, 24 Oct 2016 13:59:16 +0200 Subject: [PATCH] You can .award to a role now, closes #681 --- src/NadekoBot/Modules/Gambling/Gambling.cs | 28 +++++++++++++++++-- .../Resources/CommandStrings.Designer.cs | 4 +-- src/NadekoBot/Resources/CommandStrings.resx | 6 ++-- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index ac57940d..7107ea41 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -102,23 +102,45 @@ namespace NadekoBot.Modules.Gambling [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [OwnerOnly] - public Task Award(IUserMessage umsg, long amount, [Remainder] IGuildUser usr) => + [Priority(2)] + public Task Award(IUserMessage umsg, int amount, [Remainder] IGuildUser usr) => Award(umsg, amount, usr.Id); [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [OwnerOnly] - public async Task Award(IUserMessage umsg, long amount, [Remainder] ulong usrId) + [Priority(1)] + public async Task Award(IUserMessage umsg, int amount, ulong usrId) { var channel = (ITextChannel)umsg.Channel; if (amount <= 0) return; - await CurrencyHandler.AddCurrencyAsync(usrId, $"Awarded by bot owner. ({umsg.Author.Username}/{umsg.Author.Id})", (int)amount).ConfigureAwait(false); + await CurrencyHandler.AddCurrencyAsync(usrId, $"Awarded by bot owner. ({umsg.Author.Username}/{umsg.Author.Id})", amount).ConfigureAwait(false); await channel.SendMessageAsync($"{umsg.Author.Mention} successfully awarded {amount} {(amount == 1 ? Gambling.CurrencyName : Gambling.CurrencyPluralName)} to <@{usrId}>!").ConfigureAwait(false); } + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [OwnerOnly] + [Priority(0)] + public async Task Award(IUserMessage umsg, int amount, [Remainder] IRole role) + { + var channel = (ITextChannel)umsg.Channel; + var users = channel.Guild.GetUsers() + .Where(u => u.Roles.Contains(role)) + .ToList(); + await Task.WhenAll(users.Select(u => CurrencyHandler.AddCurrencyAsync(u.Id, + $"Awarded by bot owner to **{role.Name}** role. ({umsg.Author.Username}/{umsg.Author.Id})", + amount))) + .ConfigureAwait(false); + + await channel.SendMessageAsync($"Awarded `{amount}` {Gambling.CurrencyPluralName} to `{users.Count}` users from `{role.Name}` role.") + .ConfigureAwait(false); + + } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index d497209f..d85adb73 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -555,7 +555,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Awards someone a certain amount of currency. . + /// Looks up a localized string similar to Awards someone a certain amount of currency. You can also specify a role name to award currency to all users in a role.. /// public static string award_desc { get { @@ -564,7 +564,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to `{0}award 100 @person`. + /// Looks up a localized string similar to `{0}award 100 @person` or `{0}award 5 Role Of Gamblers`. /// public static string award_usage { get { diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index cd384176..0bd6477a 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -1246,10 +1246,10 @@ award - Awards someone a certain amount of currency. + Awards someone a certain amount of currency. You can also specify a role name to award currency to all users in a role. - `{0}award 100 @person` + `{0}award 100 @person` or `{0}award 5 Role Of Gamblers` take @@ -2511,4 +2511,4 @@ `{0}xkcd` or `{0}xkcd 1400` or `{0}xkcd latest` - + \ No newline at end of file