.ve toggle fixed
This commit is contained in:
parent
5b9cd88848
commit
d7ec044340
1 changed files with 27 additions and 13 deletions
|
@ -1,4 +1,5 @@
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
using LinqToDB;
|
||||||
using LinqToDB.EntityFrameworkCore;
|
using LinqToDB.EntityFrameworkCore;
|
||||||
using EllieBot.Common.ModuleBehaviors;
|
using EllieBot.Common.ModuleBehaviors;
|
||||||
using EllieBot.Db.Models;
|
using EllieBot.Db.Models;
|
||||||
|
@ -36,10 +37,10 @@ public class VerboseErrorsService : IReadyExecutor, IEService
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var embed = _hs.GetCommandHelp(cmd, channel.Guild)
|
var embed = _hs.GetCommandHelp(cmd, channel.Guild)
|
||||||
.WithTitle("Command Error")
|
.WithTitle("Command Error")
|
||||||
.WithDescription(reason)
|
.WithDescription(reason)
|
||||||
.WithFooter("Admin may disable verbose errors via `.ve` command")
|
.WithFooter("Admin may disable verbose errors via `.ve` command")
|
||||||
.WithErrorColor();
|
.WithErrorColor();
|
||||||
|
|
||||||
await _sender.Response(channel).Embed(embed).SendAsync();
|
await _sender.Response(channel).Embed(embed).SendAsync();
|
||||||
}
|
}
|
||||||
|
@ -50,16 +51,29 @@ public class VerboseErrorsService : IReadyExecutor, IEService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Toggles or sets verbose errors for the specified guild.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="guildId">The ID of the guild to toggle verbose errors for.</param>
|
||||||
|
/// <param name="maybeEnabled">If specified, sets to this value; otherwise toggles current value.</param>
|
||||||
|
/// <returns>Returns the new state of verbose errors (true = enabled, false = disabled).</returns>
|
||||||
public async Task<bool> ToggleVerboseErrors(ulong guildId, bool? maybeEnabled = null)
|
public async Task<bool> ToggleVerboseErrors(ulong guildId, bool? maybeEnabled = null)
|
||||||
{
|
{
|
||||||
await using var ctx = _db.GetDbContext();
|
await using var ctx = _db.GetDbContext();
|
||||||
|
|
||||||
var isEnabled = ctx.GetTable<GuildConfig>()
|
var current = await ctx.GetTable<GuildConfig>()
|
||||||
.Where(x => x.GuildId == guildId)
|
.Where(x => x.GuildId == guildId)
|
||||||
.Select(x => x.VerboseErrors)
|
.Select(x => x.VerboseErrors)
|
||||||
.FirstOrDefault();
|
.FirstOrDefaultAsync();
|
||||||
|
|
||||||
if (isEnabled) // This doesn't need to be duplicated inside the using block
|
var newState = maybeEnabled ?? !current;
|
||||||
|
|
||||||
|
await ctx.GetTable<GuildConfig>()
|
||||||
|
.Where(x => x.GuildId == guildId)
|
||||||
|
.Set(x => x.VerboseErrors, newState)
|
||||||
|
.UpdateAsync();
|
||||||
|
|
||||||
|
if (newState)
|
||||||
{
|
{
|
||||||
_guildsDisabled.TryRemove(guildId);
|
_guildsDisabled.TryRemove(guildId);
|
||||||
}
|
}
|
||||||
|
@ -68,15 +82,15 @@ public class VerboseErrorsService : IReadyExecutor, IEService
|
||||||
_guildsDisabled.Add(guildId);
|
_guildsDisabled.Add(guildId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return isEnabled;
|
return newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task OnReadyAsync()
|
public async Task OnReadyAsync()
|
||||||
{
|
{
|
||||||
await using var ctx = _db.GetDbContext();
|
await using var ctx = _db.GetDbContext();
|
||||||
var disabledOn = ctx.GetTable<GuildConfig>()
|
var disabledOn = ctx.GetTable<GuildConfig>()
|
||||||
.Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId) && !x.VerboseErrors)
|
.Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId) && !x.VerboseErrors)
|
||||||
.Select(x => x.GuildId);
|
.Select(x => x.GuildId);
|
||||||
|
|
||||||
foreach (var guildId in disabledOn)
|
foreach (var guildId in disabledOn)
|
||||||
_guildsDisabled.Add(guildId);
|
_guildsDisabled.Add(guildId);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue