NadekoBot/NadekoBot.Modules.Utility/PatreonCommands.cs

83 lines
3.2 KiB
C#
Raw Normal View History

using System.Threading.Tasks;
using Discord.Commands;
using System;
using NadekoBot.Services;
using NadekoBot.Extensions;
2017-04-01 22:01:02 +00:00
using Discord;
2017-07-17 19:42:36 +00:00
using NadekoBot.Common.Attributes;
using NadekoBot.Modules.Utility.Services;
namespace NadekoBot.Modules.Utility
{
public partial class Utility
{
[Group]
2017-07-15 16:34:34 +00:00
public class PatreonCommands : NadekoSubmodule<PatreonRewardsService>
{
2017-05-22 23:59:31 +00:00
private readonly IBotCredentials _creds;
private readonly IBotConfigProvider _config;
private readonly DbService _db;
private readonly CurrencyService _currency;
2017-05-22 23:59:31 +00:00
public PatreonCommands(IBotCredentials creds, IBotConfigProvider config, DbService db, CurrencyService currency)
{
2017-05-22 23:59:31 +00:00
_creds = creds;
_config = config;
_db = db;
_currency = currency;
}
2017-04-06 18:59:07 +00:00
[NadekoCommand, Usage, Description, Aliases]
[OwnerOnly]
2017-07-05 09:07:54 +00:00
[RequireContext(ContextType.DM)]
2017-04-06 18:59:07 +00:00
public async Task PatreonRewardsReload()
{
2017-06-24 03:24:43 +00:00
if (string.IsNullOrWhiteSpace(_creds.PatreonAccessToken))
return;
2017-07-15 16:34:34 +00:00
await _service.RefreshPledges(true).ConfigureAwait(false);
2017-04-06 18:59:07 +00:00
await Context.Channel.SendConfirmAsync("👌").ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
2017-07-05 09:07:54 +00:00
[RequireContext(ContextType.DM)]
public async Task ClaimPatreonRewards()
{
2017-05-22 23:59:31 +00:00
if (string.IsNullOrWhiteSpace(_creds.PatreonAccessToken))
return;
2017-06-24 03:24:43 +00:00
2017-04-02 00:33:43 +00:00
if (DateTime.UtcNow.Day < 5)
{
await ReplyErrorLocalized("clpa_too_early").ConfigureAwait(false);
return;
}
int amount = 0;
try
{
2017-07-15 16:34:34 +00:00
amount = await _service.ClaimReward(Context.User.Id).ConfigureAwait(false);
}
catch (Exception ex)
{
_log.Warn(ex);
}
if (amount > 0)
{
await ReplyConfirmLocalized("clpa_success", amount + _config.BotConfig.CurrencySign).ConfigureAwait(false);
return;
}
2017-07-15 16:34:34 +00:00
var rem = (_service.Interval - (DateTime.UtcNow - _service.LastUpdate));
var helpcmd = Format.Code(Prefix + "donate");
2017-04-01 22:01:02 +00:00
await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
.WithDescription(GetText("clpa_fail"))
.AddField(efb => efb.WithName(GetText("clpa_fail_already_title")).WithValue(GetText("clpa_fail_already")))
.AddField(efb => efb.WithName(GetText("clpa_fail_wait_title")).WithValue(GetText("clpa_fail_wait")))
2017-04-01 22:01:02 +00:00
.AddField(efb => efb.WithName(GetText("clpa_fail_conn_title")).WithValue(GetText("clpa_fail_conn")))
2017-04-06 18:59:07 +00:00
.AddField(efb => efb.WithName(GetText("clpa_fail_sup_title")).WithValue(GetText("clpa_fail_sup", helpcmd)))
.WithFooter(efb => efb.WithText(GetText("clpa_next_update", rem))))
.ConfigureAwait(false);
}
}
}
}