Fixed some commandhandler issues, fixed cleanup migration not taking into account alias duplication (how is it even possible?)
This commit is contained in:
parent
76bafd076f
commit
231e77452f
6 changed files with 19 additions and 32 deletions
src/EllieBot
|
@ -16,7 +16,6 @@ public sealed class Bot : IBot
|
||||||
|
|
||||||
private IContainer Services { get; set; }
|
private IContainer Services { get; set; }
|
||||||
|
|
||||||
public bool IsReady { get; private set; }
|
|
||||||
public int ShardId { get; }
|
public int ShardId { get; }
|
||||||
|
|
||||||
private readonly IBotCreds _creds;
|
private readonly IBotCreds _creds;
|
||||||
|
@ -262,19 +261,20 @@ public sealed class Bot : IBot
|
||||||
Stopwatch.GetElapsedTime(startTime).TotalSeconds);
|
Stopwatch.GetElapsedTime(startTime).TotalSeconds);
|
||||||
var commandHandler = Services.GetRequiredService<CommandHandler>();
|
var commandHandler = Services.GetRequiredService<CommandHandler>();
|
||||||
|
|
||||||
// start handling messages received in commandhandler
|
|
||||||
await commandHandler.StartHandling();
|
|
||||||
|
|
||||||
foreach (var a in _loadedAssemblies)
|
foreach (var a in _loadedAssemblies)
|
||||||
{
|
{
|
||||||
await _commandService.AddModulesAsync(a, Services);
|
await _commandService.AddModulesAsync(a, Services);
|
||||||
}
|
}
|
||||||
|
|
||||||
// await _interactionService.AddModulesAsync(typeof(Bot).Assembly, Services);
|
|
||||||
IsReady = true;
|
|
||||||
|
|
||||||
await EnsureBotOwnershipAsync();
|
await EnsureBotOwnershipAsync();
|
||||||
|
|
||||||
|
await commandHandler.InitializeAsync();
|
||||||
|
|
||||||
_ = Task.Run(ExecuteReadySubscriptions);
|
_ = Task.Run(ExecuteReadySubscriptions);
|
||||||
|
|
||||||
|
await commandHandler.StartHandling();
|
||||||
|
|
||||||
Log.Information("Shard {ShardId} ready", Client.ShardId);
|
Log.Information("Shard {ShardId} ready", Client.ShardId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,14 +94,13 @@ public sealed class EllieDbService : DbService
|
||||||
.OrderBy(x => x);
|
.OrderBy(x => x);
|
||||||
|
|
||||||
var lastApplied = applied.Last();
|
var lastApplied = applied.Last();
|
||||||
Log.Information("Last applied migration: {LastApplied}", lastApplied);
|
|
||||||
|
|
||||||
// apply all migrations with names greater than the last applied
|
// apply all migrations with names greater than the last applied
|
||||||
foreach (var runnable in available)
|
foreach (var runnable in available)
|
||||||
{
|
{
|
||||||
if (string.Compare(lastApplied, runnable, StringComparison.Ordinal) < 0)
|
if (string.Compare(lastApplied, runnable, StringComparison.Ordinal) < 0)
|
||||||
{
|
{
|
||||||
Log.Warning("Migration {MigrationName} has not been applied yet", runnable);
|
Log.Warning("Applying migration {MigrationName}", runnable);
|
||||||
|
|
||||||
var query = await File.ReadAllTextAsync(GetMigrationPath(ctx.Database, runnable));
|
var query = await File.ReadAllTextAsync(GetMigrationPath(ctx.Database, runnable));
|
||||||
await ctx.Database.ExecuteSqlRawAsync(query);
|
await ctx.Database.ExecuteSqlRawAsync(query);
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>true</ImplicitUsings>
|
<ImplicitUsings>true</ImplicitUsings>
|
||||||
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
||||||
<Version>6.0.0-alpha1</Version>
|
<Version>6.0.1</Version>
|
||||||
|
|
||||||
<!-- Output/build -->
|
<!-- Output/build -->
|
||||||
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
|
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
|
||||||
|
|
|
@ -178,7 +178,8 @@ DELETE FROM GcChannelId WHERE GuildConfigId IS NULL OR GuildConfigId NOT IN (SEL
|
||||||
UPDATE GcChannelId
|
UPDATE GcChannelId
|
||||||
SET GuildId = (SELECT GuildId FROM GuildConfigs WHERE GuildConfigs.Id = GcChannelId.GuildConfigId);
|
SET GuildId = (SELECT GuildId FROM GuildConfigs WHERE GuildConfigs.Id = GcChannelId.GuildConfigId);
|
||||||
|
|
||||||
DELETE FROM CommandCooldown WHERE GuildConfigId IS NULL OR GuildConfigId NOT IN (SELECT Id FROM GuildConfigs);
|
DELETE FROM CommandCooldown WHERE GuildConfigId IS NULL OR GuildConfigId NOT IN (SELECT Id FROM GuildConfigs)
|
||||||
|
OR (GuildId, CommandName) IN (SELECT GuildId, CommandName FROM CommandCooldown GROUP BY GuildId, CommandName HAVING COUNT(*) > 1);
|
||||||
UPDATE CommandCooldown
|
UPDATE CommandCooldown
|
||||||
SET GuildId = (SELECT GuildId FROM GuildConfigs WHERE GuildConfigs.Id = CommandCooldown.GuildConfigId);
|
SET GuildId = (SELECT GuildId FROM GuildConfigs WHERE GuildConfigs.Id = CommandCooldown.GuildConfigId);
|
||||||
|
|
||||||
|
|
|
@ -5,5 +5,4 @@ namespace EllieBot;
|
||||||
|
|
||||||
public interface IBot
|
public interface IBot
|
||||||
{
|
{
|
||||||
bool IsReady { get; }
|
|
||||||
}
|
}
|
|
@ -8,10 +8,8 @@ using PreconditionResult = Discord.Commands.PreconditionResult;
|
||||||
|
|
||||||
namespace EllieBot.Services;
|
namespace EllieBot.Services;
|
||||||
|
|
||||||
public class CommandHandler : IEService, IReadyExecutor, ICommandHandler
|
public class CommandHandler : IEService, ICommandHandler
|
||||||
{
|
{
|
||||||
private const int GLOBAL_COMMANDS_COOLDOWN = 200;
|
|
||||||
|
|
||||||
private const float ONE_THOUSANDTH = 1.0f / 1000;
|
private const float ONE_THOUSANDTH = 1.0f / 1000;
|
||||||
|
|
||||||
public event Func<IUserMessage, CommandInfo, Task> CommandExecuted = delegate { return Task.CompletedTask; };
|
public event Func<IUserMessage, CommandInfo, Task> CommandExecuted = delegate { return Task.CompletedTask; };
|
||||||
|
@ -57,21 +55,14 @@ public class CommandHandler : IEService, IReadyExecutor, ICommandHandler
|
||||||
_shardData = shardData;
|
_shardData = shardData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task OnReadyAsync()
|
public async Task InitializeAsync()
|
||||||
{
|
{
|
||||||
await using (var uow = _db.GetDbContext())
|
await using var uow = _db.GetDbContext();
|
||||||
{
|
_prefixes = await uow.GetTable<GuildConfig>()
|
||||||
_prefixes = await uow.GetTable<GuildConfig>()
|
.Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId))
|
||||||
.Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId))
|
.Where(x => x.Prefix != null)
|
||||||
.Where(x => x.Prefix != null)
|
.ToListAsyncLinqToDB()
|
||||||
.ToListAsyncLinqToDB()
|
.Fmap(x => x.ToDictionary(x => x.GuildId, x => x.Prefix).ToConcurrent());
|
||||||
.Fmap(x => x.ToDictionary(x => x.GuildId, x => x.Prefix).ToConcurrent());
|
|
||||||
}
|
|
||||||
|
|
||||||
// clear users on short cooldown every GLOBAL_COMMANDS_COOLDOWN miliseconds
|
|
||||||
using var timer = new PeriodicTimer(TimeSpan.FromMilliseconds(GLOBAL_COMMANDS_COOLDOWN));
|
|
||||||
while (await timer.WaitForNextTickAsync())
|
|
||||||
UsersOnShortCooldown.Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetPrefix(IGuild guild)
|
public string GetPrefix(IGuild guild)
|
||||||
|
@ -218,9 +209,6 @@ public class CommandHandler : IEService, IReadyExecutor, ICommandHandler
|
||||||
|
|
||||||
private Task MessageReceivedHandler(SocketMessage msg)
|
private Task MessageReceivedHandler(SocketMessage msg)
|
||||||
{
|
{
|
||||||
if (!_bot.IsReady)
|
|
||||||
return Task.CompletedTask;
|
|
||||||
|
|
||||||
if (_bc.IgnoreOtherBots)
|
if (_bc.IgnoreOtherBots)
|
||||||
{
|
{
|
||||||
if (msg.Author.IsBot)
|
if (msg.Author.IsBot)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue