Patreon stuff improved

This commit is contained in:
Kwoth
2017-04-06 20:59:07 +02:00
parent b09cd7ea43
commit 6efd78ca21
2 changed files with 55 additions and 6 deletions

View File

@@ -28,6 +28,16 @@ namespace NadekoBot.Modules.Utility
{
patreon = PatreonThingy.Instance;
}
[NadekoCommand, Usage, Description, Aliases]
[OwnerOnly]
public async Task PatreonRewardsReload()
{
await patreon.LoadPledges().ConfigureAwait(false);
await Context.Channel.SendConfirmAsync("👌").ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
public async Task ClaimPatreonRewards()
{
@@ -53,13 +63,15 @@ namespace NadekoBot.Modules.Utility
await ReplyConfirmLocalized("clpa_success", amount + NadekoBot.BotConfig.CurrencySign).ConfigureAwait(false);
return;
}
var rem = (patreon.Interval - (DateTime.UtcNow - patreon.LastUpdate));
var helpcmd = Format.Code(NadekoBot.ModulePrefixes[typeof(Help.Help).Name] + "donate");
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")))
.AddField(efb => efb.WithName(GetText("clpa_fail_conn_title")).WithValue(GetText("clpa_fail_conn")))
.AddField(efb => efb.WithName(GetText("clpa_fail_sup_title")).WithValue(GetText("clpa_fail_sup", helpcmd))))
.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);
}
}
@@ -72,21 +84,25 @@ namespace NadekoBot.Modules.Utility
private readonly SemaphoreSlim getPledgesLocker = new SemaphoreSlim(1, 1);
public ImmutableArray<PatreonUserAndReward> Pledges { get; private set; }
public DateTime LastUpdate { get; private set; } = DateTime.UtcNow;
private readonly Timer update;
private readonly SemaphoreSlim claimLockJustInCase = new SemaphoreSlim(1, 1);
private readonly Logger _log;
public readonly TimeSpan Interval = TimeSpan.FromHours(1);
private PatreonThingy()
{
if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.PatreonAccessToken))
return;
_log = LogManager.GetCurrentClassLogger();
update = new Timer(async (_) => await LoadPledges(), null, TimeSpan.Zero, TimeSpan.FromHours(3));
update = new Timer(async (_) => await LoadPledges(), null, TimeSpan.Zero, Interval);
}
public async Task LoadPledges()
{
LastUpdate = DateTime.UtcNow;
await getPledgesLocker.WaitAsync(1000).ConfigureAwait(false);
try
{