2017-05-29 04:13:22 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2017-04-01 19:51:25 +00:00
|
|
|
|
using Discord.Commands;
|
|
|
|
|
using System;
|
2017-10-13 04:14:54 +00:00
|
|
|
|
using NadekoBot.Core.Services;
|
2017-04-01 19:51:25 +00:00
|
|
|
|
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;
|
2017-04-01 19:51:25 +00:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Modules.Utility
|
|
|
|
|
{
|
|
|
|
|
public partial class Utility
|
|
|
|
|
{
|
|
|
|
|
[Group]
|
2017-07-15 16:34:34 +00:00
|
|
|
|
public class PatreonCommands : NadekoSubmodule<PatreonRewardsService>
|
2017-04-01 19:51:25 +00:00
|
|
|
|
{
|
2017-05-22 23:59:31 +00:00
|
|
|
|
private readonly IBotCredentials _creds;
|
2017-07-20 03:10:39 +00:00
|
|
|
|
private readonly IBotConfigProvider _config;
|
2017-05-29 04:13:22 +00:00
|
|
|
|
private readonly DbService _db;
|
|
|
|
|
private readonly CurrencyService _currency;
|
2017-05-22 23:59:31 +00:00
|
|
|
|
|
2017-07-20 03:10:39 +00:00
|
|
|
|
public PatreonCommands(IBotCredentials creds, IBotConfigProvider config, DbService db, CurrencyService currency)
|
2017-04-09 20:28:42 +00:00
|
|
|
|
{
|
2017-05-22 23:59:31 +00:00
|
|
|
|
_creds = creds;
|
|
|
|
|
_config = config;
|
|
|
|
|
_db = db;
|
|
|
|
|
_currency = currency;
|
2017-04-09 20:28:42 +00:00
|
|
|
|
}
|
2017-10-13 00:21:39 +00:00
|
|
|
|
|
2017-04-06 18:59:07 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
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-10-13 00:21:39 +00:00
|
|
|
|
await _service.RefreshPledges().ConfigureAwait(false);
|
2017-04-06 18:59:07 +00:00
|
|
|
|
|
|
|
|
|
await Context.Channel.SendConfirmAsync("👌").ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-01 19:51:25 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
public async Task ClaimPatreonRewards()
|
|
|
|
|
{
|
2017-05-22 23:59:31 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(_creds.PatreonAccessToken))
|
2017-04-01 19:51:25 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2017-04-01 19:51:25 +00:00
|
|
|
|
int amount = 0;
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-07-15 16:34:34 +00:00
|
|
|
|
amount = await _service.ClaimReward(Context.User.Id).ConfigureAwait(false);
|
2017-04-01 19:51:25 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_log.Warn(ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (amount > 0)
|
|
|
|
|
{
|
2017-07-20 03:10:39 +00:00
|
|
|
|
await ReplyConfirmLocalized("clpa_success", amount + _config.BotConfig.CurrencySign).ConfigureAwait(false);
|
2017-04-01 19:51:25 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-07-15 16:34:34 +00:00
|
|
|
|
var rem = (_service.Interval - (DateTime.UtcNow - _service.LastUpdate));
|
2017-05-30 04:54:59 +00:00
|
|
|
|
var helpcmd = Format.Code(Prefix + "donate");
|
2017-04-01 22:01:02 +00:00
|
|
|
|
await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
|
2017-04-01 19:51:25 +00:00
|
|
|
|
.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))))
|
2017-04-01 19:51:25 +00:00
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|