- 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:
Kwoth
2021-06-25 19:14:34 +02:00
parent a1ef862382
commit 670b0aca96
14 changed files with 119 additions and 398 deletions

View File

@@ -1,70 +0,0 @@
using System;
using System.Data.Common;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Services;
using Serilog;
namespace NadekoBot.Modules.Xp.Services
{
public sealed class XpConfigMigrator : IConfigMigrator
{
private readonly DbService _db;
private readonly XpConfigService _gss;
public XpConfigMigrator(DbService dbService, XpConfigService gss)
{
_db = dbService;
_gss = gss;
}
public void EnsureMigrated()
{
using var uow = _db.GetDbContext();
using var conn = uow.Database.GetDbConnection();
Migrate(conn);
}
private void Migrate(DbConnection conn)
{
using (var checkTableCommand = conn.CreateCommand())
{
// make sure table still exists
checkTableCommand.CommandText =
"SELECT name FROM sqlite_master WHERE type='table' AND name='BotConfig';";
var checkReader = checkTableCommand.ExecuteReader();
if (!checkReader.HasRows)
return;
}
using (var checkMigratedCommand = conn.CreateCommand())
{
checkMigratedCommand.CommandText =
"UPDATE BotConfig SET HasMigratedXpSettings = 1 WHERE HasMigratedXpSettings = 0;";
var changedRows = checkMigratedCommand.ExecuteNonQuery();
if (changedRows == 0)
return;
}
Log.Information("Migrating Xp settings...");
using var com = conn.CreateCommand();
com.CommandText = $@"SELECT XpPerMessage, XpMinutesTimeout, VoiceXpPerMinute, MaxXpMinutes
FROM BotConfig";
using var reader = com.ExecuteReader();
if (!reader.Read())
return;
_gss.ModifyConfig(ModifyAction(reader));
}
private static Action<XpConfig> ModifyAction(DbDataReader reader)
=> config =>
{
config.XpPerMessage = (int) (long) reader["XpPerMessage"];
config.MessageXpCooldown = (int) (long) reader["XpMinutesTimeout"];
config.VoiceMaxMinutes = (int) (long) reader["MaxXpMinutes"];
config.VoiceXpPerMinute = (double) reader["VoiceXpPerMinute"];
};
}
}