mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-12 02:08:27 -04:00
Restructured folders and project names, ci should be fixed
This commit is contained in:
132
src/NadekoBot/Modules/Administration/DangerousCommands.cs
Normal file
132
src/NadekoBot/Modules/Administration/DangerousCommands.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Common.Attributes;
|
||||
using NadekoBot.Extensions;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using NadekoBot.Core.Modules.Administration.Services;
|
||||
using System.Linq;
|
||||
|
||||
#if !GLOBAL_NADEKO
|
||||
namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
public partial class Administration
|
||||
{
|
||||
[Group]
|
||||
[OwnerOnly]
|
||||
public class DangerousCommands : NadekoSubmodule<DangerousCommandsService>
|
||||
{
|
||||
|
||||
private async Task InternalExecSql(string sql, params object[] reps)
|
||||
{
|
||||
sql = string.Format(sql, reps);
|
||||
try
|
||||
{
|
||||
var embed = new EmbedBuilder()
|
||||
.WithTitle(GetText("sql_confirm_exec"))
|
||||
.WithDescription(Format.Code(sql));
|
||||
|
||||
if (!await PromptUserConfirmAsync(embed).ConfigureAwait(false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var res = await _service.ExecuteSql(sql).ConfigureAwait(false);
|
||||
await ctx.Channel.SendConfirmAsync(res.ToString()).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await ctx.Channel.SendErrorAsync(ex.ToString()).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[OwnerOnly]
|
||||
public Task SqlSelect([Leftover]string sql)
|
||||
{
|
||||
var result = _service.SelectSql(sql);
|
||||
|
||||
return ctx.SendPaginatedConfirmAsync(0, (cur) =>
|
||||
{
|
||||
var items = result.Results.Skip(cur * 20).Take(20);
|
||||
|
||||
if (!items.Any())
|
||||
{
|
||||
return new EmbedBuilder()
|
||||
.WithErrorColor()
|
||||
.WithFooter(sql)
|
||||
.WithDescription("-");
|
||||
}
|
||||
|
||||
return new EmbedBuilder()
|
||||
.WithOkColor()
|
||||
.WithFooter(sql)
|
||||
.WithTitle(string.Join(" ║ ", result.ColumnNames))
|
||||
.WithDescription(string.Join('\n', items.Select(x => string.Join(" ║ ", x))));
|
||||
|
||||
}, result.Results.Count, 20);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[OwnerOnly]
|
||||
public Task SqlExec([Leftover]string sql) =>
|
||||
InternalExecSql(sql);
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[OwnerOnly]
|
||||
public Task DeleteWaifus() =>
|
||||
SqlExec(DangerousCommandsService.WaifusDeleteSql);
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[OwnerOnly]
|
||||
public Task DeleteWaifu(IUser user) =>
|
||||
DeleteWaifu(user.Id);
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[OwnerOnly]
|
||||
public Task DeleteWaifu(ulong userId) =>
|
||||
InternalExecSql(DangerousCommandsService.WaifuDeleteSql, userId);
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[OwnerOnly]
|
||||
public Task DeleteCurrency() =>
|
||||
SqlExec(DangerousCommandsService.CurrencyDeleteSql);
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[OwnerOnly]
|
||||
public Task DeletePlaylists() =>
|
||||
SqlExec(DangerousCommandsService.MusicPlaylistDeleteSql);
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[OwnerOnly]
|
||||
public Task DeleteXp() =>
|
||||
SqlExec(DangerousCommandsService.XpDeleteSql);
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[OwnerOnly]
|
||||
public async Task PurgeUser(ulong userId)
|
||||
{
|
||||
var embed = new EmbedBuilder()
|
||||
.WithDescription(GetText("purge_user_confirm", Format.Bold(userId.ToString())));
|
||||
|
||||
if (!await PromptUserConfirmAsync(embed).ConfigureAwait(false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await _service.PurgeUserAsync(userId);
|
||||
await ctx.OkAsync();
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[OwnerOnly]
|
||||
public Task PurgeUser([Leftover]IUser user)
|
||||
=> PurgeUser(user.Id);
|
||||
//[NadekoCommand, Usage, Description, Aliases]
|
||||
//[OwnerOnly]
|
||||
//public Task DeleteUnusedCrnQ() =>
|
||||
// SqlExec(DangerousCommandsService.DeleteUnusedCustomReactionsAndQuotes);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user