Improved support for sql execution, added some pre-built queries which people would probably want to use.

This commit is contained in:
Master Kwoth 2017-10-13 04:41:01 +02:00
parent 998c048874
commit e434de5abb
5 changed files with 63 additions and 11 deletions

View File

@ -2,12 +2,11 @@
using Microsoft.EntityFrameworkCore;
using NadekoBot.Common.Attributes;
using NadekoBot.Extensions;
using NadekoBot.Modules;
using NadekoBot.Services;
using System;
using System.Threading.Tasks;
#if DEBUG
#if !GLOBAL_NADEKO
namespace NadekoBot.Modules.Administration
{
public partial class Administration
@ -42,6 +41,33 @@ namespace NadekoBot.Modules.Administration
await Context.Channel.SendErrorAsync(ex.ToString());
}
}
[NadekoCommand, Usage, Description, Aliases]
[OwnerOnly]
public Task DeleteWaifus() =>
ExecSql("DELETE FROM WaifuUpdates; DELETE FROM WaifuInfo;");
[NadekoCommand, Usage, Description, Aliases]
[OwnerOnly]
public Task DeleteCurrency() =>
ExecSql("DELETE FROM Currency; DELETE FROM CurrencyTransactions;");
[NadekoCommand, Usage, Description, Aliases]
[OwnerOnly]
public Task DeletePlaylists() =>
ExecSql("DELETE FROM MusicPlaylists;");
[NadekoCommand, Usage, Description, Aliases]
[OwnerOnly]
public Task DeleteExp() =>
ExecSql(@"DELETE FROM UserXpStats;
UPDATE DiscordUser
SET ClubId=NULL,
IsClubAdmin=0,
TotalXp=0;
DELETE FROM ClubApplicants;
DELETE FROM ClubBans;
DELETE FROM Clubs;");
}
}
}

View File

@ -51,7 +51,6 @@ namespace NadekoBot.Services.Database
//orphans xD
public DbSet<EightBallResponse> EightBallResponses { get; set; }
public DbSet<RaceAnimal> RaceAnimals { get; set; }
public DbSet<ModulePrefix> ModulePrefixes { get; set; }
public DbSet<RewardedUser> RewardedUsers { get; set; }
public NadekoContext(DbContextOptions<NadekoContext> options) : base(options)

View File

@ -132,8 +132,6 @@ namespace NadekoBot
IBotConfigProvider botConfigProvider = new BotConfigProvider(_db, _botConfig);
//var localization = new Localization(_botConfig.Locale, AllGuildConfigs.ToDictionary(x => x.GuildId, x => x.Locale), Db);
//initialize Services
Services = new NServiceProvider()
.AddManual<IBotCredentials>(Credentials)
@ -175,9 +173,7 @@ namespace NadekoBot
var toReturn = new List<object>();
foreach (var ft in filteredTypes)
{
//:yayyy:
var x = (TypeReader)Activator.CreateInstance(ft, Client, CommandService);
//@.@ XD XDDD
var baseType = ft.BaseType;
var typeArgs = baseType.GetGenericArguments();
try

View File

@ -11,10 +11,6 @@ using NadekoBot.Common;
using NadekoBot.Common.Attributes;
using NadekoBot.Modules.Gambling.Services;
//todo add .deletewaifus
//todo add .deletecurrency
//todo add .deleteplaylists
//todo add .deletexp
namespace NadekoBot.Modules.Gambling
{
public partial class Gambling

View File

@ -3002,5 +3002,40 @@
"usage": [
"{0}say hi"
]
},
"execsql": {
"cmd": "execsql",
"desc": "Executes an sql command and returns the number of affected rows. Dangerous.",
"usage": [
"{0}execsql UPDATE Currency SET Amount=Amount+1234"
]
},
"deletewaifus": {
"cmd": "deletewaifus",
"desc": "Deletes everything from WaifuUpdates and WaifuInfo tables.",
"usage": [
"{0}deletewaifus"
]
},
"deletecurrency": {
"cmd": "deletecurrency",
"desc": "Deletes everything from Currency and CurrencyTransactions.",
"usage": [
"{0}deletecurrency"
]
},
"deleteplaylists": {
"cmd": "deleteplaylists",
"desc": "Deletes everything from MusicPlaylists.",
"usage": [
"{0}deleteplaylists"
]
},
"deletexp": {
"cmd": "deletexp",
"desc": "Deletes everything from UserXpStats, Clubs and sets users' TotalXP to 0.",
"usage": [
"{0}execsql UPDATE Currency SET Amount=Amount+1234"
]
}
}