You can .award to a role now, closes #681

This commit is contained in:
Kwoth 2016-10-24 13:59:16 +02:00
parent 2cafd17de9
commit 29b06567bd
3 changed files with 30 additions and 8 deletions

View File

@ -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)]

View File

@ -555,7 +555,7 @@ namespace NadekoBot.Resources {
}
/// <summary>
/// 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..
/// </summary>
public static string award_desc {
get {
@ -564,7 +564,7 @@ namespace NadekoBot.Resources {
}
/// <summary>
/// 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`.
/// </summary>
public static string award_usage {
get {

View File

@ -1246,10 +1246,10 @@
<value>award</value>
</data>
<data name="award_desc" xml:space="preserve">
<value>Awards someone a certain amount of currency. </value>
<value>Awards someone a certain amount of currency. You can also specify a role name to award currency to all users in a role.</value>
</data>
<data name="award_usage" xml:space="preserve">
<value>`{0}award 100 @person`</value>
<value>`{0}award 100 @person` or `{0}award 5 Role Of Gamblers`</value>
</data>
<data name="take_cmd" xml:space="preserve">
<value>take</value>
@ -2511,4 +2511,4 @@
<data name="xkcd_usage" xml:space="preserve">
<value>`{0}xkcd` or `{0}xkcd 1400` or `{0}xkcd latest`</value>
</data>
</root>
</root>