Log errors with stacktrace in migration, skip 10k+ guilds, prevent migration from running twice by accident
This commit is contained in:
parent
9354e5f83e
commit
f53258e348
3 changed files with 78 additions and 44 deletions
|
@ -35,14 +35,27 @@ namespace Geekbot.net.Commands.Admin
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("migrate", RunMode = RunMode.Async)]
|
[Command("migrate", RunMode = RunMode.Async)]
|
||||||
public async Task Migrate()
|
public async Task Migrate(string force = "")
|
||||||
{
|
{
|
||||||
await ReplyAsync("starting migration");
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var status = _globalSettings.GetKey("MigrationStatus");
|
||||||
|
if (status.Equals("Running"))
|
||||||
|
{
|
||||||
|
await ReplyAsync("Migration already running");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (status.Equals("Done") && !force.Equals("force"))
|
||||||
|
{
|
||||||
|
await ReplyAsync("Migration already ran, write `!owner migrate force` to run again");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await ReplyAsync("starting migration");
|
||||||
|
_globalSettings.SetKey("MigrationStatus", "Running");
|
||||||
var redisMigration = new RedisMigration(_database, _redis, _logger, _client);
|
var redisMigration = new RedisMigration(_database, _redis, _logger, _client);
|
||||||
await redisMigration.Migrate();
|
await redisMigration.Migrate();
|
||||||
|
_globalSettings.SetKey("MigrationStatus", "Done");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,6 +33,12 @@ namespace Geekbot.net.Database
|
||||||
_logger.Information(LogSource.Geekbot, "Starting migration process");
|
_logger.Information(LogSource.Geekbot, "Starting migration process");
|
||||||
foreach (var guild in _client.Guilds)
|
foreach (var guild in _client.Guilds)
|
||||||
{
|
{
|
||||||
|
if (guild.MemberCount > 10000)
|
||||||
|
{
|
||||||
|
_logger.Information(LogSource.Geekbot, $"Skipping {guild.Name} because server size is to big ({guild.MemberCount})");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
_logger.Information(LogSource.Geekbot, $"Start Migration for {guild.Name}");
|
_logger.Information(LogSource.Geekbot, $"Start Migration for {guild.Name}");
|
||||||
#region Quotes
|
#region Quotes
|
||||||
/**
|
/**
|
||||||
|
@ -50,15 +56,15 @@ namespace Geekbot.net.Database
|
||||||
_database.Quotes.Add(quote);
|
_database.Quotes.Add(quote);
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Warning(LogSource.Geekbot, $"quote failed: {q}");
|
_logger.Error(LogSource.Geekbot, $"quote failed: {q}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Warning(LogSource.Geekbot, "quote migration failed");
|
_logger.Error(LogSource.Geekbot, "quote migration failed", e);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -83,15 +89,15 @@ namespace Geekbot.net.Database
|
||||||
_database.Karma.Add(user);
|
_database.Karma.Add(user);
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Warning(LogSource.Geekbot, $"karma failed for: {q.Name}");
|
_logger.Error(LogSource.Geekbot, $"karma failed for: {q.Name}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Warning(LogSource.Geekbot, "karma migration failed");
|
_logger.Error(LogSource.Geekbot, "karma migration failed", e);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -115,15 +121,15 @@ namespace Geekbot.net.Database
|
||||||
_database.Rolls.Add(user);
|
_database.Rolls.Add(user);
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Warning(LogSource.Geekbot, $"Rolls failed for: {q.Name}");
|
_logger.Error(LogSource.Geekbot, $"Rolls failed for: {q.Name}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Warning(LogSource.Geekbot, "rolls migration failed");
|
_logger.Error(LogSource.Geekbot, "rolls migration failed", e);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -144,20 +150,20 @@ namespace Geekbot.net.Database
|
||||||
GuildId = guild.Id.AsLong(),
|
GuildId = guild.Id.AsLong(),
|
||||||
UserId = ulong.Parse(q.Name).AsLong(),
|
UserId = ulong.Parse(q.Name).AsLong(),
|
||||||
Given = int.Parse(q.Value),
|
Given = int.Parse(q.Value),
|
||||||
Recieved= int.Parse(gotten[int.Parse(q.Name)].Value)
|
Recieved= int.Parse(gotten[long.Parse(q.Name)].Value)
|
||||||
};
|
};
|
||||||
_database.Slaps.Add(user);
|
_database.Slaps.Add(user);
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Warning(LogSource.Geekbot, $"Slaps failed for: {q.Name}");
|
_logger.Error(LogSource.Geekbot, $"Slaps failed for: {q.Name}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Warning(LogSource.Geekbot, "Slaps migration failed");
|
_logger.Error(LogSource.Geekbot, "Slaps migration failed", e);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -181,15 +187,15 @@ namespace Geekbot.net.Database
|
||||||
_database.Messages.Add(user);
|
_database.Messages.Add(user);
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Warning(LogSource.Geekbot, $"Messages failed for: {q.Name}");
|
_logger.Error(LogSource.Geekbot, $"Messages failed for: {q.Name}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Warning(LogSource.Geekbot, "Messages migration failed");
|
_logger.Error(LogSource.Geekbot, "Messages migration failed", e);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -217,15 +223,15 @@ namespace Geekbot.net.Database
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
done.Add(q.Name);
|
done.Add(q.Name);
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Warning(LogSource.Geekbot, $"Ships failed for: {q.Name}");
|
_logger.Error(LogSource.Geekbot, $"Ships failed for: {q.Name}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Warning(LogSource.Geekbot, "Ships migration failed");
|
_logger.Error(LogSource.Geekbot, "Ships migration failed", e);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -268,19 +274,17 @@ namespace Geekbot.net.Database
|
||||||
case "ModChannel":
|
case "ModChannel":
|
||||||
settings.ModChannel = long.Parse(setting.Value);
|
settings.ModChannel = long.Parse(setting.Value);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Warning(LogSource.Geekbot, $"Setting failed: {setting.Name} - {guild.Id}", e);
|
_logger.Error(LogSource.Geekbot, $"Setting failed: {setting.Name} - {guild.Id}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Warning(LogSource.Geekbot, "Settings migration failed");
|
_logger.Error(LogSource.Geekbot, "Settings migration failed", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -296,6 +300,11 @@ namespace Geekbot.net.Database
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (user.Username == null)
|
||||||
|
{
|
||||||
|
await Task.Delay(100);
|
||||||
|
if (user.Username == null) break;
|
||||||
|
}
|
||||||
var namesSerialized = _redis.HashGet($"User:{user.Id}", "UsedNames").ToString();
|
var namesSerialized = _redis.HashGet($"User:{user.Id}", "UsedNames").ToString();
|
||||||
var names = namesSerialized != null
|
var names = namesSerialized != null
|
||||||
? Utf8Json.JsonSerializer.Deserialize<string[]>(namesSerialized)
|
? Utf8Json.JsonSerializer.Deserialize<string[]>(namesSerialized)
|
||||||
|
@ -314,30 +323,38 @@ namespace Geekbot.net.Database
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Warning(LogSource.Geekbot, $"User failed: {user.Username}", e);
|
_logger.Error(LogSource.Geekbot, $"User failed: {user.Username}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Warning(LogSource.Geekbot, "User migration failed");
|
_logger.Error(LogSource.Geekbot, "User migration failed", e);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Guilds
|
#region Guilds
|
||||||
|
|
||||||
_database.Guilds.Add(new GuildsModel
|
try
|
||||||
{
|
{
|
||||||
CreatedAt = guild.CreatedAt,
|
_database.Guilds.Add(new GuildsModel
|
||||||
GuildId = guild.Id.AsLong(),
|
{
|
||||||
IconUrl = guild.IconUrl,
|
CreatedAt = guild.CreatedAt,
|
||||||
Name = guild.Name,
|
GuildId = guild.Id.AsLong(),
|
||||||
Owner = guild.Owner.Id.AsLong()
|
IconUrl = guild?.IconUrl,
|
||||||
});
|
Name = guild.Name,
|
||||||
await _database.SaveChangesAsync();
|
Owner = guild.Owner.Id.AsLong()
|
||||||
|
});
|
||||||
|
await _database.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.Error(LogSource.Geekbot, $"Guild migration failed: {guild.Name}", e);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
_logger.Information(LogSource.Geekbot, $"Finished Migration for {guild.Name}");
|
_logger.Information(LogSource.Geekbot, $"Finished Migration for {guild.Name}");
|
||||||
|
await Task.Delay(1000);
|
||||||
}
|
}
|
||||||
_logger.Information(LogSource.Geekbot, "Finished migration process");
|
_logger.Information(LogSource.Geekbot, "Finished migration process");
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,10 @@ namespace Geekbot.net
|
||||||
if (!(messageParam is SocketUserMessage message)) return Task.CompletedTask;
|
if (!(messageParam is SocketUserMessage message)) return Task.CompletedTask;
|
||||||
if (message.Author.IsBot) return Task.CompletedTask;
|
if (message.Author.IsBot) return Task.CompletedTask;
|
||||||
var argPos = 0;
|
var argPos = 0;
|
||||||
|
|
||||||
|
// ToDo: remove
|
||||||
|
// if (!message.Author.Id.Equals(93061333972455424)) return Task.CompletedTask;
|
||||||
|
|
||||||
var lowCaseMsg = message.ToString().ToLower();
|
var lowCaseMsg = message.ToString().ToLower();
|
||||||
if (lowCaseMsg.StartsWith("hui"))
|
if (lowCaseMsg.StartsWith("hui"))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue