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

48 lines
1.8 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 System;
using NadekoBot.Core.Services;
using NadekoBot.Extensions;
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-19 12:10:22 +00:00
[NadekoCommand, Usage, Description, Aliases]
public async Task RaffleCur(int amount)
{
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 03:55:14 +00:00
await ReplyConfirmLocalized("rafflecur_ended", _bc.BotConfig.CurrencyName, Format.Bold(arg.ToString()), won + _bc.BotConfig.CurrencySign);
}
var res = await _service.JoinOrCreateGame(Context.Channel.Id,
Context.User, amount, OnEnded)
.ConfigureAwait(false);
2017-10-19 12:10:22 +00:00
2017-10-20 03:55:14 +00:00
if (res.Item1 != null)
{
await Context.Channel.SendConfirmAsync(GetText("rafflecur_joined", Context.User.ToString()),
string.Join("\n", res.Item1.Users)).ConfigureAwait(false);
}
else
{
if (res.Item2 == CurrencyRaffleService.JoinErrorType.AlreadyJoined)
await ReplyErrorLocalized("rafflecur_already_joined").ConfigureAwait(false);
else if (res.Item2 == CurrencyRaffleService.JoinErrorType.NotEnoughCurrency)
await ReplyErrorLocalized("not_enough").ConfigureAwait(false);
2017-10-19 12:10:22 +00:00
}
}
}
}
}