From e818b4f013dcb829b4cfb4e934c748d04dac087a Mon Sep 17 00:00:00 2001 From: Sean Stoves Date: Wed, 5 Aug 2020 23:13:31 -0400 Subject: [PATCH] Removing Legacy Point Code --- .../Discord/ModulesOld/PointsCommands.cs.txt | 157 ------------------ 1 file changed, 157 deletions(-) delete mode 100644 ChaosBot/Discord/ModulesOld/PointsCommands.cs.txt diff --git a/ChaosBot/Discord/ModulesOld/PointsCommands.cs.txt b/ChaosBot/Discord/ModulesOld/PointsCommands.cs.txt deleted file mode 100644 index 0257089..0000000 --- a/ChaosBot/Discord/ModulesOld/PointsCommands.cs.txt +++ /dev/null @@ -1,157 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using ChaosBot.Migrations; -using ChaosBot.Models; -using Discord; -using Discord.Commands; -using NLog; -using ChaosBot.Repositories; - -namespace ChaosBot.Discord.Modules -{ - public class PointsCommands : ModuleBase - { - private static ILogger _logger = Program.Logger; - - [Command("points help")] - public async Task PointsCommandInfo() - { - try - { - var sb = new StringBuilder(); - var embed = new EmbedBuilder(); - string prefix = ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!"); - - embed.WithColor(new Color(255, 255, 0)); - embed.Title = $"Points system"; - sb.AppendLine($"{Context.User.Mention} has requested points information."); - sb.AppendLine(); - sb.AppendLine($"Usage:"); - sb.AppendLine($"{prefix}points status"); - sb.AppendLine($"{prefix}points help"); - sb.AppendLine(); - sb.AppendLine("Moderation commands:"); - sb.AppendLine($"{prefix}points add "); - sb.AppendLine($"{prefix}point remove "); - sb.AppendLine($"{prefix}point delete "); - - /* - * Add the string to the Embed - */ - embed.Description = sb.ToString(); - - /* - * Reply with the Embed created above - */ - await ReplyAsync(null, false, embed.Build()); - } - catch (Exception ex) - { - _logger.Error($"InfoCommands.InfoCommand: Exception [{ex}] thrown, <[{ex.Message}]>."); - } - } - [Command("points")] - [Alias("points info")] - public async Task PointsCommandTotal() - { - ulong cur; - using (ChaosbotContext dbContext = new ChaosbotContext()) - { - IQueryable points = dbContext.Points; - cur = points - .Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)) - .Where(p => p.DiscordUserId.Equals(Context.User.Id)) - .First().Amount; - } - await ReplyAsync($"You have {cur} points.", false); - - } - - [Command("points add")] - [RequireUserPermission(ChannelPermission.ManageMessages)] - public async Task RaffleCommandAdd(string user, int amount = 1) - { - - if (ChannelPermissions.Text.ManageMessages) - { - ulong userId = Convert.ToUInt64(user.Substring(3, user.Length - 4)); - - await ReplyAsync($"{Context.User.Mention} has given <@{userId}> {amount} points for a total of {PointsRepository.Add(Convert.ToInt64(userId), amount, Convert.ToInt64(Context.Guild.Id))} points.", false); - } - else - await ReplyAsync($"NO ACCESS"); - - - } - - [Command("points remove")] - [RequireUserPermission(ChannelPermission.ManageMessages)] - public async Task RaffleCommandRemove(string user, ulong amount = 1) - { - ulong userId = Convert.ToUInt64(user.Substring(3, user.Length - 4)); - ulong cur; - using (ChaosbotContext dbContext = new ChaosbotContext()) - { - IQueryable points = dbContext.Points; - cur = points - .Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)) - .Where(p => p.DiscordUserId.Equals(Context.User.Id)) - .First().Amount; - } - if (cur > amount) - await ReplyAsync($"{Context.User.Mention} has removed {amount} points from <@{userId}> for a total of {PointsRepository.Remove(Convert.ToInt64(userId), amount, Convert.ToInt64(Context.Guild.Id))} points.", false); - 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)); - - // int matches = PointsRepository.Count(Convert.ToInt64(userId), Convert.ToInt64(Context.Guild.Id)); - - int matches; - using (ChaosbotContext dbContext = new ChaosbotContext()) - { - IQueryable points = dbContext.Points; - matches = points - .Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)) - .Where(p => p.DiscordUserId.Equals(Context.User.Id)) - .Count(); - } - if (matches > 0) - { - using (ChaosbotContext dbContext = new ChaosbotContext()) - { - IQueryable points = dbContext.Points; - List pointList = points - .Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)) - .Where(p => p.DiscordUserId.Equals(Context.User.Id)) - .ToList(); - - foreach (Point point in pointList) - { - dbContext.Remove(point); - } - - dbContext.SaveChanges(); - } - - string message = $"{Context.User.Mention} has removed <@{userId}> from the database."; - await ReplyAsync(message, false); - _logger.Info($"PointsCommands.DeletePoints: {message}"); - } - else - { - 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}"); - } - } - } -}