Point System finalized.
This commit is contained in:
parent
8aa467cef3
commit
19c1c29aed
@ -23,7 +23,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
|
||||
[Command("points")]
|
||||
[CheckCommandPerm("User")]
|
||||
public async Task PointsCommand(string cmd = null, string userMention = null, ulong Amount = 0)
|
||||
public async Task PointsCommand(string cmd = "total", string userMention = null, ulong Amount = 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -41,7 +41,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
}
|
||||
else if ((cmd.ToLower() == "remove") || (cmd.ToLower() == "rem") || (cmd.ToLower() == "take") || (cmd.ToLower() == "-"))
|
||||
{
|
||||
if((Amount != 0) || (await CheckPermissions.CheckPerms(Context, "points.remove", "Admin")))
|
||||
if((Amount != 0) && (await CheckPermissions.CheckPerms(Context, "points.remove", "Admin")))
|
||||
{
|
||||
await RemPoints(userMention, Amount);
|
||||
}
|
||||
@ -52,7 +52,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
}
|
||||
else if ((cmd.ToLower() == "delete") || (cmd.ToLower() == "del"))
|
||||
{
|
||||
if((Amount == 0) || (await CheckPermissions.CheckPerms(Context, "points.remove", "Admin")))
|
||||
if((Amount == 0) && (await CheckPermissions.CheckPerms(Context, "points.remove", "Admin")))
|
||||
{
|
||||
await DelPoints(userMention);
|
||||
}
|
||||
@ -89,7 +89,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
sb.AppendLine($"{Context.User.Mention} has requested points information.");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine($"Usage:");
|
||||
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}points status");
|
||||
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}points info");
|
||||
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}points help");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine("Moderation commands:");
|
||||
@ -151,15 +151,27 @@ namespace ChaosBot.Discord.Modules.User
|
||||
{
|
||||
IQueryable<Point> ctxPoints = dbContext.Points;
|
||||
|
||||
Point usrPoint = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(Context.User.Id)).First();
|
||||
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))));
|
||||
|
||||
cur = usrPoint.Amount + Amount;
|
||||
Point usrPoint;
|
||||
if (ctxPointCheck.Any())
|
||||
{
|
||||
usrPoint = ctxPointCheck.First();
|
||||
cur = usrPoint.Amount + Amount;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
usrPoint = new Point();
|
||||
cur = Amount;
|
||||
}
|
||||
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 => usrPoint).RunAsync();
|
||||
.On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync();
|
||||
|
||||
}
|
||||
|
||||
await ReplyAsync(
|
||||
@ -172,30 +184,51 @@ namespace ChaosBot.Discord.Modules.User
|
||||
{
|
||||
IQueryable<Point> ctxPoints = dbContext.Points;
|
||||
|
||||
Point usrPoint = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(Context.User.Id)).First();
|
||||
Point rctPoint = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4)))).First();
|
||||
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))));
|
||||
|
||||
if (usrPoint.Amount >= Amount)
|
||||
if (ctxUserPoint.Any())
|
||||
{
|
||||
usrPoint.Amount -= Amount;
|
||||
usrPoint.DiscordGuildId = Context.Guild.Id;
|
||||
usrPoint.DiscordUserId = Context.User.Id;
|
||||
Point usrPoint = ctxUserPoint.First();
|
||||
|
||||
await dbContext.Points.Upsert(usrPoint)
|
||||
.On(x => usrPoint).RunAsync();
|
||||
if (usrPoint.Amount >= Amount)
|
||||
{
|
||||
usrPoint.Amount -= Amount;
|
||||
usrPoint.DiscordGuildId = Context.Guild.Id;
|
||||
usrPoint.DiscordUserId = Context.User.Id;
|
||||
|
||||
cur = rctPoint.Amount + Amount;
|
||||
rctPoint.Amount = cur;
|
||||
rctPoint.DiscordGuildId = Context.Guild.Id;
|
||||
rctPoint.DiscordUserId = Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4));
|
||||
await dbContext.Points.Upsert(usrPoint)
|
||||
.On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync();
|
||||
|
||||
await dbContext.Points.Upsert(rctPoint)
|
||||
.On(x => rctPoint).RunAsync();
|
||||
Point rctPoint;
|
||||
if (ctxRctPoint.Any())
|
||||
{
|
||||
rctPoint = ctxRctPoint.First();
|
||||
cur = rctPoint.Amount + Amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
rctPoint = new Point();
|
||||
cur = Amount;
|
||||
}
|
||||
rctPoint.Amount = cur;
|
||||
rctPoint.DiscordGuildId = Context.Guild.Id;
|
||||
rctPoint.DiscordUserId = Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4));
|
||||
|
||||
await ReplyAsync(
|
||||
$"{Context.User.Mention} has given <@{Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4))}> {Amount} points for a total of {cur} points.",
|
||||
false);
|
||||
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.",
|
||||
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.",
|
||||
false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -204,7 +237,6 @@ namespace ChaosBot.Discord.Modules.User
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -223,15 +255,29 @@ namespace ChaosBot.Discord.Modules.User
|
||||
{
|
||||
IQueryable<Point> ctxPoints = dbContext.Points;
|
||||
|
||||
Point usrPoint = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4)))).First();
|
||||
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))));
|
||||
|
||||
cur = (usrPoint.Amount - Amount) >= 1 ? cur : 0;
|
||||
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 => usrPoint).RunAsync();
|
||||
.On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -258,7 +304,7 @@ namespace ChaosBot.Discord.Modules.User
|
||||
usrPoint.DiscordUserId = Convert.ToUInt64(userMention.Substring(3, userMention.Length - 4));
|
||||
|
||||
await dbContext.Points.Upsert(usrPoint)
|
||||
.On(x => usrPoint).RunAsync();
|
||||
.On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user