Removing Legacy Point Code
This commit is contained in:
parent
19c1c29aed
commit
e818b4f013
@ -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<string>("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 <discord mention> <amount>");
|
||||
sb.AppendLine($"{prefix}point remove <discord mention> <amount>");
|
||||
sb.AppendLine($"{prefix}point delete <discord mention>");
|
||||
|
||||
/*
|
||||
* 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<Point> 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<Point> 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<Point> 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<Point> points = dbContext.Points;
|
||||
List<Point> 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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user