diff --git a/ChaosBot/Database/Repository/PointsRepository.cs b/ChaosBot/Database/Repository/PointsRepository.cs index d6d063f..6d389c7 100644 --- a/ChaosBot/Database/Repository/PointsRepository.cs +++ b/ChaosBot/Database/Repository/PointsRepository.cs @@ -76,12 +76,6 @@ namespace ChaosBot.Database.Repository } - - - - - - public static int Add(string userId, int points, string guildId) { Dictionary selectfilterDict = new Dictionary(); diff --git a/ChaosBot/Discord/Modules/PointsCommands.cs b/ChaosBot/Discord/Modules/PointsCommands.cs index b86d70b..6fc839d 100644 --- a/ChaosBot/Discord/Modules/PointsCommands.cs +++ b/ChaosBot/Discord/Modules/PointsCommands.cs @@ -8,7 +8,8 @@ using Discord.Commands; using Microsoft.Extensions.Configuration; using NLog; using ChaosBot.Database.Repository; - +using ChaosBot.Database; +using System.Data; namespace ChaosBot.Discord.Modules { @@ -35,7 +36,8 @@ namespace ChaosBot.Discord.Modules sb.AppendLine(); sb.AppendLine("Moderation commands:"); sb.AppendLine($"{prefix}points add "); - sb.AppendLine($"{prefix}point remove"); + sb.AppendLine($"{prefix}point remove "); + sb.AppendLine($"{prefix}point delete "); /* * Add the string to the Embed @@ -89,5 +91,29 @@ namespace ChaosBot.Discord.Modules else await ReplyAsync($"{Context.User.Mention} has tried to remove {amount} points from <@{userId}> they only had {cur} points. None were taken...", false); } + + [Command("points delete")] + [RequireUserPermission(ChannelPermission.ManageMessages)] + public async Task DeletePoints(string userMention) + { + ulong userId = Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4)); + Dictionary filterColumns = new Dictionary + { + { "userId", userId }, + { "guildId", Context.Guild.Id } + }; + Dictionary selectfilterDict = new Dictionary(); + selectfilterDict.Add("userId", userId); + selectfilterDict.Add("guildId", Context.Guild.Id); + DataTable dt = Controller.SelectQuery(Table, "COUNT(*)", selectfilterDict); + int matches = dt.Rows[0]["COUNT(*)"]; + if (matches > 0) + { + Controller.DeleteQuery("PointsTable", filterColumns); + await ReplyAsync($"{Context.User.Mention} has removed <@{userId}> from the database.", false); + } + else + await ReplyAsync($"{Context.User.Mention} has failed to remove <@{userId}> from the database, <@{userId}> does not exist. ", false); + } } }