small change to how .ropl works

This commit is contained in:
Kwoth 2017-01-29 05:56:08 +01:00
parent d5c4d3f3d2
commit d4e78aa8ef
2 changed files with 32 additions and 35 deletions

View File

@ -10,6 +10,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace NadekoBot.Modules.Administration
@ -22,8 +23,8 @@ namespace NadekoBot.Modules.Administration
private static Logger _log { get; }
public static List<PlayingStatus> RotatingStatusMessages { get; }
public static bool RotatingStatuses { get; private set; } = false;
private static Timer _t { get; }
//todo wtf is with this while(true) in constructor
static PlayingRotateCommands()
{
_log = LogManager.GetCurrentClassLogger();
@ -31,48 +32,43 @@ namespace NadekoBot.Modules.Administration
RotatingStatusMessages = NadekoBot.BotConfig.RotatingStatusMessages;
RotatingStatuses = NadekoBot.BotConfig.RotatingStatuses;
var t = Task.Run(async () =>
_t = new Timer(async (_) =>
{
var index = 0;
do
try
{
try
if (!RotatingStatuses)
return;
else
{
if (!RotatingStatuses)
continue;
else
{
if (index >= RotatingStatusMessages.Count)
index = 0;
if (index >= RotatingStatusMessages.Count)
index = 0;
if (!RotatingStatusMessages.Any())
continue;
var status = RotatingStatusMessages[index++].Status;
if (string.IsNullOrWhiteSpace(status))
continue;
PlayingPlaceholders.ForEach(e => status = status.Replace(e.Key, e.Value()));
var shards = NadekoBot.Client.Shards;
for (int i = 0; i < shards.Count; i++)
if (!RotatingStatusMessages.Any())
return;
var status = RotatingStatusMessages[index++].Status;
if (string.IsNullOrWhiteSpace(status))
return;
PlayingPlaceholders.ForEach(e => status = status.Replace(e.Key, e.Value()));
var shards = NadekoBot.Client.Shards;
for (int i = 0; i < shards.Count; i++)
{
ShardSpecificPlaceholders.ForEach(e => status = status.Replace(e.Key, e.Value(shards.ElementAt(i))));
try { await shards.ElementAt(i).SetGameAsync(status).ConfigureAwait(false); }
catch (Exception ex)
{
ShardSpecificPlaceholders.ForEach(e => status = status.Replace(e.Key, e.Value(shards.ElementAt(i))));
try { await shards.ElementAt(i).SetGameAsync(status).ConfigureAwait(false); }
catch (Exception ex)
{
_log.Warn(ex);
}
_log.Warn(ex);
}
}
}
catch (Exception ex)
{
_log.Warn("Rotating playing status errored.\n" + ex);
}
finally
{
await Task.Delay(TimeSpan.FromMinutes(1));
}
} while (true);
});
}
catch (Exception ex)
{
_log.Warn("Rotating playing status errored.\n" + ex);
}
}, null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
}
public static Dictionary<string, Func<string>> PlayingPlaceholders { get; } =

View File

@ -222,6 +222,7 @@ namespace NadekoBot.Services
return;
// maybe this message is a custom reaction
// todo log custom reaction executions. return struct with info
var crExecuted = await Task.Run(() => CustomReactions.TryExecuteCustomReaction(usrMsg)).ConfigureAwait(false);
if (crExecuted) //if it was, don't execute the command
return;