mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
add: Added .xplevelset
remove: removed awardedxp from database. change: .sclr show will now show hex change: .awardxp will now add directly to user's real xp
This commit is contained in:
@@ -66,9 +66,9 @@ public partial class Administration
|
||||
|
||||
await message.ModifyAsync(x =>
|
||||
x.Embed = CreateEmbed()
|
||||
.WithDescription(GetText(strs.cache_users_done(added, updated)))
|
||||
.WithOkColor()
|
||||
.Build()
|
||||
.WithDescription(GetText(strs.cache_users_done(added, updated)))
|
||||
.WithOkColor()
|
||||
.Build()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -119,13 +119,13 @@ public partial class Administration
|
||||
|
||||
await Response()
|
||||
.Embed(CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.scadd))
|
||||
.AddField(GetText(strs.server),
|
||||
cmd.GuildId is null ? "-" : $"{cmd.GuildName}/{cmd.GuildId}",
|
||||
true)
|
||||
.AddField(GetText(strs.channel), $"{cmd.ChannelName}/{cmd.ChannelId}", true)
|
||||
.AddField(GetText(strs.command_text), cmdText))
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.scadd))
|
||||
.AddField(GetText(strs.server),
|
||||
cmd.GuildId is null ? "-" : $"{cmd.GuildName}/{cmd.GuildId}",
|
||||
true)
|
||||
.AddField(GetText(strs.channel), $"{cmd.ChannelName}/{cmd.ChannelId}", true)
|
||||
.AddField(GetText(strs.command_text), cmdText))
|
||||
.SendAsync();
|
||||
}
|
||||
|
||||
@@ -502,7 +502,7 @@ public partial class Administration
|
||||
await _bas.SetActivityAsync(game is null ? game : await repSvc.ReplaceAsync(game, repCtx), type);
|
||||
|
||||
await Response().Confirm(strs.set_activity).SendAsync();
|
||||
}
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[OwnerOnly]
|
||||
|
@@ -12,17 +12,21 @@ public partial class Utility
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task ServerColorsShow()
|
||||
{
|
||||
var colors = _service.GetColors(ctx.Guild.Id);
|
||||
var okHex = colors?.Ok?.RawValue.ToString("X8");
|
||||
var warnHex = colors?.Warn?.RawValue.ToString("X8");
|
||||
var errHex = colors?.Error?.RawValue.ToString("X8");
|
||||
EmbedBuilder[] ebs =
|
||||
[
|
||||
CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithDescription("\\✅"),
|
||||
.WithDescription($"\\✅ {okHex}"),
|
||||
CreateEmbed()
|
||||
.WithPendingColor()
|
||||
.WithDescription("\\⏳\\⚠️"),
|
||||
.WithDescription($"\\⏳\\⚠️ {warnHex}"),
|
||||
CreateEmbed()
|
||||
.WithErrorColor()
|
||||
.WithDescription("\\❌")
|
||||
.WithDescription($"\\❌ {errHex}")
|
||||
];
|
||||
|
||||
await Response()
|
||||
|
@@ -59,9 +59,9 @@ public partial class Xp : NadekoModule<XpService>
|
||||
var serverSetting = _service.GetNotificationType(ctx.User.Id, ctx.Guild.Id);
|
||||
|
||||
var embed = CreateEmbed()
|
||||
.WithOkColor()
|
||||
.AddField(GetText(strs.xpn_setting_global), GetNotifLocationString(globalSetting))
|
||||
.AddField(GetText(strs.xpn_setting_server), GetNotifLocationString(serverSetting));
|
||||
.WithOkColor()
|
||||
.AddField(GetText(strs.xpn_setting_global), GetNotifLocationString(globalSetting))
|
||||
.AddField(GetText(strs.xpn_setting_server), GetNotifLocationString(serverSetting));
|
||||
|
||||
await Response().Embed(embed).SendAsync();
|
||||
}
|
||||
@@ -154,9 +154,9 @@ public partial class Xp : NadekoModule<XpService>
|
||||
.Page((items, _) =>
|
||||
{
|
||||
var embed = CreateEmbed()
|
||||
.WithTitle(GetText(strs.exclusion_list))
|
||||
.WithDescription(string.Join('\n', items))
|
||||
.WithOkColor();
|
||||
.WithTitle(GetText(strs.exclusion_list))
|
||||
.WithDescription(string.Join('\n', items))
|
||||
.WithOkColor();
|
||||
|
||||
return embed;
|
||||
})
|
||||
@@ -214,16 +214,12 @@ public partial class Xp : NadekoModule<XpService>
|
||||
|
||||
for (var i = 0; i < users.Count; i++)
|
||||
{
|
||||
var levelStats = new LevelStats(users[i].Xp + users[i].AwardedXp);
|
||||
var levelStats = new LevelStats(users[i].Xp);
|
||||
var user = ((SocketGuild)ctx.Guild).GetUser(users[i].UserId);
|
||||
|
||||
var userXpData = users[i];
|
||||
|
||||
var awardStr = string.Empty;
|
||||
if (userXpData.AwardedXp > 0)
|
||||
awardStr = $"(+{userXpData.AwardedXp})";
|
||||
else if (userXpData.AwardedXp < 0)
|
||||
awardStr = $"({userXpData.AwardedXp})";
|
||||
|
||||
embed.AddField($"#{i + 1 + (curPage * 10)} {user?.ToString() ?? users[i].UserId.ToString()}",
|
||||
$"{GetText(strs.level_x(levelStats.Level))} - {levelStats.TotalXp}xp {awardStr}");
|
||||
@@ -266,8 +262,8 @@ public partial class Xp : NadekoModule<XpService>
|
||||
.Page((users, curPage) =>
|
||||
{
|
||||
var embed = CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.global_leaderboard));
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.global_leaderboard));
|
||||
|
||||
if (!users.Any())
|
||||
{
|
||||
@@ -287,6 +283,28 @@ public partial class Xp : NadekoModule<XpService>
|
||||
.SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[UserPerm(GuildPerm.Administrator)]
|
||||
[Priority(1)]
|
||||
public Task XpLevelSet(int level, IGuildUser user)
|
||||
=> XpLevelSet(level, user.Id);
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[UserPerm(GuildPerm.Administrator)]
|
||||
[Priority(0)]
|
||||
public async Task XpLevelSet(int level, ulong userId)
|
||||
{
|
||||
if (level < 0)
|
||||
return;
|
||||
|
||||
await _service.SetLevelAsync(ctx.Guild.Id, userId, level);
|
||||
await Response()
|
||||
.Confirm(strs.level_set($"<@{userId}>", Format.Bold(level.ToString())))
|
||||
.SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[UserPerm(GuildPerm.Administrator)]
|
||||
@@ -351,8 +369,8 @@ public partial class Xp : NadekoModule<XpService>
|
||||
public async Task XpReset(ulong userId)
|
||||
{
|
||||
var embed = CreateEmbed()
|
||||
.WithTitle(GetText(strs.reset))
|
||||
.WithDescription(GetText(strs.reset_user_confirm));
|
||||
.WithTitle(GetText(strs.reset))
|
||||
.WithDescription(GetText(strs.reset_user_confirm));
|
||||
|
||||
if (!await PromptUserConfirmAsync(embed))
|
||||
return;
|
||||
@@ -368,8 +386,8 @@ public partial class Xp : NadekoModule<XpService>
|
||||
public async Task XpReset()
|
||||
{
|
||||
var embed = CreateEmbed()
|
||||
.WithTitle(GetText(strs.reset))
|
||||
.WithDescription(GetText(strs.reset_server_confirm));
|
||||
.WithTitle(GetText(strs.reset))
|
||||
.WithDescription(GetText(strs.reset_server_confirm));
|
||||
|
||||
if (!await PromptUserConfirmAsync(embed))
|
||||
return;
|
||||
@@ -446,20 +464,20 @@ public partial class Xp : NadekoModule<XpService>
|
||||
{
|
||||
if (!items.Any())
|
||||
return CreateEmbed()
|
||||
.WithDescription(GetText(strs.not_found))
|
||||
.WithErrorColor();
|
||||
.WithDescription(GetText(strs.not_found))
|
||||
.WithErrorColor();
|
||||
|
||||
var (key, item) = items.FirstOrDefault();
|
||||
|
||||
var eb = CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithTitle(item.Name)
|
||||
.AddField(GetText(strs.price),
|
||||
CurrencyHelper.N(item.Price, Culture, _gss.GetCurrencySign()),
|
||||
true)
|
||||
.WithImageUrl(string.IsNullOrWhiteSpace(item.Preview)
|
||||
? item.Url
|
||||
: item.Preview);
|
||||
.WithOkColor()
|
||||
.WithTitle(item.Name)
|
||||
.AddField(GetText(strs.price),
|
||||
CurrencyHelper.N(item.Price, Culture, _gss.GetCurrencySign()),
|
||||
true)
|
||||
.WithImageUrl(string.IsNullOrWhiteSpace(item.Preview)
|
||||
? item.Url
|
||||
: item.Preview);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(item.Desc))
|
||||
eb.AddField(GetText(strs.desc), item.Desc);
|
||||
|
@@ -261,7 +261,6 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
|
||||
GuildId = guildId,
|
||||
Xp = group.Key,
|
||||
DateAdded = DateTime.UtcNow,
|
||||
AwardedXp = 0,
|
||||
NotifyOnLevelUp = XpNotificationLocation.None
|
||||
},
|
||||
_ => new()
|
||||
@@ -310,8 +309,8 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
|
||||
if (guildToAdd.TryGetValue(du.GuildId, out var users)
|
||||
&& users.TryGetValue(du.UserId, out var xpGainData))
|
||||
{
|
||||
var oldLevel = new LevelStats(du.Xp - xpGainData.XpAmount + du.AwardedXp);
|
||||
var newLevel = new LevelStats(du.Xp + du.AwardedXp);
|
||||
var oldLevel = new LevelStats(du.Xp - xpGainData.XpAmount);
|
||||
var newLevel = new LevelStats(du.Xp);
|
||||
|
||||
if (oldLevel.Level < newLevel.Level)
|
||||
{
|
||||
@@ -595,7 +594,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
|
||||
return await uow
|
||||
.UserXpStats
|
||||
.Where(x => x.GuildId == guildId)
|
||||
.OrderByDescending(x => x.Xp + x.AwardedXp)
|
||||
.OrderByDescending(x => x.Xp)
|
||||
.Skip(page * 10)
|
||||
.Take(10)
|
||||
.ToArrayAsyncLinqToDB();
|
||||
@@ -606,7 +605,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
|
||||
await using var uow = _db.GetDbContext();
|
||||
return await uow.Set<UserXpStats>()
|
||||
.Where(x => x.GuildId == guildId && x.UserId.In(users))
|
||||
.OrderByDescending(x => x.Xp + x.AwardedXp)
|
||||
.OrderByDescending(x => x.Xp)
|
||||
.Skip(page * 10)
|
||||
.Take(10)
|
||||
.ToArrayAsyncLinqToDB();
|
||||
@@ -903,7 +902,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
|
||||
using var uow = _db.GetDbContext();
|
||||
var usr = uow.GetOrCreateUserXpStats(guildId, userId);
|
||||
|
||||
usr.AwardedXp += amount;
|
||||
usr.Xp += amount;
|
||||
|
||||
uow.SaveChanges();
|
||||
}
|
||||
@@ -949,7 +948,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
|
||||
return new(du,
|
||||
stats,
|
||||
new(totalXp),
|
||||
new(stats.Xp + stats.AwardedXp),
|
||||
new(stats.Xp),
|
||||
globalRank,
|
||||
guildRank);
|
||||
}
|
||||
@@ -1192,19 +1191,6 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
|
||||
outlinePen));
|
||||
}
|
||||
|
||||
if (stats.FullGuildStats.AwardedXp != 0 && template.User.Xp.Awarded.Show)
|
||||
{
|
||||
var sign = stats.FullGuildStats.AwardedXp > 0 ? "+ " : "";
|
||||
var awX = template.User.Xp.Awarded.Pos.X
|
||||
- (Math.Max(0, stats.FullGuildStats.AwardedXp.ToString().Length - 2) * 5);
|
||||
var awY = template.User.Xp.Awarded.Pos.Y;
|
||||
img.Mutate(x => x.DrawText($"({sign}{stats.FullGuildStats.AwardedXp})",
|
||||
_fonts.NotoSans.CreateFont(template.User.Xp.Awarded.FontSize, FontStyle.Bold),
|
||||
Brushes.Solid(template.User.Xp.Awarded.Color),
|
||||
outlinePen,
|
||||
new(awX, awY)));
|
||||
}
|
||||
|
||||
var rankPen = new SolidPen(Color.White, 1);
|
||||
//ranking
|
||||
if (template.User.GlobalRank.Show)
|
||||
@@ -1671,6 +1657,29 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
|
||||
&& (guildUsers == null || guildUsers.Contains(x.UserId)))
|
||||
.CountAsyncLinqToDB();
|
||||
}
|
||||
|
||||
public async Task SetLevelAsync(ulong guildId, ulong userId, int level)
|
||||
{
|
||||
var lvlStats = LevelStats.CreateForLevel(level);
|
||||
await using var ctx = _db.GetDbContext();
|
||||
await ctx.GetTable<UserXpStats>()
|
||||
.InsertOrUpdateAsync(() => new()
|
||||
{
|
||||
GuildId = guildId,
|
||||
UserId = userId,
|
||||
AwardedXp = 0,
|
||||
Xp = lvlStats.TotalXp,
|
||||
NotifyOnLevelUp = XpNotificationLocation.None,
|
||||
DateAdded = DateTime.UtcNow
|
||||
}, (old) => new()
|
||||
{
|
||||
Xp = lvlStats.TotalXp
|
||||
}, () => new()
|
||||
{
|
||||
GuildId = guildId,
|
||||
UserId = userId
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public enum BuyResult
|
||||
|
Reference in New Issue
Block a user