fix shard status nullrefs

This commit is contained in:
Master Kwoth 2017-06-21 23:49:13 +02:00
parent f1bcbd91a3
commit d2ea530c10
2 changed files with 25 additions and 15 deletions

View File

@ -285,12 +285,14 @@ namespace NadekoBot.Modules.Utility
{ {
if (--page < 0) if (--page < 0)
return; return;
var statuses = _bot.ShardCoord.Statuses.ToArray();
var status = string.Join(", ", _bot.ShardCoord.Statuses.GroupBy(x => x.ConnectionState) var status = string.Join(", ", statuses
.Where(x => x != null)
.GroupBy(x => x.ConnectionState)
.Select(x => $"{x.Count()} {x.Key}") .Select(x => $"{x.Count()} {x.Key}")
.ToArray()); .ToArray());
var allShardStrings = _bot.ShardCoord.Statuses var allShardStrings = statuses
.Select(x => .Select(x =>
GetText("shard_stats_txt", x.ShardId.ToString(), GetText("shard_stats_txt", x.ShardId.ToString(),
Format.Bold(x.ConnectionState.ToString()), Format.Bold(x.Guilds.ToString()))) Format.Bold(x.ConnectionState.ToString()), Format.Bold(x.Guilds.ToString())))

View File

@ -65,22 +65,30 @@ namespace NadekoBot
} }
await Task.Run(() => await Task.Run(() =>
{ {
string input; try
while ((input = Console.ReadLine()?.ToLowerInvariant()) != "quit")
{ {
switch (input) string input;
while ((input = Console.ReadLine()?.ToLowerInvariant()) != "quit")
{ {
case "ls": switch (input)
var groupStr = string.Join(",", Statuses {
.Where(x => x != null) case "ls":
.GroupBy(x => x.ConnectionState) var groupStr = string.Join(",", Statuses
.Select(x => x.Count() + " " + x.Key)); .ToArray()
_log.Info(string.Join("\n", Statuses.Select(x => $"Shard {x.ShardId} is in {x.ConnectionState.ToString()} state with {x.Guilds} servers")) + "\n" + groupStr); .Where(x => x != null)
break; .GroupBy(x => x.ConnectionState)
default: .Select(x => x.Count() + " " + x.Key));
break; _log.Info(string.Join("\n", Statuses.Select(x => $"Shard {x.ShardId} is in {x.ConnectionState.ToString()} state with {x.Guilds} servers")) + "\n" + groupStr);
break;
default:
break;
}
} }
} }
catch (Exception ex)
{
_log.Warn(ex);
}
}); });
foreach (var p in ShardProcesses) foreach (var p in ShardProcesses)
{ {