.reloadimages owner-only command added.

This commit is contained in:
Kwoth 2017-02-03 09:54:22 +01:00
parent a728e6f670
commit dcc2f8f9e0
4 changed files with 107 additions and 45 deletions

View File

@ -3,6 +3,7 @@ using Discord.Commands;
using NadekoBot.Attributes; using NadekoBot.Attributes;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
@ -168,6 +169,23 @@ namespace NadekoBot.Modules.Administration
await Context.Channel.SendConfirmAsync("🆗").ConfigureAwait(false); await Context.Channel.SendConfirmAsync("🆗").ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[OwnerOnly]
public async Task ReloadImages()
{
var channel = (ITextChannel)Context.Channel;
var msg = await Context.Channel.SendMessageAsync("Reloading Images...").ConfigureAwait(false);
var sw = Stopwatch.StartNew();
await NadekoBot.Images.Reload().ConfigureAwait(false);
sw.Stop();
await msg.ModifyAsync(x =>
{
x.Content = "✅ Images reloaded.";
}).ConfigureAwait(false);
}
private static UserStatus SettableUserStatusToUserStatus(SettableUserStatus sus) private static UserStatus SettableUserStatusToUserStatus(SettableUserStatus sus)
{ {
switch (sus) switch (sus)

View File

@ -51,24 +51,27 @@ namespace NadekoBot.Modules.Games
.SelectMany(c => c.GenerateCurrencyChannelIds.Select(obj => obj.ChannelId))); .SelectMany(c => c.GenerateCurrencyChannelIds.Select(obj => obj.ChannelId)));
} }
private static async Task PotentialFlowerGeneration(SocketMessage imsg) private static Task PotentialFlowerGeneration(SocketMessage imsg)
{
try
{ {
var msg = imsg as SocketUserMessage; var msg = imsg as SocketUserMessage;
if (msg == null || msg.IsAuthor() || msg.Author.IsBot) if (msg == null || msg.IsAuthor() || msg.Author.IsBot)
return; return Task.CompletedTask;
var channel = imsg.Channel as ITextChannel; var channel = imsg.Channel as ITextChannel;
if (channel == null) if (channel == null)
return; return Task.CompletedTask;
if (!generationChannels.Contains(channel.Id)) if (!generationChannels.Contains(channel.Id))
return; return Task.CompletedTask;
var _ = Task.Run(async () =>
{
try
{
var lastGeneration = lastGenerations.GetOrAdd(channel.Id, DateTime.MinValue); var lastGeneration = lastGenerations.GetOrAdd(channel.Id, DateTime.MinValue);
var rng = new NadekoRandom(); var rng = new NadekoRandom();
//todo i'm stupid :rofl: wtg kwoth. real async programming :100: :ok_hand: :100: :100: :thumbsup:
if (DateTime.Now - TimeSpan.FromSeconds(NadekoBot.BotConfig.CurrencyGenerationCooldown) < lastGeneration) //recently generated in this channel, don't generate again if (DateTime.Now - TimeSpan.FromSeconds(NadekoBot.BotConfig.CurrencyGenerationCooldown) < lastGeneration) //recently generated in this channel, don't generate again
return; return;
@ -106,7 +109,12 @@ namespace NadekoBot.Modules.Games
} }
} }
} }
catch { } catch (Exception ex)
{
_log.Warn(ex);
}
});
return Task.CompletedTask;
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]

View File

@ -5621,6 +5621,33 @@ namespace NadekoBot.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to reloadimages.
/// </summary>
public static string reloadimages_cmd {
get {
return ResourceManager.GetString("reloadimages_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Reloads images bot is using. Safe to use even when bot is being used heavily..
/// </summary>
public static string reloadimages_desc {
get {
return ResourceManager.GetString("reloadimages_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}reloadimages`.
/// </summary>
public static string reloadimages_usage {
get {
return ResourceManager.GetString("reloadimages_usage", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to remind. /// Looks up a localized string similar to remind.
/// </summary> /// </summary>

View File

@ -3042,4 +3042,13 @@
<data name="setmusicchannel_usage" xml:space="preserve"> <data name="setmusicchannel_usage" xml:space="preserve">
<value>`{0}smch`</value> <value>`{0}smch`</value>
</data> </data>
<data name="reloadimages_cmd" xml:space="preserve">
<value>reloadimages</value>
</data>
<data name="reloadimages_desc" xml:space="preserve">
<value>Reloads images bot is using. Safe to use even when bot is being used heavily.</value>
</data>
<data name="reloadimages_usage" xml:space="preserve">
<value>`{0}reloadimages`</value>
</data>
</root> </root>