mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 17:58:26 -04:00
- Bot now takes shard id (optional) and total shards (optional) command line arguments (changed from shard id and parent process id)
- Sharding with coordinator now works properly - Documented creds.yml RestartCommand - it has no effect when coordinator is starting the bot - Regenerated creds_example.yml - Removed all db migrators as the v3 requires the user to have updated 2.x all the way - TotalShards in creds.yml gets overriden by coord.yml's TotalShards if the bot is ran through coordinator (more precisely, by the command line argument to the bot) - Coordinator now runs on http://localhost:3442 by default, you can change this in appsettings.json - This is done because of macos https issues - Primarily because https for regular users is a massive hassle. Coordinator shouldn't be exposed anyway - Minor cleanup
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.IO;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Common;
|
||||
using NadekoBot.Common.Yml;
|
||||
using Serilog;
|
||||
|
||||
@@ -10,6 +12,7 @@ namespace NadekoBot.Services
|
||||
// todo check why is memory usage so unstable
|
||||
public class BotCredsProvider
|
||||
{
|
||||
private readonly int? _totalShards;
|
||||
private const string _credsFileName = "creds.yml";
|
||||
private string CredsPath => Path.Combine(Directory.GetCurrentDirectory(), _credsFileName);
|
||||
private const string _credsExampleFileName = "creds_example.yml";
|
||||
@@ -28,12 +31,42 @@ namespace NadekoBot.Services
|
||||
_creds.OwnerIds.Clear();
|
||||
_config.Bind(_creds);
|
||||
|
||||
// todo load defaults for restart command, redis, and some others maybe?
|
||||
if (string.IsNullOrWhiteSpace(_creds.Token))
|
||||
{
|
||||
Log.Error("Token is missing from credentials.json or Environment variables.\n" +
|
||||
"Add it and restart the program.");
|
||||
Helpers.ReadErrorAndExit(5);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(_creds.RestartCommand?.Cmd)
|
||||
|| string.IsNullOrWhiteSpace(_creds.RestartCommand?.Args))
|
||||
{
|
||||
if (Environment.OSVersion.Platform == PlatformID.Unix)
|
||||
{
|
||||
_creds.RestartCommand = new RestartConfig()
|
||||
{
|
||||
Args = "dotnet",
|
||||
Cmd = "NadekoBot.dll -- {0}",
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
_creds.RestartCommand = new RestartConfig()
|
||||
{
|
||||
Args = "NadekoBot.exe",
|
||||
Cmd = "{0}",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
_creds.TotalShards = _totalShards ?? _creds.TotalShards;
|
||||
}
|
||||
}
|
||||
|
||||
public BotCredsProvider()
|
||||
public BotCredsProvider(int? totalShards = null)
|
||||
{
|
||||
_totalShards = totalShards;
|
||||
if (!File.Exists(CredsExamplePath))
|
||||
{
|
||||
File.WriteAllText(CredsExamplePath, Yaml.Serializer.Serialize(_creds));
|
@@ -20,8 +20,11 @@ namespace NadekoBot.Services
|
||||
|
||||
public RemoteGrpcCoordinator(IBotCredentials creds, DiscordSocketClient client)
|
||||
{
|
||||
// todo should use credentials
|
||||
var channel = Grpc.Net.Client.GrpcChannel.ForAddress("https://localhost:3443");
|
||||
var coordUrl = string.IsNullOrWhiteSpace(creds.CoordinatorUrl)
|
||||
? "http://localhost:3442"
|
||||
: creds.CoordinatorUrl;
|
||||
|
||||
var channel = Grpc.Net.Client.GrpcChannel.ForAddress(coordUrl);
|
||||
_coordClient = new(channel);
|
||||
_client = client;
|
||||
}
|
||||
@@ -29,8 +32,8 @@ namespace NadekoBot.Services
|
||||
public bool RestartBot()
|
||||
{
|
||||
_coordClient.RestartAllShards(new RestartAllRequest
|
||||
{
|
||||
|
||||
{
|
||||
|
||||
});
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user