.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.Extensions;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Http;
@ -168,6 +169,23 @@ namespace NadekoBot.Modules.Administration
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)
{
switch (sus)

View File

@ -51,62 +51,70 @@ namespace NadekoBot.Modules.Games
.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;
if (msg == null || msg.IsAuthor() || msg.Author.IsBot)
return Task.CompletedTask;
var channel = imsg.Channel as ITextChannel;
if (channel == null)
return Task.CompletedTask;
if (!generationChannels.Contains(channel.Id))
return Task.CompletedTask;
var _ = Task.Run(async () =>
{
var msg = imsg as SocketUserMessage;
if (msg == null || msg.IsAuthor() || msg.Author.IsBot)
return;
var channel = imsg.Channel as ITextChannel;
if (channel == null)
return;
if (!generationChannels.Contains(channel.Id))
return;
var lastGeneration = lastGenerations.GetOrAdd(channel.Id, DateTime.MinValue);
var rng = new NadekoRandom();
if (DateTime.Now - TimeSpan.FromSeconds(NadekoBot.BotConfig.CurrencyGenerationCooldown) < lastGeneration) //recently generated in this channel, don't generate again
return;
var num = rng.Next(1, 101) + NadekoBot.BotConfig.CurrencyGenerationChance * 100;
if (num > 100)
try
{
lastGenerations.AddOrUpdate(channel.Id, DateTime.Now, (id, old) => DateTime.Now);
var lastGeneration = lastGenerations.GetOrAdd(channel.Id, DateTime.MinValue);
var rng = new NadekoRandom();
var dropAmount = NadekoBot.BotConfig.CurrencyDropAmount;
//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
return;
if (dropAmount > 0)
var num = rng.Next(1, 101) + NadekoBot.BotConfig.CurrencyGenerationChance * 100;
if (num > 100)
{
var msgs = new IUserMessage[dropAmount];
lastGenerations.AddOrUpdate(channel.Id, DateTime.Now, (id, old) => DateTime.Now);
string firstPart;
if (dropAmount == 1)
var dropAmount = NadekoBot.BotConfig.CurrencyDropAmount;
if (dropAmount > 0)
{
firstPart = $"A random { NadekoBot.BotConfig.CurrencyName } appeared!";
}
else
{
firstPart = $"{dropAmount} random { NadekoBot.BotConfig.CurrencyPluralName } appeared!";
}
var file = GetRandomCurrencyImage();
var sent = await channel.SendFileAsync(
file.Item2,
file.Item1,
$"❗ {firstPart} Pick it up by typing `{NadekoBot.ModulePrefixes[typeof(Games).Name]}pick`")
.ConfigureAwait(false);
var msgs = new IUserMessage[dropAmount];
msgs[0] = sent;
string firstPart;
if (dropAmount == 1)
{
firstPart = $"A random { NadekoBot.BotConfig.CurrencyName } appeared!";
}
else
{
firstPart = $"{dropAmount} random { NadekoBot.BotConfig.CurrencyPluralName } appeared!";
}
var file = GetRandomCurrencyImage();
var sent = await channel.SendFileAsync(
file.Item2,
file.Item1,
$"❗ {firstPart} Pick it up by typing `{NadekoBot.ModulePrefixes[typeof(Games).Name]}pick`")
.ConfigureAwait(false);
plantedFlowers.AddOrUpdate(channel.Id, msgs.ToList(), (id, old) => { old.AddRange(msgs); return old; });
msgs[0] = sent;
plantedFlowers.AddOrUpdate(channel.Id, msgs.ToList(), (id, old) => { old.AddRange(msgs); return old; });
}
}
}
}
catch { }
catch (Exception ex)
{
_log.Warn(ex);
}
});
return Task.CompletedTask;
}
[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>
/// Looks up a localized string similar to remind.
/// </summary>

View File

@ -3042,4 +3042,13 @@
<data name="setmusicchannel_usage" xml:space="preserve">
<value>`{0}smch`</value>
</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>