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