- Reaction roles rewritten completely. They now support multiple exclusivity groups per message and level requirements. However they can only be added one by one

- Bot now support much higher XP values for global and server levels
This commit is contained in:
Kwoth
2022-05-04 02:08:15 +02:00
parent 5cb95cf94d
commit 5b5bc278ff
35 changed files with 10820 additions and 715 deletions

View File

@@ -17,7 +17,6 @@ using Image = SixLabors.ImageSharp.Image;
namespace NadekoBot.Modules.Xp.Services;
// todo improve xp with linqtodb
public class XpService : INService, IReadyExecutor, IExecNoCommand
{
public const int XP_REQUIRED_LVL_1 = 36;
@@ -133,7 +132,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
try
{
var toNotify =
new List<(IGuild Guild, IMessageChannel MessageChannel, IUser User, int Level,
new List<(IGuild Guild, IMessageChannel MessageChannel, IUser User, long Level,
XpNotificationLocation NotifyType, NotifOf NotifOf)>();
var roleRewards = new Dictionary<ulong, List<XpRoleReward>>();
var curRewards = new Dictionary<ulong, List<XpCurrencyReward>>();
@@ -640,7 +639,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
{
DiscordUser du;
UserXpStats stats;
int totalXp;
long totalXp;
int globalRank;
int guildRank;
await using (var uow = _db.GetDbContext())

View File

@@ -1,29 +1,15 @@
#nullable disable
using NadekoBot.Modules.Xp.Services;
using LinqToDB;
using NadekoBot.Services.Database.Models;
namespace NadekoBot.Modules.Xp.Extensions;
public static class Extensions
{
public static (int Level, int LevelXp, int LevelRequiredXp) GetLevelData(this UserXpStats stats)
{
var baseXp = XpService.XP_REQUIRED_LVL_1;
var required = baseXp;
var totalXp = 0;
var lvl = 1;
while (true)
{
required = (int)(baseXp + (baseXp / 4.0 * (lvl - 1)));
if (required + totalXp > stats.Xp)
break;
totalXp += required;
lvl++;
}
return (lvl - 1, stats.Xp - totalXp, required);
}
public static async Task<LevelStats> GetLevelDataFor(this ITable<UserXpStats> userXp, ulong guildId, ulong userId)
=> await userXp
.Where(x => x.GuildId == guildId && x.UserId == userId)
.FirstOrDefaultAsync() is UserXpStats uxs
? new(uxs.Xp + uxs.AwardedXp)
: new(0);
}

View File

@@ -5,12 +5,12 @@ namespace NadekoBot.Modules.Xp;
public class LevelStats
{
public int Level { get; }
public int LevelXp { get; }
public int RequiredXp { get; }
public int TotalXp { get; }
public long Level { get; }
public long LevelXp { get; }
public long RequiredXp { get; }
public long TotalXp { get; }
public LevelStats(int xp)
public LevelStats(long xp)
{
if (xp < 0)
xp = 0;