mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
Added ICoordinator for bots which arent' sharded (the ones which won't be using NadekoBot.Coordinator)
This commit is contained in:
68
src/NadekoBot/Services/Impl/SingleProcessCoordinator.cs
Normal file
68
src/NadekoBot/Services/Impl/SingleProcessCoordinator.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Core.Services;
|
||||
using Serilog;
|
||||
|
||||
namespace NadekoBot.Services
|
||||
{
|
||||
public class SingleProcessCoordinator : ICoordinator
|
||||
{
|
||||
private readonly IBotCredentials _creds;
|
||||
private readonly DiscordSocketClient _client;
|
||||
|
||||
public SingleProcessCoordinator(IBotCredentials creds, DiscordSocketClient client)
|
||||
{
|
||||
_creds = creds;
|
||||
_client = client;
|
||||
}
|
||||
public bool RestartBot()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_creds.RestartCommand?.Cmd)
|
||||
|| string.IsNullOrWhiteSpace(_creds.RestartCommand?.Args))
|
||||
{
|
||||
Log.Error("You must set RestartCommand.Cmd and RestartCommand.Args in credentials.json");
|
||||
return false;
|
||||
}
|
||||
|
||||
Process.Start(_creds.RestartCommand.Cmd, _creds.RestartCommand.Args);
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(2000);
|
||||
Die();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Die()
|
||||
{
|
||||
Environment.Exit(5);
|
||||
}
|
||||
|
||||
public bool RestartShard(int shardId)
|
||||
{
|
||||
return RestartBot();
|
||||
}
|
||||
|
||||
public IList<ShardStatus> GetAllShardStatuses()
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
new ShardStatus()
|
||||
{
|
||||
ConnectionState = _client.ConnectionState,
|
||||
GuildCount = _client.Guilds.Count,
|
||||
LastUpdate = DateTime.UtcNow,
|
||||
ShardId = _client.ShardId
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public int GetGuildCount()
|
||||
{
|
||||
return _client.Guilds.Count;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user