Split dangerous commands into cleanup commands for each module they belong to

This commit is contained in:
Kwoth
2023-07-15 13:39:46 +00:00
parent 842a8a2f71
commit 8f62a46016
91 changed files with 616 additions and 501 deletions

View File

@@ -0,0 +1,25 @@
#nullable disable
namespace NadekoBot.Common;
public abstract class CleanupModuleBase : NadekoModule
{
protected async Task ConfirmActionInternalAsync(string name, Func<Task> action)
{
try
{
var embed = _eb.Create()
.WithTitle(GetText(strs.sql_confirm_exec))
.WithDescription(name);
if (!await PromptUserConfirmAsync(embed))
return;
await action();
await ctx.OkAsync();
}
catch (Exception ex)
{
await SendErrorAsync(ex.ToString());
}
}
}

View File

@@ -1,4 +1,5 @@
using NadekoBot.Db;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Db;
using NadekoBot.Db.Models;
// todo fix these namespaces. It should only be Nadeko.Bot.Db
using NadekoBot.Services.Database;
@@ -7,6 +8,6 @@ namespace NadekoBot.Extensions;
public static class DbExtensions
{
public static DiscordUser GetOrCreateUser(this NadekoBaseContext ctx, IUser original, Func<IQueryable<DiscordUser>, IQueryable<DiscordUser>>? includes = null)
public static DiscordUser GetOrCreateUser(this DbContext ctx, IUser original, Func<IQueryable<DiscordUser>, IQueryable<DiscordUser>>? includes = null)
=> ctx.GetOrCreateUser(original.Id, original.Username, original.Discriminator, original.AvatarId, includes);
}

View File

@@ -30,15 +30,15 @@ public abstract class NadekoModule : ModuleBase
protected string GetText(in LocStr data)
=> Strings.GetText(data, Culture);
public Task<IUserMessage> SendErrorAsync(
string title,
string error,
string url = null,
string footer = null,
string footer = null,
NadekoInteraction inter = null)
=> ctx.Channel.SendErrorAsync(_eb, title, error, url, footer);
public Task<IUserMessage> SendConfirmAsync(
string title,
string text,
@@ -49,12 +49,14 @@ public abstract class NadekoModule : ModuleBase
//
public Task<IUserMessage> SendErrorAsync(string text, NadekoInteraction inter = null)
=> ctx.Channel.SendAsync(_eb, text, MsgType.Error, inter);
public Task<IUserMessage> SendConfirmAsync(string text, NadekoInteraction inter = null)
=> ctx.Channel.SendAsync(_eb, text, MsgType.Ok, inter);
public Task<IUserMessage> SendPendingAsync(string text, NadekoInteraction inter = null)
=> ctx.Channel.SendAsync(_eb, text, MsgType.Pending, inter);
// localized normal
public Task<IUserMessage> ErrorLocalizedAsync(LocStr str, NadekoInteraction inter = null)
=> SendErrorAsync(GetText(str), inter);