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
{

View File

@ -2596,10 +2596,10 @@
<value>listquotes liqu</value>
</data>
<data name="listquotes_desc" xml:space="preserve">
<value>`{0}liqu` or `{0}liqu 3`</value>
<value>Lists all quotes on the server ordered alphabetically. 15 Per page.</value>
</data>
<data name="listquotes_usage" xml:space="preserve">
<value>Lists all quotes on the server ordered alphabetically. 15 Per page.</value>
<value>`{0}liqu` or `{0}liqu 3`</value>
</data>
<data name="typedel_cmd" xml:space="preserve">
<value>typedel</value>
@ -3211,7 +3211,7 @@
<value>Toggles whether the response message of the custom reaction will be sent as a direct message.</value>
</data>
<data name="crdm_usage" xml:space="preserve">
<value>`{0}crad 44`</value>
<value>`{0}crdm 44`</value>
</data>
<data name="aliaslist_cmd" xml:space="preserve">
<value>aliaslist cmdmaplist aliases</value>
@ -3334,7 +3334,7 @@
<value>clparew</value>
</data>
<data name="claimpatreonrewards_desc" xml:space="preserve">
<value>Claim patreon rewards. If you're subscribed to bot owner's patreon you can user this command to claim your rewards - assuming bot owner did setup has their patreon key.</value>
<value>Claim patreon rewards. If you're subscribed to bot owner's patreon you can use this command to claim your rewards - assuming bot owner did setup has their patreon key.</value>
</data>
<data name="claimpatreonrewards_usage" xml:space="preserve">
<value>`{0}clparew`</value>
@ -3366,4 +3366,37 @@
<data name="time_usage" xml:space="preserve">
<value>`{0}time London, UK`</value>
</data>
<data name="patreonrewardsreload_cmd" xml:space="preserve">
<value>parewrel</value>
</data>
<data name="patreonrewardsreload_desc" xml:space="preserve">
<value>Forces the update of the list of patrons who are eligible for the reward.</value>
</data>
<data name="patreonrewardsreload_usage" xml:space="preserve">
<value>`{0}parewrel`</value>
</data>
<data name="shopadd_cmd" xml:space="preserve">
<value>shopadd</value>
</data>
<data name="shopadd_desc" xml:space="preserve">
<value>Adds an item to the shop by specifying type price and name.</value>
</data>
<data name="shopadd_usage" xml:space="preserve">
<value>`{0}shopadd role 1000 Rich`</value>
</data>
<data name="shopremove_cmd" xml:space="preserve">
<value>shoprem shoprm</value>
</data>
<data name="shopremove_desc" xml:space="preserve">
<value>Removes an item from the shop by its color.</value>
</data>
<data name="shop_cmd" xml:space="preserve">
<value>shop</value>
</data>
<data name="shop_desc" xml:space="preserve">
<value>Lists this server's administrators' shop. Paginated.</value>
</data>
<data name="shop_usage" xml:space="preserve">
<value>`{0}shop` or `{0}shop 2`</value>
</data>
</root>