Fixes to .xprr, leveling system

This commit is contained in:
Master Kwoth 2017-09-11 22:43:32 +02:00
parent d658fe7414
commit 4c591a69b1
7 changed files with 2000 additions and 11 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
namespace NadekoBot.Migrations
{
public partial class lastXpGain : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "LastXpGain",
table: "DiscordUser",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
migrationBuilder.Sql("DELETE FROM XpRoleReward WHERE XpSettingsId is null");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "LastXpGain",
table: "DiscordUser");
}
}
}

View File

@ -464,7 +464,9 @@ namespace NadekoBot.Migrations
b.Property<DateTime>("LastLevelUp") b.Property<DateTime>("LastLevelUp")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasDefaultValue(new DateTime(2017, 9, 9, 1, 7, 29, 857, DateTimeKind.Local)); .HasDefaultValue(new DateTime(2017, 9, 11, 22, 0, 31, 236, DateTimeKind.Local));
b.Property<DateTime>("LastXpGain");
b.Property<int>("NotifyOnLevelUp"); b.Property<int>("NotifyOnLevelUp");
@ -1360,7 +1362,7 @@ namespace NadekoBot.Migrations
b.Property<DateTime>("LastLevelUp") b.Property<DateTime>("LastLevelUp")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasDefaultValue(new DateTime(2017, 9, 9, 1, 7, 29, 858, DateTimeKind.Local)); .HasDefaultValue(new DateTime(2017, 9, 11, 22, 0, 31, 238, DateTimeKind.Local));
b.Property<int>("NotifyOnLevelUp"); b.Property<int>("NotifyOnLevelUp");

View File

@ -131,8 +131,6 @@ namespace NadekoBot.Modules.Xp.Services
if (toAddTo.Count == 0) if (toAddTo.Count == 0)
return; return;
_log.Info("Adding XP to {0} users.", toAddTo.Count);
using (var uow = _db.UnitOfWork) using (var uow = _db.UnitOfWork)
{ {
foreach (var item in group) foreach (var item in group)
@ -142,6 +140,11 @@ namespace NadekoBot.Modules.Xp.Services
var usr = uow.Xp.GetOrCreateUser(item.Key.GuildId, item.Key.User.Id); var usr = uow.Xp.GetOrCreateUser(item.Key.GuildId, item.Key.User.Id);
var du = uow.DiscordUsers.GetOrCreate(item.Key.User); var du = uow.DiscordUsers.GetOrCreate(item.Key.User);
if (du.LastXpGain + TimeSpan.FromMinutes(_bc.BotConfig.XpMinutesTimeout) > DateTime.UtcNow)
continue;
du.LastXpGain = DateTime.UtcNow;
var globalXp = uow.Xp.GetTotalUserXp(item.Key.User.Id); var globalXp = uow.Xp.GetTotalUserXp(item.Key.User.Id);
var oldGlobalLevelData = new LevelStats(globalXp); var oldGlobalLevelData = new LevelStats(globalXp);
var newGlobalLevelData = new LevelStats(globalXp + xp); var newGlobalLevelData = new LevelStats(globalXp + xp);
@ -239,6 +242,9 @@ namespace NadekoBot.Modules.Xp.Services
} }
}, null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5)); }, null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5));
//just a first line, in order to prevent queries. But since other shards can try to do this too,
//i'll check in the db too.
var clearRewardTimer = Task.Run(async () => var clearRewardTimer = Task.Run(async () =>
{ {
while (true) while (true)
@ -268,10 +274,16 @@ namespace NadekoBot.Modules.Xp.Services
if (roleId == null) if (roleId == null)
{ {
settings.RoleRewards.RemoveWhere(x => x.Level == level); var toRemove = settings.RoleRewards.FirstOrDefault(x => x.Level == level);
if (toRemove != null)
{
uow._context.Remove(toRemove);
settings.RoleRewards.Remove(toRemove);
}
} }
else else
{ {
var rew = settings.RoleRewards.FirstOrDefault(x => x.Level == level); var rew = settings.RoleRewards.FirstOrDefault(x => x.Level == level);
if (rew != null) if (rew != null)
@ -553,7 +565,7 @@ namespace NadekoBot.Modules.Xp.Services
_timeFont = _fonts.Find("Whitney-Bold").CreateFont(20); _timeFont = _fonts.Find("Whitney-Bold").CreateFont(20);
} }
public async Task<Image<Rgba32>> GenerateImageAsync(FullUserStats stats) public Task<Image<Rgba32>> GenerateImageAsync(FullUserStats stats) => Task.Run(async () =>
{ {
var img = Image.Load(_images.XpCard.ToArray()); var img = Image.Load(_images.XpCard.ToArray());
@ -717,7 +729,7 @@ namespace NadekoBot.Modules.Xp.Services
//_log.Info("{0:F2} KB", arr.Length * 1.0f / 1.KB()); //_log.Info("{0:F2} KB", arr.Length * 1.0f / 1.KB());
return img; return img;
} });
// https://github.com/SixLabors/ImageSharp/tree/master/samples/AvatarWithRoundedCorner // https://github.com/SixLabors/ImageSharp/tree/master/samples/AvatarWithRoundedCorner

View File

@ -11,6 +11,7 @@ namespace NadekoBot.Services.Database.Models
public ClubInfo Club { get; set; } public ClubInfo Club { get; set; }
public DateTime LastLevelUp { get; set; } = DateTime.UtcNow; public DateTime LastLevelUp { get; set; } = DateTime.UtcNow;
public DateTime LastXpGain { get; set; } = DateTime.MinValue;
public XpNotificationType NotifyOnLevelUp { get; set; } public XpNotificationType NotifyOnLevelUp { get; set; }
public override bool Equals(object obj) public override bool Equals(object obj)

Binary file not shown.

After

Width:  |  Height:  |  Size: 288 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 288 KiB

After

Width:  |  Height:  |  Size: 76 KiB