Change userString parameters to SocketUser params
This commit is contained in:
parent
a6c328d843
commit
289de62f8f
@ -12,6 +12,7 @@ using Discord.Commands;
|
||||
using NLog;
|
||||
using ChaosBot.Repositories;
|
||||
using ChaosBot.Services;
|
||||
using Discord.WebSocket;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
@ -23,7 +24,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
|
||||
[Command("points")]
|
||||
[CheckCommandPerm("User")]
|
||||
public async Task PointsCommand(string cmd = "total", string userMention = null, ulong Amount = 0)
|
||||
public async Task PointsCommand(string cmd = "total", SocketUser user = null, ulong Amount = 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -32,7 +33,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
if(Amount != 0)
|
||||
{
|
||||
Boolean adminAccess = CheckPermissions.CheckPerms(Context, "points.add", "Admin");
|
||||
await AddPoints(userMention, Amount, adminAccess);
|
||||
await AddPoints(user, Amount, adminAccess);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -43,7 +44,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
{
|
||||
if((Amount != 0) && (CheckPermissions.CheckPerms(Context, "points.remove", "Admin")))
|
||||
{
|
||||
await RemPoints(userMention, Amount);
|
||||
await RemPoints(user, Amount);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -54,7 +55,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
{
|
||||
if((Amount == 0) && (CheckPermissions.CheckPerms(Context, "points.remove", "Admin")))
|
||||
{
|
||||
await DelPoints(userMention);
|
||||
await DelPoints(user);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -140,7 +141,52 @@ namespace ChaosBot.Discord.Modules.User
|
||||
|
||||
}
|
||||
|
||||
public async Task AddPoints(string userMention = null, ulong Amount = 0, bool admin = false)
|
||||
public async Task RemPoints(SocketUser user = null, ulong Amount = 0)
|
||||
{
|
||||
ulong cur = 0;
|
||||
try
|
||||
{
|
||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
||||
{
|
||||
IQueryable<Point> ctxPoints = dbContext.Points;
|
||||
|
||||
IQueryable<Point> ctxusrPoint = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(user.Id));
|
||||
|
||||
Point usrPoint;
|
||||
|
||||
if(ctxusrPoint.Any())
|
||||
{
|
||||
usrPoint = ctxusrPoint.First();
|
||||
if (usrPoint.Amount >= Amount)
|
||||
cur = usrPoint.Amount - Amount;
|
||||
else
|
||||
cur = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
usrPoint = new Point();
|
||||
cur = 0;
|
||||
}
|
||||
usrPoint.Amount = cur;
|
||||
usrPoint.DiscordGuildId = Context.Guild.Id;
|
||||
usrPoint.DiscordUserId = user.Id;
|
||||
|
||||
await dbContext.Points.Upsert(usrPoint)
|
||||
.On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(
|
||||
$"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
||||
}
|
||||
|
||||
await ReplyAsync(
|
||||
$"{Context.User.Mention} has taken {Amount} points from {user.Mention} leaving them with a total of {cur} points.",
|
||||
false);
|
||||
}
|
||||
|
||||
public async Task AddPoints(SocketUser user = null, ulong Amount = 0, bool admin = false)
|
||||
{
|
||||
ulong cur = 0;
|
||||
try
|
||||
@ -151,7 +197,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
{
|
||||
IQueryable<Point> ctxPoints = dbContext.Points;
|
||||
|
||||
IQueryable<Point> ctxPointCheck = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4))));
|
||||
IQueryable<Point> ctxPointCheck = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(user.Id));
|
||||
|
||||
Point usrPoint;
|
||||
if (ctxPointCheck.Any())
|
||||
@ -167,7 +213,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
}
|
||||
usrPoint.Amount = cur;
|
||||
usrPoint.DiscordGuildId = Context.Guild.Id;
|
||||
usrPoint.DiscordUserId = Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4));
|
||||
usrPoint.DiscordUserId = user.Id;
|
||||
|
||||
await dbContext.Points.Upsert(usrPoint)
|
||||
.On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync();
|
||||
@ -175,7 +221,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
}
|
||||
|
||||
await ReplyAsync(
|
||||
$"{Context.User.Mention} has added {Amount} points to <@{Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4))}> for a total of {cur} points.",
|
||||
$"{Context.User.Mention} has added {Amount} points to {user.Mention} for a total of {cur} points.",
|
||||
false);
|
||||
}
|
||||
else
|
||||
@ -185,7 +231,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
IQueryable<Point> ctxPoints = dbContext.Points;
|
||||
|
||||
IQueryable<Point> ctxUserPoint = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(Context.User.Id));
|
||||
IQueryable<Point> ctxRctPoint = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4))));
|
||||
IQueryable<Point> ctxRctPoint = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(user.Id));
|
||||
|
||||
if (ctxUserPoint.Any())
|
||||
{
|
||||
@ -213,27 +259,27 @@ namespace ChaosBot.Discord.Modules.User
|
||||
}
|
||||
rctPoint.Amount = cur;
|
||||
rctPoint.DiscordGuildId = Context.Guild.Id;
|
||||
rctPoint.DiscordUserId = Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4));
|
||||
rctPoint.DiscordUserId = user.Id;
|
||||
|
||||
await dbContext.Points.Upsert(rctPoint)
|
||||
.On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync();
|
||||
|
||||
await ReplyAsync(
|
||||
$"{Context.User.Mention} has given <@{Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4))}> {Amount} points for a total of {cur} points.",
|
||||
$"{Context.User.Mention} has given {user.Mention} {Amount} points for a total of {cur} points.",
|
||||
false);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyAsync(
|
||||
$"{Context.User.Mention}, you do not have enough points to give <@{Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4))}> {Amount} points.",
|
||||
$"{Context.User.Mention}, you do not have enough points to give {user.Mention} {Amount} points.",
|
||||
false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyAsync(
|
||||
$"{Context.User.Mention}, you do not have enough points to give <@{Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4))}> {Amount} points.",
|
||||
$"{Context.User.Mention}, you do not have enough points to give {user.Mention} {Amount} points.",
|
||||
false);
|
||||
}
|
||||
}
|
||||
@ -246,52 +292,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
}
|
||||
}
|
||||
|
||||
public async Task RemPoints(string userMention = null, ulong Amount = 0)
|
||||
{
|
||||
ulong cur = 0;
|
||||
try
|
||||
{
|
||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
||||
{
|
||||
IQueryable<Point> ctxPoints = dbContext.Points;
|
||||
|
||||
IQueryable<Point> ctxusrPoint = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4))));
|
||||
|
||||
Point usrPoint;
|
||||
|
||||
if(ctxusrPoint.Any())
|
||||
{
|
||||
usrPoint = ctxusrPoint.First();
|
||||
if (usrPoint.Amount >= Amount)
|
||||
cur = usrPoint.Amount - Amount;
|
||||
else
|
||||
cur = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
usrPoint = new Point();
|
||||
cur = 0;
|
||||
}
|
||||
usrPoint.Amount = cur;
|
||||
usrPoint.DiscordGuildId = Context.Guild.Id;
|
||||
usrPoint.DiscordUserId = Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4));
|
||||
|
||||
await dbContext.Points.Upsert(usrPoint)
|
||||
.On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(
|
||||
$"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
||||
}
|
||||
|
||||
await ReplyAsync(
|
||||
$"{Context.User.Mention} has taken {Amount} points from <@{Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4))}> leaving them with a total of {cur} points.",
|
||||
false);
|
||||
}
|
||||
|
||||
public async Task DelPoints(string userMention = null)
|
||||
public async Task DelPoints(SocketUser user = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -301,7 +302,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
|
||||
usrPoint.Amount = 0;
|
||||
usrPoint.DiscordGuildId = Context.Guild.Id;
|
||||
usrPoint.DiscordUserId = Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4));
|
||||
usrPoint.DiscordUserId = user.Id;
|
||||
|
||||
await dbContext.Points.Upsert(usrPoint)
|
||||
.On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync();
|
||||
@ -314,7 +315,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
}
|
||||
|
||||
await ReplyAsync(
|
||||
$"{Context.User.Mention} has removed all points from <@{Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4))}>.",
|
||||
$"{Context.User.Mention} has removed all points from {user.Mention}.",
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ using Discord.Commands;
|
||||
using NLog;
|
||||
using ChaosBot.Repositories;
|
||||
using ChaosBot.Services;
|
||||
using Discord.WebSocket;
|
||||
|
||||
namespace ChaosBot.Discord.Modules.User
|
||||
{
|
||||
@ -19,7 +20,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
|
||||
[Command("raffle")]
|
||||
[CheckCommandPerm("User")]
|
||||
public async Task RaffleCommand(string cmd = "total", string userMention = null, int Amount = 0)
|
||||
public async Task RaffleCommand(string cmd = "total", SocketUser user = null, int Amount = 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -27,7 +28,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
{
|
||||
if((Amount != 0) && (CheckPermissions.CheckPerms(Context, "raffle.add", "Admin")))
|
||||
{
|
||||
await AddRaffle(userMention, Amount, true);
|
||||
await AddRaffle(user, Amount, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -49,7 +50,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
{
|
||||
if((Amount != 0) && (CheckPermissions.CheckPerms(Context, "raffle.remove", "Admin")))
|
||||
{
|
||||
await RemRaffle(userMention, Amount);
|
||||
await RemRaffle(user, Amount);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -60,7 +61,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
{
|
||||
if((Amount == 0) && (CheckPermissions.CheckPerms(Context, "raffle.remove", "Admin")))
|
||||
{
|
||||
await DelRaffle(userMention);
|
||||
await DelRaffle(user);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -71,10 +72,6 @@ namespace ChaosBot.Discord.Modules.User
|
||||
{
|
||||
await TotalRaffle();
|
||||
}
|
||||
else if ((cmd.ToLower() == "clear") && (CheckPermissions.CheckPerms(Context, "raffle.clear", "Admin")))
|
||||
{
|
||||
await ClearRaffle(userMention);
|
||||
}
|
||||
else
|
||||
{
|
||||
await RaffleHelp();
|
||||
@ -154,7 +151,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
|
||||
}
|
||||
|
||||
public async Task AddRaffle(string userMention = null, int Amount = 0, bool admin = false)
|
||||
public async Task AddRaffle(SocketUser user = null, int Amount = 0, bool admin = false)
|
||||
{
|
||||
int cur = 0;
|
||||
try
|
||||
@ -170,7 +167,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
Raffle usrRaff = new Raffle();
|
||||
|
||||
usrRaff.DiscordGuildId = Context.Guild.Id;
|
||||
usrRaff.DiscordUserId = Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4));
|
||||
usrRaff.DiscordUserId = user.Id;
|
||||
|
||||
dbContext.Raffles.Add(usrRaff);
|
||||
}
|
||||
@ -179,11 +176,12 @@ namespace ChaosBot.Discord.Modules.User
|
||||
|
||||
cur = ctxRaffles
|
||||
.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id))
|
||||
.Where(p => p.DiscordUserId.Equals(Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4)))).Count();
|
||||
.Where(p => p.DiscordUserId.Equals(user.Id))
|
||||
.Count();
|
||||
}
|
||||
|
||||
await ReplyAsync(
|
||||
$"{Context.User.Mention} has added {Amount} tickets to <@{Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4))}> for a total of {cur} tickets.",
|
||||
$"{Context.User.Mention} has added {Amount} tickets to {user.Mention} for a total of {cur} tickets.",
|
||||
false);
|
||||
}
|
||||
}
|
||||
@ -194,7 +192,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
}
|
||||
}
|
||||
|
||||
public async Task RemRaffle(string userMention = null, int Amount = 0)
|
||||
public async Task RemRaffle(SocketUser user = null, int Amount = 0)
|
||||
{
|
||||
int cur = 0;
|
||||
try
|
||||
@ -205,8 +203,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
|
||||
IQueryable<Raffle> ctxRaffleDetail = ctxRaffles
|
||||
.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id))
|
||||
.Where(p => p.DiscordUserId.Equals(
|
||||
Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4))));
|
||||
.Where(p => p.DiscordUserId.Equals(user.Id));
|
||||
|
||||
cur = ctxRaffleDetail.Count();
|
||||
|
||||
@ -231,11 +228,11 @@ namespace ChaosBot.Discord.Modules.User
|
||||
}
|
||||
|
||||
await ReplyAsync(
|
||||
$"{Context.User.Mention} has taken {Amount} raffle tickets from <@{Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4))}> leaving them with a total of {cur-Amount} raffle tickets.",
|
||||
$"{Context.User.Mention} has taken {Amount} raffle tickets from {user.Mention} leaving them with a total of {cur-Amount} raffle tickets.",
|
||||
false);
|
||||
}
|
||||
|
||||
public async Task DelRaffle(string userMention = null)
|
||||
public async Task DelRaffle(SocketUser user = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -245,8 +242,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
|
||||
IQueryable<Raffle> ctxRaffleDetail = ctxRaffles
|
||||
.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id))
|
||||
.Where(p => p.DiscordUserId.Equals(
|
||||
Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4))));
|
||||
.Where(p => p.DiscordUserId.Equals(user.Id));
|
||||
|
||||
int cur = ctxRaffleDetail.Count();
|
||||
|
||||
@ -264,10 +260,12 @@ namespace ChaosBot.Discord.Modules.User
|
||||
}
|
||||
|
||||
await ReplyAsync(
|
||||
$"{Context.User.Mention} has removed all raffle tickets from <@{Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4))}>.",
|
||||
$"{Context.User.Mention} has removed all raffle tickets from {user.Mention}.",
|
||||
false);
|
||||
}
|
||||
|
||||
[Command("raffle clear")]
|
||||
[CheckCommandPerm("Admin")]
|
||||
public async Task ClearRaffle(string confirm = null)
|
||||
{
|
||||
try
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit 88776d67515e8228b31500a9e5fde663fa73ef90
|
||||
Subproject commit 018538162a471a6a028149d27f4b3e992c3c7998
|
||||
Loading…
Reference in New Issue
Block a user