Fix Entity data types to longs

This commit is contained in:
Daniel_I_Am 2020-06-15 01:11:40 +02:00
parent 707e0b1bc1
commit 7046b97bee
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84
3 changed files with 12 additions and 13 deletions

View File

@ -11,14 +11,14 @@ namespace ChaosBot.Database.Entity
[DBAutoIncrement] [DBAutoIncrement]
[DBNotNull] [DBNotNull]
[DBUnique] [DBUnique]
public Nullable<int> id { get; private set; } public Nullable<long> id { get; private set; }
public int points { get; private set; } public long points { get; private set; }
public long userId { get; private set; } public long userId { get; private set; }
public long guildId { get; private set; } public long guildId { get; private set; }
public Points() {} public Points() {}
public Points(int id, long userId, long guildId, int points) public Points(long id, long userId, long guildId, int points)
{ {
this.id = id; this.id = id;
this.userId = userId; this.userId = userId;
@ -26,7 +26,7 @@ namespace ChaosBot.Database.Entity
this.points = points; this.points = points;
} }
public Points(long userId, long guildId, int points) public Points(long userId, long guildId, long points)
{ {
this.points = points; this.points = points;
this.userId = userId; this.userId = userId;
@ -40,10 +40,10 @@ namespace ChaosBot.Database.Entity
public override void SetFromRow(DataRow row) public override void SetFromRow(DataRow row)
{ {
id = (int)row["id"]; id = (long)row["id"];
userId = (long)row["userId"]; userId = (long)row["userId"];
guildId = (long)row["guildId"]; guildId = (long)row["guildId"];
points = (int)row["points"]; points = (long)row["points"];
} }
} }
} }

View File

@ -24,7 +24,7 @@ namespace ChaosBot.Database.Repository
} }
public static int Total(long userId, long guildId) public static long Total(long userId, long guildId)
{ {
Points userPoints = Points.Query().Where("userId", userId).Where("guildId", guildId).First(); Points userPoints = Points.Query().Where("userId", userId).Where("guildId", guildId).First();
@ -43,14 +43,13 @@ namespace ChaosBot.Database.Repository
} }
public static int Add(long userId, int points, long guildId) public static long Add(long userId, long points, long guildId)
{ {
Points userPoints = Points.Query().Where("userId", userId).Where("guildId", guildId).First(); Points userPoints = Points.Query().Where("userId", userId).Where("guildId", guildId).First();
if (userPoints != null) if (userPoints != null)
{ {
Points.Query().Where("userId", userId).Where("guildId", guildId).Set("points", userPoints.points + points).Update(); Points.Query().Where("userId", userId).Where("guildId", guildId).Set("points", userPoints.points + points).Update();
return userPoints.points + points; return userPoints.points + points;
} }
Points newUserPoints = new Points(userId, guildId, points); Points newUserPoints = new Points(userId, guildId, points);
@ -59,7 +58,7 @@ namespace ChaosBot.Database.Repository
return points; return points;
} }
public static int Remove(long userId, int points, long guildId) public static long Remove(long userId, long points, long guildId)
{ {
Points userPoints = Points.Query().Where("userId", userId).Where("guildId", guildId).First(); Points userPoints = Points.Query().Where("userId", userId).Where("guildId", guildId).First();

View File

@ -58,7 +58,7 @@ namespace ChaosBot.Discord.Modules
[Alias("points info")] [Alias("points info")]
public async Task PointsCommandTotal() public async Task PointsCommandTotal()
{ {
int cur = PointsRepository.Total(Convert.ToInt64(Context.User.Id), Convert.ToInt64(Context.Guild.Id)); long cur = PointsRepository.Total(Convert.ToInt64(Context.User.Id), Convert.ToInt64(Context.Guild.Id));
await ReplyAsync($"You have {cur} points.", false); await ReplyAsync($"You have {cur} points.", false);
} }
@ -82,10 +82,10 @@ namespace ChaosBot.Discord.Modules
[Command("points remove")] [Command("points remove")]
[RequireUserPermission(ChannelPermission.ManageMessages)] [RequireUserPermission(ChannelPermission.ManageMessages)]
public async Task RaffleCommandRemove(string user, int amount = 1) public async Task RaffleCommandRemove(string user, long amount = 1)
{ {
ulong userId = Convert.ToUInt64(user.Substring(3, user.Length - 4)); ulong userId = Convert.ToUInt64(user.Substring(3, user.Length - 4));
int cur = PointsRepository.Total(Convert.ToInt64(Context.User.Id), Convert.ToInt64(Context.Guild.Id)); long cur = PointsRepository.Total(Convert.ToInt64(Context.User.Id), Convert.ToInt64(Context.Guild.Id));
if (cur > 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); 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 else