NadekoBot/NadekoBot.Core/Modules/Gambling/CurrencyRaffleCommands.cs

63 lines
2.4 KiB
C#
Raw Normal View History

2017-10-19 12:10:22 +00:00
using NadekoBot.Common.Attributes;
using NadekoBot.Core.Modules.Gambling.Services;
using System.Threading.Tasks;
2017-10-20 03:55:14 +00:00
using Discord;
using NadekoBot.Core.Services;
using NadekoBot.Extensions;
2017-10-20 15:20:26 +00:00
using System.Linq;
using Discord.Commands;
2017-10-19 12:10:22 +00:00
namespace NadekoBot.Modules.Gambling
{
public partial class Gambling
{
public class CurrencyRaffleCommands : NadekoSubmodule<CurrencyRaffleService>
{
2017-10-20 03:55:14 +00:00
private readonly IBotConfigProvider _bc;
public CurrencyRaffleCommands(IBotConfigProvider bc)
{
_bc = bc;
}
2017-10-20 15:20:26 +00:00
public enum Mixed { Mixed }
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[Priority(0)]
public Task RaffleCur(Mixed _, int amount) =>
RaffleCur(amount, true);
2017-10-19 12:10:22 +00:00
[NadekoCommand, Usage, Description, Aliases]
2017-10-20 15:20:26 +00:00
[RequireContext(ContextType.Guild)]
[Priority(1)]
public async Task RaffleCur(int amount, bool mixed = false)
2017-10-19 12:10:22 +00:00
{
2017-10-20 15:20:26 +00:00
if (amount < 1)
return;
2017-10-20 03:55:14 +00:00
async Task OnEnded(IUser arg, int won)
2017-10-19 12:10:22 +00:00
{
2017-10-20 15:20:26 +00:00
await Context.Channel.SendConfirmAsync(GetText("rafflecur_ended", _bc.BotConfig.CurrencyName, Format.Bold(arg.ToString()), won + _bc.BotConfig.CurrencySign));
2017-10-20 03:55:14 +00:00
}
var res = await _service.JoinOrCreateGame(Context.Channel.Id,
2017-10-20 15:20:26 +00:00
Context.User, amount, mixed, OnEnded)
2017-10-20 03:55:14 +00:00
.ConfigureAwait(false);
2017-10-19 12:10:22 +00:00
2017-10-20 03:55:14 +00:00
if (res.Item1 != null)
{
2017-10-20 15:20:26 +00:00
await Context.Channel.SendConfirmAsync(GetText("rafflecur", res.Item1.GameType.ToString()),
string.Join("\n", res.Item1.Users.Select(x => $"{x.DiscordUser} ({x.Amount})")),
footer: GetText("rafflecur_joined", Context.User.ToString())).ConfigureAwait(false);
2017-10-20 03:55:14 +00:00
}
else
{
2017-10-20 15:20:26 +00:00
if (res.Item2 == CurrencyRaffleService.JoinErrorType.AlreadyJoinedOrInvalidAmount)
2017-10-20 03:55:14 +00:00
await ReplyErrorLocalized("rafflecur_already_joined").ConfigureAwait(false);
else if (res.Item2 == CurrencyRaffleService.JoinErrorType.NotEnoughCurrency)
2017-10-20 15:20:26 +00:00
await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false);
2017-10-19 12:10:22 +00:00
}
}
}
}
}