Applied codestyle to all .cs files

This commit is contained in:
Kwoth
2021-12-29 06:07:16 +01:00
parent 723447c7d4
commit 82000c97a4
543 changed files with 13221 additions and 14059 deletions

View File

@@ -1,8 +1,8 @@
#nullable disable
using NadekoBot.Db.Models;
using Microsoft.EntityFrameworkCore;
#nullable disable
using LinqToDB;
using LinqToDB.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Db.Models;
using NadekoBot.Services.Database;
namespace NadekoBot.Db;
@@ -16,19 +16,18 @@ public static class DiscordUserExtensions
string discrim,
string avatarId)
=> ctx.DiscordUser.ToLinqToDBTable()
.InsertOrUpdate(
() => new()
{
UserId = userId,
Username = username,
Discriminator = discrim,
AvatarId = avatarId,
TotalXp = 0,
CurrencyAmount = 0
},
old => new() { Username = username, Discriminator = discrim, AvatarId = avatarId, },
() => new() { UserId = userId }
);
.InsertOrUpdate(
() => new()
{
UserId = userId,
Username = username,
Discriminator = discrim,
AvatarId = avatarId,
TotalXp = 0,
CurrencyAmount = 0
},
old => new() { Username = username, Discriminator = discrim, AvatarId = avatarId },
() => new() { UserId = userId });
//temp is only used in updatecurrencystate, so that i don't overwrite real usernames/discrims with Unknown
public static DiscordUser GetOrCreateUser(
@@ -38,40 +37,22 @@ public static class DiscordUserExtensions
string discrim,
string avatarId)
{
ctx.EnsureUserCreated(userId,
username,
discrim,
avatarId
);
return ctx.DiscordUser.Include(x => x.Club)
.First(u => u.UserId == userId);
ctx.EnsureUserCreated(userId, username, discrim, avatarId);
return ctx.DiscordUser.Include(x => x.Club).First(u => u.UserId == userId);
}
public static DiscordUser GetOrCreateUser(this NadekoContext ctx, IUser original)
=> ctx.GetOrCreateUser(original.Id,
original.Username,
original.Discriminator,
original.AvatarId
);
=> ctx.GetOrCreateUser(original.Id, original.Username, original.Discriminator, original.AvatarId);
public static int GetUserGlobalRank(this DbSet<DiscordUser> users, ulong id)
=> users.AsQueryable()
.Where(x => x.TotalXp >
users.AsQueryable()
.Where(y => y.UserId == id)
.Select(y => y.TotalXp)
.FirstOrDefault()
)
.Count() +
1;
.Where(x => x.TotalXp
> users.AsQueryable().Where(y => y.UserId == id).Select(y => y.TotalXp).FirstOrDefault())
.Count()
+ 1;
public static DiscordUser[] GetUsersXpLeaderboardFor(this DbSet<DiscordUser> users, int page)
=> users.AsQueryable()
.OrderByDescending(x => x.TotalXp)
.Skip(page * 9)
.Take(9)
.AsEnumerable()
.ToArray();
=> users.AsQueryable().OrderByDescending(x => x.TotalXp).Skip(page * 9).Take(9).AsEnumerable().ToArray();
public static List<DiscordUser> GetTopRichest(
this DbSet<DiscordUser> users,
@@ -79,26 +60,19 @@ public static class DiscordUserExtensions
int count,
int page = 0)
=> users.AsQueryable()
.Where(c => c.CurrencyAmount > 0 && botId != c.UserId)
.OrderByDescending(c => c.CurrencyAmount)
.Skip(page * 9)
.Take(count)
.ToList();
.Where(c => c.CurrencyAmount > 0 && botId != c.UserId)
.OrderByDescending(c => c.CurrencyAmount)
.Skip(page * 9)
.Take(count)
.ToList();
public static long GetUserCurrency(this DbSet<DiscordUser> users, ulong userId)
=> users.AsNoTracking()
.FirstOrDefault(x => x.UserId == userId)
?.CurrencyAmount ??
0;
=> users.AsNoTracking().FirstOrDefault(x => x.UserId == userId)?.CurrencyAmount ?? 0;
public static void RemoveFromMany(this DbSet<DiscordUser> users, IEnumerable<ulong> ids)
{
var items = users.AsQueryable()
.Where(x => ids.Contains(x.UserId));
foreach (var item in items)
{
item.CurrencyAmount = 0;
}
var items = users.AsQueryable().Where(x => ids.Contains(x.UserId));
foreach (var item in items) item.CurrencyAmount = 0;
}
public static bool TryUpdateCurrencyState(
@@ -115,14 +89,12 @@ public static class DiscordUserExtensions
// if remove - try to remove if he has more or equal than the amount
// and return number of rows > 0 (was there a change)
if (amount < 0 &&
!allowNegative)
if (amount < 0 && !allowNegative)
{
var rows = ctx.Database.ExecuteSqlInterpolated($@"
UPDATE DiscordUser
SET CurrencyAmount=CurrencyAmount+{amount}
WHERE UserId={userId} AND CurrencyAmount>={-amount};"
);
WHERE UserId={userId} AND CurrencyAmount>={-amount};");
return rows > 0;
}
@@ -132,8 +104,7 @@ WHERE UserId={userId} AND CurrencyAmount>={-amount};"
var rows = ctx.Database.ExecuteSqlInterpolated($@"
UPDATE DiscordUser
SET CurrencyAmount=CurrencyAmount+{amount}
WHERE UserId={userId};"
);
WHERE UserId={userId};");
return rows > 0;
}
@@ -147,7 +118,6 @@ WHERE UserId={userId};"
// just update the amount, there is no new user data
if (!updatedUserData)
{
ctx.Database.ExecuteSqlInterpolated($@"
UPDATE OR IGNORE DiscordUser
SET CurrencyAmount=CurrencyAmount+{amount}
@@ -155,11 +125,8 @@ WHERE UserId={userId};
INSERT OR IGNORE INTO DiscordUser (UserId, Username, Discriminator, AvatarId, CurrencyAmount, TotalXp)
VALUES ({userId}, {name}, {discrim}, {avatarId}, {amount}, 0);
"
);
}
");
else
{
ctx.Database.ExecuteSqlInterpolated($@"
UPDATE OR IGNORE DiscordUser
SET CurrencyAmount=CurrencyAmount+{amount},
@@ -170,9 +137,7 @@ WHERE UserId={userId};
INSERT OR IGNORE INTO DiscordUser (UserId, Username, Discriminator, AvatarId, CurrencyAmount, TotalXp)
VALUES ({userId}, {name}, {discrim}, {avatarId}, {amount}, 0);
"
);
}
");
return true;
}
@@ -182,8 +147,8 @@ VALUES ({userId}, {name}, {discrim}, {avatarId}, {amount}, 0);
public static decimal GetTopOnePercentCurrency(this DbSet<DiscordUser> users, ulong botId)
=> users.AsQueryable()
.Where(x => x.UserId != botId)
.OrderByDescending(x => x.CurrencyAmount)
.Take(users.Count() / 100 == 0 ? 1 : users.Count() / 100)
.Sum(x => x.CurrencyAmount);
}
.Where(x => x.UserId != botId)
.OrderByDescending(x => x.CurrencyAmount)
.Take(users.Count() / 100 == 0 ? 1 : users.Count() / 100)
.Sum(x => x.CurrencyAmount);
}