mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-12 10:18:27 -04:00
Rewrote several raw queries to linqtodb
This commit is contained in:
@@ -10,27 +10,26 @@ namespace NadekoBot.Modules.Administration
|
||||
[OwnerOnly]
|
||||
public partial class DangerousCommands : NadekoModule<DangerousCommandsService>
|
||||
{
|
||||
private async Task InternalExecSql(string sql, params object[] reps)
|
||||
private async Task ConfirmActionInternalAsync(string name, Func<Task> action)
|
||||
{
|
||||
sql = string.Format(sql, reps);
|
||||
try
|
||||
{
|
||||
var embed = _eb.Create()
|
||||
.WithTitle(GetText(strs.sql_confirm_exec))
|
||||
.WithDescription(Format.Code(sql));
|
||||
.WithDescription(name);
|
||||
|
||||
if (!await PromptUserConfirmAsync(embed))
|
||||
return;
|
||||
|
||||
var res = await _service.ExecuteSql(sql);
|
||||
await SendConfirmAsync(res.ToString());
|
||||
await action();
|
||||
await ctx.OkAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await SendErrorAsync(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Cmd]
|
||||
[OwnerOnly]
|
||||
public partial Task SqlSelect([Leftover] string sql)
|
||||
@@ -57,38 +56,55 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
[Cmd]
|
||||
[OwnerOnly]
|
||||
public partial Task SqlExec([Leftover] string sql)
|
||||
=> InternalExecSql(sql);
|
||||
public async partial Task SqlExec([Leftover] string sql)
|
||||
{
|
||||
try
|
||||
{
|
||||
var embed = _eb.Create()
|
||||
.WithTitle(GetText(strs.sql_confirm_exec))
|
||||
.WithDescription(Format.Code(sql));
|
||||
|
||||
if (!await PromptUserConfirmAsync(embed))
|
||||
return;
|
||||
|
||||
var res = await _service.ExecuteSql(sql);
|
||||
await SendConfirmAsync(res.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await SendErrorAsync(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[OwnerOnly]
|
||||
public partial Task DeleteWaifus()
|
||||
=> SqlExec(DangerousCommandsService.WAIFUS_DELETE_SQL);
|
||||
=> ConfirmActionInternalAsync("Delete Waifus", () => _service.DeleteWaifus());
|
||||
|
||||
[Cmd]
|
||||
[OwnerOnly]
|
||||
public partial Task DeleteWaifu(IUser user)
|
||||
=> DeleteWaifu(user.Id);
|
||||
public async partial Task DeleteWaifu(IUser user)
|
||||
=> await DeleteWaifu(user.Id);
|
||||
|
||||
[Cmd]
|
||||
[OwnerOnly]
|
||||
public partial Task DeleteWaifu(ulong userId)
|
||||
=> InternalExecSql(DangerousCommandsService.WAIFU_DELETE_SQL, userId);
|
||||
=> ConfirmActionInternalAsync($"Delete Waifu {userId}", () => _service.DeleteWaifu(userId));
|
||||
|
||||
[Cmd]
|
||||
[OwnerOnly]
|
||||
public partial Task DeleteCurrency()
|
||||
=> SqlExec(DangerousCommandsService.CURRENCY_DELETE_SQL);
|
||||
=> ConfirmActionInternalAsync("Delete Currency", () => _service.DeleteCurrency());
|
||||
|
||||
[Cmd]
|
||||
[OwnerOnly]
|
||||
public partial Task DeletePlaylists()
|
||||
=> SqlExec(DangerousCommandsService.MUSIC_PLAYLIST_DELETE_SQL);
|
||||
=> ConfirmActionInternalAsync("Delete Playlists", () => _service.DeletePlaylists());
|
||||
|
||||
[Cmd]
|
||||
[OwnerOnly]
|
||||
public partial Task DeleteXp()
|
||||
=> SqlExec(DangerousCommandsService.XP_DELETE_SQL);
|
||||
=> ConfirmActionInternalAsync("Delete Xp", () => _service.DeleteXp());
|
||||
|
||||
[Cmd]
|
||||
[OwnerOnly]
|
||||
@@ -108,10 +124,6 @@ namespace NadekoBot.Modules.Administration
|
||||
[OwnerOnly]
|
||||
public partial Task PurgeUser([Leftover] IUser user)
|
||||
=> PurgeUser(user.Id);
|
||||
//[NadekoCommand, Usage, Description, Aliases]
|
||||
//[OwnerOnly]
|
||||
//public partial Task DeleteUnusedCrnQ() =>
|
||||
// SqlExec(DangerousCommandsService.DeleteUnusedExpressionsAndQuotes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user