diff --git a/src/NadekoBot/Bot.cs b/src/NadekoBot/Bot.cs index 4f116bb44..de70503a1 100644 --- a/src/NadekoBot/Bot.cs +++ b/src/NadekoBot/Bot.cs @@ -171,7 +171,7 @@ public sealed class Bot _ = LoadTypeReaders(typeof(Bot).Assembly); sw.Stop(); - Log.Information("All services loaded in {ServiceLoadTime:F2}s", sw.Elapsed.TotalSeconds); + Log.Information( "All services loaded in {ServiceLoadTime:F2}s", sw.Elapsed.TotalSeconds); } private void ApplyConfigMigrations() diff --git a/src/NadekoBot/Modules/Xp/ResetCommands.cs b/src/NadekoBot/Modules/Xp/ResetCommands.cs deleted file mode 100644 index aba08b4fb..000000000 --- a/src/NadekoBot/Modules/Xp/ResetCommands.cs +++ /dev/null @@ -1,46 +0,0 @@ -#nullable disable -using NadekoBot.Modules.Xp.Services; - -namespace NadekoBot.Modules.Xp; - -public partial class Xp -{ - public partial class ResetCommands : NadekoModule - { - [Cmd] - [RequireContext(ContextType.Guild)] - [UserPerm(GuildPerm.Administrator)] - public partial Task XpReset(IGuildUser user) - => XpReset(user.Id); - - [Cmd] - [RequireContext(ContextType.Guild)] - [UserPerm(GuildPerm.Administrator)] - public async partial Task XpReset(ulong userId) - { - var embed = _eb.Create().WithTitle(GetText(strs.reset)).WithDescription(GetText(strs.reset_user_confirm)); - - if (!await PromptUserConfirmAsync(embed)) - return; - - _service.XpReset(ctx.Guild.Id, userId); - - await ReplyConfirmLocalizedAsync(strs.reset_user(userId)); - } - - [Cmd] - [RequireContext(ContextType.Guild)] - [UserPerm(GuildPerm.Administrator)] - public async partial Task XpReset() - { - var embed = _eb.Create().WithTitle(GetText(strs.reset)).WithDescription(GetText(strs.reset_server_confirm)); - - if (!await PromptUserConfirmAsync(embed)) - return; - - _service.XpReset(ctx.Guild.Id); - - await ReplyConfirmLocalizedAsync(strs.reset_server); - } - } -} \ No newline at end of file diff --git a/src/NadekoBot/Modules/Xp/Xp.cs b/src/NadekoBot/Modules/Xp/Xp.cs index 9f733b785..be2301fb1 100644 --- a/src/NadekoBot/Modules/Xp/Xp.cs +++ b/src/NadekoBot/Modules/Xp/Xp.cs @@ -42,137 +42,6 @@ public partial class Xp : NadekoModule } } - [Cmd] - [RequireContext(ContextType.Guild)] - [UserPerm(GuildPerm.Administrator)] - public async partial Task XpRewsReset() - { - var reply = await PromptUserConfirmAsync(_eb.Create() - .WithPendingColor() - .WithDescription(GetText(strs.xprewsreset_confirm))); - - if (!reply) - return; - - await _service.ResetXpRewards(ctx.Guild.Id); - await ctx.OkAsync(); - } - - [Cmd] - [RequireContext(ContextType.Guild)] - public partial Task XpLevelUpRewards(int page = 1) - { - page--; - - if (page is < 0 or > 100) - return Task.CompletedTask; - - var allRewards = _service.GetRoleRewards(ctx.Guild.Id) - .OrderBy(x => x.Level) - .Select(x => - { - var sign = !x.Remove ? @"✅ " : @"❌ "; - - var str = ctx.Guild.GetRole(x.RoleId)?.ToString(); - - if (str is null) - str = GetText(strs.role_not_found(Format.Code(x.RoleId.ToString()))); - else - { - if (!x.Remove) - str = GetText(strs.xp_receive_role(Format.Bold(str))); - else - str = GetText(strs.xp_lose_role(Format.Bold(str))); - } - - return (x.Level, Text: sign + str); - }) - .Concat(_service.GetCurrencyRewards(ctx.Guild.Id) - .OrderBy(x => x.Level) - .Select(x => (x.Level, - Format.Bold(x.Amount + _gss.Data.Currency.Sign)))) - .GroupBy(x => x.Level) - .OrderBy(x => x.Key) - .ToList(); - - return Context.SendPaginatedConfirmAsync(page, - cur => - { - var embed = _eb.Create().WithTitle(GetText(strs.level_up_rewards)).WithOkColor(); - - var localRewards = allRewards.Skip(cur * 9).Take(9).ToList(); - - if (!localRewards.Any()) - return embed.WithDescription(GetText(strs.no_level_up_rewards)); - - foreach (var reward in localRewards) - embed.AddField(GetText(strs.level_x(reward.Key)), string.Join("\n", reward.Select(y => y.Item2))); - - return embed; - }, - allRewards.Count, - 9); - } - - [Cmd] - [UserPerm(GuildPerm.Administrator)] - [BotPerm(GuildPerm.ManageRoles)] - [RequireContext(ContextType.Guild)] - [Priority(2)] - public async partial Task XpRoleReward(int level) - { - _service.ResetRoleReward(ctx.Guild.Id, level); - await ReplyConfirmLocalizedAsync(strs.xp_role_reward_cleared(level)); - } - - [Cmd] - [UserPerm(GuildPerm.Administrator)] - [BotPerm(GuildPerm.ManageRoles)] - [RequireContext(ContextType.Guild)] - [Priority(1)] - public async partial Task XpRoleReward(int level, AddRemove action, [Leftover] IRole role) - { - if (level < 1) - return; - - _service.SetRoleReward(ctx.Guild.Id, level, role.Id, action == AddRemove.Remove); - if (action == AddRemove.Add) - await ReplyConfirmLocalizedAsync(strs.xp_role_reward_add_role(level, Format.Bold(role.ToString()))); - else - { - await ReplyConfirmLocalizedAsync(strs.xp_role_reward_remove_role(Format.Bold(level.ToString()), - Format.Bold(role.ToString()))); - } - } - - [Cmd] - [RequireContext(ContextType.Guild)] - [OwnerOnly] - public async partial Task XpCurrencyReward(int level, int amount = 0) - { - if (level < 1 || amount < 0) - return; - - _service.SetCurrencyReward(ctx.Guild.Id, level, amount); - var config = _gss.Data; - - if (amount == 0) - await ReplyConfirmLocalizedAsync(strs.cur_reward_cleared(level, config.Currency.Sign)); - else - await ReplyConfirmLocalizedAsync(strs.cur_reward_added(level, Format.Bold(amount + config.Currency.Sign))); - } - - private string GetNotifLocationString(XpNotificationLocation loc) - { - if (loc == XpNotificationLocation.Channel) - return GetText(strs.xpn_notif_channel); - - if (loc == XpNotificationLocation.Dm) - return GetText(strs.xpn_notif_dm); - - return GetText(strs.xpn_notif_disabled); - } - [Cmd] [RequireContext(ContextType.Guild)] public async partial Task XpNotify() @@ -405,4 +274,51 @@ public partial class Xp : NadekoModule await Task.Delay(1000); await ReplyConfirmLocalizedAsync(strs.template_reloaded); } + + [Cmd] + [RequireContext(ContextType.Guild)] + [UserPerm(GuildPerm.Administrator)] + public partial Task XpReset(IGuildUser user) + => XpReset(user.Id); + + [Cmd] + [RequireContext(ContextType.Guild)] + [UserPerm(GuildPerm.Administrator)] + public async partial Task XpReset(ulong userId) + { + var embed = _eb.Create().WithTitle(GetText(strs.reset)).WithDescription(GetText(strs.reset_user_confirm)); + + if (!await PromptUserConfirmAsync(embed)) + return; + + _service.XpReset(ctx.Guild.Id, userId); + + await ReplyConfirmLocalizedAsync(strs.reset_user(userId)); + } + + [Cmd] + [RequireContext(ContextType.Guild)] + [UserPerm(GuildPerm.Administrator)] + public async partial Task XpReset() + { + var embed = _eb.Create().WithTitle(GetText(strs.reset)).WithDescription(GetText(strs.reset_server_confirm)); + + if (!await PromptUserConfirmAsync(embed)) + return; + + _service.XpReset(ctx.Guild.Id); + + await ReplyConfirmLocalizedAsync(strs.reset_server); + } + + private string GetNotifLocationString(XpNotificationLocation loc) + { + if (loc == XpNotificationLocation.Channel) + return GetText(strs.xpn_notif_channel); + + if (loc == XpNotificationLocation.Dm) + return GetText(strs.xpn_notif_dm); + + return GetText(strs.xpn_notif_disabled); + } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Xp/XpRewards.cs b/src/NadekoBot/Modules/Xp/XpRewards.cs new file mode 100644 index 000000000..934c49086 --- /dev/null +++ b/src/NadekoBot/Modules/Xp/XpRewards.cs @@ -0,0 +1,139 @@ +using NadekoBot.Modules.Gambling.Services; +using NadekoBot.Modules.Xp.Services; + +namespace NadekoBot.Modules.Xp; + +public partial class Xp +{ + public partial class XpRewards : NadekoModule + { + private readonly GamblingConfigService _gss; + + public XpRewards(GamblingConfigService gcs) + => _gss = gcs; + + [Cmd] + [RequireContext(ContextType.Guild)] + [UserPerm(GuildPerm.Administrator)] + public async partial Task XpRewsReset() + { + var promptEmbed = _eb.Create() + .WithPendingColor() + .WithDescription(GetText(strs.xprewsreset_confirm)); + + var reply = await PromptUserConfirmAsync(promptEmbed); + + if (!reply) + return; + + await _service.ResetXpRewards(ctx.Guild.Id); + await ctx.OkAsync(); + } + + [Cmd] + [RequireContext(ContextType.Guild)] + public partial Task XpLevelUpRewards(int page = 1) + { + page--; + + if (page is < 0 or > 100) + return Task.CompletedTask; + + var allRewards = _service.GetRoleRewards(ctx.Guild.Id) + .OrderBy(x => x.Level) + .Select(x => + { + var sign = !x.Remove ? @"✅ " : @"❌ "; + + var str = ctx.Guild.GetRole(x.RoleId)?.ToString(); + + if (str is null) + str = GetText(strs.role_not_found(Format.Code(x.RoleId.ToString()))); + else + { + if (!x.Remove) + str = GetText(strs.xp_receive_role(Format.Bold(str))); + else + str = GetText(strs.xp_lose_role(Format.Bold(str))); + } + + return (x.Level, Text: sign + str); + }) + .Concat(_service.GetCurrencyRewards(ctx.Guild.Id) + .OrderBy(x => x.Level) + .Select(x => (x.Level, + Format.Bold(x.Amount + _gss.Data.Currency.Sign)))) + .GroupBy(x => x.Level) + .OrderBy(x => x.Key) + .ToList(); + + return Context.SendPaginatedConfirmAsync(page, + cur => + { + var embed = _eb.Create().WithTitle(GetText(strs.level_up_rewards)).WithOkColor(); + + var localRewards = allRewards.Skip(cur * 9).Take(9).ToList(); + + if (!localRewards.Any()) + return embed.WithDescription(GetText(strs.no_level_up_rewards)); + + foreach (var reward in localRewards) + embed.AddField(GetText(strs.level_x(reward.Key)), + string.Join("\n", reward.Select(y => y.Item2))); + + return embed; + }, + allRewards.Count, + 9); + } + + [Cmd] + [UserPerm(GuildPerm.Administrator)] + [BotPerm(GuildPerm.ManageRoles)] + [RequireContext(ContextType.Guild)] + [Priority(2)] + public async partial Task XpRoleReward(int level) + { + _service.ResetRoleReward(ctx.Guild.Id, level); + await ReplyConfirmLocalizedAsync(strs.xp_role_reward_cleared(level)); + } + + [Cmd] + [UserPerm(GuildPerm.Administrator)] + [BotPerm(GuildPerm.ManageRoles)] + [RequireContext(ContextType.Guild)] + [Priority(1)] + public async partial Task XpRoleReward(int level, AddRemove action, [Leftover] IRole role) + { + if (level < 1) + return; + + _service.SetRoleReward(ctx.Guild.Id, level, role.Id, action == AddRemove.Remove); + if (action == AddRemove.Add) + await ReplyConfirmLocalizedAsync(strs.xp_role_reward_add_role(level, Format.Bold(role.ToString()))); + else + { + await ReplyConfirmLocalizedAsync(strs.xp_role_reward_remove_role(Format.Bold(level.ToString()), + Format.Bold(role.ToString()))); + } + } + + [Cmd] + [RequireContext(ContextType.Guild)] + [OwnerOnly] + public async partial Task XpCurrencyReward(int level, int amount = 0) + { + if (level < 1 || amount < 0) + return; + + _service.SetCurrencyReward(ctx.Guild.Id, level, amount); + var config = _gss.Data; + + if (amount == 0) + await ReplyConfirmLocalizedAsync(strs.cur_reward_cleared(level, config.Currency.Sign)); + else + await ReplyConfirmLocalizedAsync(strs.cur_reward_added(level, + Format.Bold(amount + config.Currency.Sign))); + } + } +} \ No newline at end of file