From 9871d402de82faf51b439ec8e40ca237b6481a15 Mon Sep 17 00:00:00 2001 From: Daniel-I-Am Date: Sat, 6 Jun 2020 02:42:14 +0200 Subject: [PATCH] Rework DeletePoints method to use Count Repository method --- ChaosBot/Discord/Modules/PointsCommands.cs | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/ChaosBot/Discord/Modules/PointsCommands.cs b/ChaosBot/Discord/Modules/PointsCommands.cs index 6fc839d..5a4bbdd 100644 --- a/ChaosBot/Discord/Modules/PointsCommands.cs +++ b/ChaosBot/Discord/Modules/PointsCommands.cs @@ -102,18 +102,22 @@ namespace ChaosBot.Discord.Modules { "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(*)"]; + + int matches = PointsRepository.Count(userId.ToString(), Context.Guild.Id.ToString()); if (matches > 0) - { - Controller.DeleteQuery("PointsTable", filterColumns); - await ReplyAsync($"{Context.User.Mention} has removed <@{userId}> from the database.", false); - } + { + Controller.DeleteQuery("PointsTable", filterColumns); + + string message = $"{Context.User.Mention} has removed <@{userId}> from the database."; + await ReplyAsync(message, false); + _logger.Info($"PointsCommands.DeletePoints: {message}"); + } else - await ReplyAsync($"{Context.User.Mention} has failed to remove <@{userId}> from the database, <@{userId}> does not exist. ", false); + { + string message = $"{Context.User.Mention} has failed to remove <@{userId}> from the database, <@{userId}> does not exist."; + await ReplyAsync(message, false); + _logger.Warn($"PointsCommands.DeletePoints: {message}"); + } } } }