Add simple migration script
This commit is contained in:
parent
9ecc224ae1
commit
32ae82ca8d
6 changed files with 341 additions and 12 deletions
|
@ -33,6 +33,24 @@ namespace Geekbot.net.Commands.Admin
|
|||
_database = database;
|
||||
}
|
||||
|
||||
[Command("migrate", RunMode = RunMode.Async)]
|
||||
public async Task Migrate()
|
||||
{
|
||||
await ReplyAsync("starting migration");
|
||||
|
||||
try
|
||||
{
|
||||
var redisMigration = new RedisMigration(_database, _redis, _logger, _client);
|
||||
await redisMigration.Migrate();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
|
||||
await ReplyAsync("done");
|
||||
}
|
||||
|
||||
[Command("youtubekey", RunMode = RunMode.Async)]
|
||||
[Remarks(CommandCategories.Admin)]
|
||||
[Summary("Set the youtube api key")]
|
||||
|
@ -90,8 +108,14 @@ namespace Geekbot.net.Commands.Admin
|
|||
[Summary("Throw an error un purpose")]
|
||||
public void PurposefulError()
|
||||
{
|
||||
var e = new Exception("Error Generated by !owner error");
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
try
|
||||
{
|
||||
throw new Exception("Error Generated by !owner error");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,22 +3,23 @@ using System.Linq;
|
|||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Database;
|
||||
using Geekbot.net.Lib;
|
||||
using Geekbot.net.Lib.ErrorHandling;
|
||||
using Geekbot.net.Lib.Extensions;
|
||||
using Geekbot.net.Lib.Levels;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Geekbot.net.Commands.User
|
||||
{
|
||||
public class GuildInfo : ModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
private readonly DatabaseContext _database;
|
||||
private readonly ILevelCalc _levelCalc;
|
||||
private readonly IDatabase _redis;
|
||||
|
||||
public GuildInfo(IDatabase redis, ILevelCalc levelCalc, IErrorHandler errorHandler)
|
||||
public GuildInfo(DatabaseContext database, ILevelCalc levelCalc, IErrorHandler errorHandler)
|
||||
{
|
||||
_redis = redis;
|
||||
_database = database;
|
||||
_levelCalc = levelCalc;
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
@ -39,7 +40,9 @@ namespace Geekbot.net.Commands.User
|
|||
var created = Context.Guild.CreatedAt;
|
||||
var age = Math.Floor((DateTime.Now - created).TotalDays);
|
||||
|
||||
var messages = _redis.HashGet($"{Context.Guild.Id}:Messages", 0.ToString());
|
||||
var messages = _database.Messages
|
||||
.Where(e => e.GuildId == Context.Guild.Id.AsLong())
|
||||
.Sum(e => e.MessageCount);
|
||||
var level = _levelCalc.GetLevel((int) messages);
|
||||
|
||||
eb.AddField("Server Age", $"{created.Day}/{created.Month}/{created.Year} ({age} days)");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue