Merge branch 'master' into cleanup
This commit is contained in:
commit
7e7c11c4ff
@ -76,10 +76,16 @@ namespace ChaosBot.Database.Repository
|
||||
}
|
||||
|
||||
|
||||
public static int Count(string userId, string guildId)
|
||||
{
|
||||
Dictionary<string, object> selectfilterDict = new Dictionary<string, object>();
|
||||
selectfilterDict.Add("userId", userId);
|
||||
selectfilterDict.Add("guildId", guildId);
|
||||
|
||||
DataTable dt = Controller.SelectQuery(Table, "COUNT(*)", selectfilterDict);
|
||||
|
||||
|
||||
|
||||
return Convert.ToInt32(dt.Rows[0]["COUNT(*)"]);
|
||||
}
|
||||
|
||||
|
||||
public static int Add(string userId, int points, string guildId)
|
||||
|
||||
@ -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 <discord mention> <amount>");
|
||||
sb.AppendLine($"{prefix}point remove");
|
||||
sb.AppendLine($"{prefix}point remove <discord mention> <amount>");
|
||||
sb.AppendLine($"{prefix}point delete <discord mention>");
|
||||
|
||||
/*
|
||||
* Add the string to the Embed
|
||||
@ -89,5 +91,33 @@ 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<string, object> filterColumns = new Dictionary<string, object>
|
||||
{
|
||||
{ "userId", userId },
|
||||
{ "guildId", Context.Guild.Id }
|
||||
};
|
||||
|
||||
int matches = PointsRepository.Count(userId.ToString(), Context.Guild.Id.ToString());
|
||||
if (matches > 0)
|
||||
{
|
||||
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
|
||||
{
|
||||
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