small change to how .ropl works
This commit is contained in:
parent
d5c4d3f3d2
commit
d4e78aa8ef
@ -10,6 +10,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Administration
|
namespace NadekoBot.Modules.Administration
|
||||||
@ -22,8 +23,8 @@ namespace NadekoBot.Modules.Administration
|
|||||||
private static Logger _log { get; }
|
private static Logger _log { get; }
|
||||||
public static List<PlayingStatus> RotatingStatusMessages { get; }
|
public static List<PlayingStatus> RotatingStatusMessages { get; }
|
||||||
public static bool RotatingStatuses { get; private set; } = false;
|
public static bool RotatingStatuses { get; private set; } = false;
|
||||||
|
private static Timer _t { get; }
|
||||||
//todo wtf is with this while(true) in constructor
|
|
||||||
static PlayingRotateCommands()
|
static PlayingRotateCommands()
|
||||||
{
|
{
|
||||||
_log = LogManager.GetCurrentClassLogger();
|
_log = LogManager.GetCurrentClassLogger();
|
||||||
@ -31,48 +32,43 @@ namespace NadekoBot.Modules.Administration
|
|||||||
RotatingStatusMessages = NadekoBot.BotConfig.RotatingStatusMessages;
|
RotatingStatusMessages = NadekoBot.BotConfig.RotatingStatusMessages;
|
||||||
RotatingStatuses = NadekoBot.BotConfig.RotatingStatuses;
|
RotatingStatuses = NadekoBot.BotConfig.RotatingStatuses;
|
||||||
|
|
||||||
var t = Task.Run(async () =>
|
|
||||||
|
|
||||||
|
_t = new Timer(async (_) =>
|
||||||
{
|
{
|
||||||
var index = 0;
|
var index = 0;
|
||||||
do
|
try
|
||||||
{
|
{
|
||||||
try
|
if (!RotatingStatuses)
|
||||||
|
return;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (!RotatingStatuses)
|
if (index >= RotatingStatusMessages.Count)
|
||||||
continue;
|
index = 0;
|
||||||
else
|
|
||||||
{
|
|
||||||
if (index >= RotatingStatusMessages.Count)
|
|
||||||
index = 0;
|
|
||||||
|
|
||||||
if (!RotatingStatusMessages.Any())
|
if (!RotatingStatusMessages.Any())
|
||||||
continue;
|
return;
|
||||||
var status = RotatingStatusMessages[index++].Status;
|
var status = RotatingStatusMessages[index++].Status;
|
||||||
if (string.IsNullOrWhiteSpace(status))
|
if (string.IsNullOrWhiteSpace(status))
|
||||||
continue;
|
return;
|
||||||
PlayingPlaceholders.ForEach(e => status = status.Replace(e.Key, e.Value()));
|
PlayingPlaceholders.ForEach(e => status = status.Replace(e.Key, e.Value()));
|
||||||
var shards = NadekoBot.Client.Shards;
|
var shards = NadekoBot.Client.Shards;
|
||||||
for (int i = 0; i < shards.Count; i++)
|
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))));
|
_log.Warn(ex);
|
||||||
try { await shards.ElementAt(i).SetGameAsync(status).ConfigureAwait(false); }
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_log.Warn(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
}
|
||||||
{
|
catch (Exception ex)
|
||||||
_log.Warn("Rotating playing status errored.\n" + ex);
|
{
|
||||||
}
|
_log.Warn("Rotating playing status errored.\n" + ex);
|
||||||
finally
|
}
|
||||||
{
|
}, null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
|
||||||
await Task.Delay(TimeSpan.FromMinutes(1));
|
|
||||||
}
|
|
||||||
} while (true);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Dictionary<string, Func<string>> PlayingPlaceholders { get; } =
|
public static Dictionary<string, Func<string>> PlayingPlaceholders { get; } =
|
||||||
|
@ -222,6 +222,7 @@ namespace NadekoBot.Services
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// maybe this message is a custom reaction
|
// 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);
|
var crExecuted = await Task.Run(() => CustomReactions.TryExecuteCustomReaction(usrMsg)).ConfigureAwait(false);
|
||||||
if (crExecuted) //if it was, don't execute the command
|
if (crExecuted) //if it was, don't execute the command
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user