Global usings and file scoped namespaces

This commit is contained in:
Kwoth
2021-12-19 05:14:11 +01:00
parent bc31dae965
commit ee33313519
548 changed files with 47528 additions and 49115 deletions

View File

@@ -1,73 +1,68 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics;
using System.Threading.Tasks;
using Discord.WebSocket;
using NadekoBot.Services;
using Serilog;
namespace NadekoBot.Services
namespace NadekoBot.Services;
public class SingleProcessCoordinator : ICoordinator
{
public class SingleProcessCoordinator : ICoordinator
private readonly IBotCredentials _creds;
private readonly DiscordSocketClient _client;
public SingleProcessCoordinator(IBotCredentials creds, DiscordSocketClient client)
{
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))
{
_creds = creds;
_client = client;
Log.Error("You must set RestartCommand.Cmd and RestartCommand.Args in creds.yml");
return false;
}
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 creds.yml");
return false;
}
Process.Start(_creds.RestartCommand.Cmd, _creds.RestartCommand.Args);
_ = Task.Run(async () =>
Process.Start(_creds.RestartCommand.Cmd, _creds.RestartCommand.Args);
_ = Task.Run(async () =>
{
await Task.Delay(2000);
Die();
});
return true;
}
public void Die(bool graceful = false)
{
Environment.Exit(5);
}
public bool RestartShard(int shardId)
{
return RestartBot();
}
public IList<ShardStatus> GetAllShardStatuses()
{
return new[]
{
new ShardStatus()
{
await Task.Delay(2000);
Die();
});
return true;
}
ConnectionState = _client.ConnectionState,
GuildCount = _client.Guilds.Count,
LastUpdate = DateTime.UtcNow,
ShardId = _client.ShardId
}
};
}
public void Die(bool graceful = false)
{
Environment.Exit(5);
}
public int GetGuildCount()
{
return _client.Guilds.Count;
}
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;
}
public Task Reload()
{
return Task.CompletedTask;
}
public Task Reload()
{
return Task.CompletedTask;
}
}