From a562a571e2a01e58acb1630cff6f01ea8a613046 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Wed, 22 Sep 2021 23:07:23 +0200 Subject: [PATCH] - .shopadd will now ignore negative price input - Make sure bot has manage roles permission for .xprr - Small cleanup --- .../Common/Waifu/WaifuProfileTitle.cs | 14 ------ .../Gambling/CurrencyEventsCommands.cs | 49 ++++++++----------- .../Modules/Gambling/ShopCommands.cs | 11 ++++- src/NadekoBot/Modules/Xp/Xp.cs | 2 + 4 files changed, 31 insertions(+), 45 deletions(-) delete mode 100644 src/NadekoBot/Modules/Gambling/Common/Waifu/WaifuProfileTitle.cs diff --git a/src/NadekoBot/Modules/Gambling/Common/Waifu/WaifuProfileTitle.cs b/src/NadekoBot/Modules/Gambling/Common/Waifu/WaifuProfileTitle.cs deleted file mode 100644 index e9d190735..000000000 --- a/src/NadekoBot/Modules/Gambling/Common/Waifu/WaifuProfileTitle.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace NadekoBot.Modules.Gambling.Common.Waifu -{ - public struct WaifuProfileTitle - { - public int Count { get; } - public string Title { get; } - - public WaifuProfileTitle(int count, string title) - { - Count = count; - Title = title; - } - } -} diff --git a/src/NadekoBot/Modules/Gambling/CurrencyEventsCommands.cs b/src/NadekoBot/Modules/Gambling/CurrencyEventsCommands.cs index 92fea7373..442451405 100644 --- a/src/NadekoBot/Modules/Gambling/CurrencyEventsCommands.cs +++ b/src/NadekoBot/Modules/Gambling/CurrencyEventsCommands.cs @@ -17,11 +17,6 @@ namespace NadekoBot.Modules.Gambling [Group] public class CurrencyEventsCommands : GamblingSubmodule { - public enum OtherEvent - { - BotListUpvoters - } - public CurrencyEventsCommands(GamblingConfigService gamblingConf) : base(gamblingConf) { } @@ -37,41 +32,36 @@ namespace NadekoBot.Modules.Gambling ctx.Channel.Id, ev, opts, - GetEmbed - ).ConfigureAwait(false)) + GetEmbed)) { await ReplyErrorLocalizedAsync(strs.start_event_fail).ConfigureAwait(false); - return; } } private IEmbedBuilder GetEmbed(CurrencyEvent.Type type, EventOptions opts, long currentPot) { - switch (type) + return type switch { - case CurrencyEvent.Type.Reaction: - return _eb.Create() - .WithOkColor() - .WithTitle(GetText(strs.event_title(type.ToString()))) - .WithDescription(GetReactionDescription(opts.Amount, currentPot)) - .WithFooter(GetText(strs.event_duration_footer(opts.Hours))); - case CurrencyEvent.Type.GameStatus: - return _eb.Create() - .WithOkColor() - .WithTitle(GetText(strs.event_title(type.ToString()))) - .WithDescription(GetGameStatusDescription(opts.Amount, currentPot)) - .WithFooter(GetText(strs.event_duration_footer(opts.Hours))); - default: - break; - } - throw new ArgumentOutOfRangeException(nameof(type)); + CurrencyEvent.Type.Reaction => _eb.Create() + .WithOkColor() + .WithTitle(GetText(strs.event_title(type.ToString()))) + .WithDescription(GetReactionDescription(opts.Amount, currentPot)) + .WithFooter(GetText(strs.event_duration_footer(opts.Hours))), + CurrencyEvent.Type.GameStatus => _eb.Create() + .WithOkColor() + .WithTitle(GetText(strs.event_title(type.ToString()))) + .WithDescription(GetGameStatusDescription(opts.Amount, currentPot)) + .WithFooter(GetText(strs.event_duration_footer(opts.Hours))), + _ => throw new ArgumentOutOfRangeException(nameof(type)) + }; } private string GetReactionDescription(long amount, long potSize) { - string potSizeStr = Format.Bold(potSize == 0 + var potSizeStr = Format.Bold(potSize == 0 ? "∞" + CurrencySign - : potSize.ToString() + CurrencySign); + : potSize + CurrencySign); + return GetText(strs.new_reaction_event( CurrencySign, Format.Bold(amount + CurrencySign), @@ -80,9 +70,10 @@ namespace NadekoBot.Modules.Gambling private string GetGameStatusDescription(long amount, long potSize) { - string potSizeStr = Format.Bold(potSize == 0 + var potSizeStr = Format.Bold(potSize == 0 ? "∞" + CurrencySign - : potSize.ToString() + CurrencySign); + : potSize + CurrencySign); + return GetText(strs.new_gamestatus_event( CurrencySign, Format.Bold(amount + CurrencySign), diff --git a/src/NadekoBot/Modules/Gambling/ShopCommands.cs b/src/NadekoBot/Modules/Gambling/ShopCommands.cs index 3fecfeb40..45e466d72 100644 --- a/src/NadekoBot/Modules/Gambling/ShopCommands.cs +++ b/src/NadekoBot/Modules/Gambling/ShopCommands.cs @@ -225,6 +225,9 @@ namespace NadekoBot.Modules.Gambling [BotPerm(GuildPerm.ManageRoles)] public async Task ShopAdd(Role _, int price, [Leftover] IRole role) { + if (price < 1) + return; + var entry = new ShopEntry() { Name = "-", @@ -252,8 +255,11 @@ namespace NadekoBot.Modules.Gambling [NadekoCommand, Aliases] [RequireContext(ContextType.Guild)] [UserPerm(GuildPerm.Administrator)] - public async Task ShopAdd(List _, int price, [Leftover]string name) + public async Task ShopAdd(List _, int price, [Leftover] string name) { + if (price < 1) + return; + var entry = new ShopEntry() { Name = name.TrimTo(100), @@ -266,13 +272,14 @@ namespace NadekoBot.Modules.Gambling { var entries = new IndexedCollection(uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.ShopEntries) - .ThenInclude(x => x.Items)).ShopEntries) + .ThenInclude(x => x.Items)).ShopEntries) { entry }; uow.GuildConfigsForId(ctx.Guild.Id, set => set).ShopEntries = entries; uow.SaveChanges(); } + await ctx.Channel.EmbedAsync(EntryToEmbed(entry) .WithTitle(GetText(strs.shop_item_add))).ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Xp/Xp.cs b/src/NadekoBot/Modules/Xp/Xp.cs index dcf851b3f..9083d7310 100644 --- a/src/NadekoBot/Modules/Xp/Xp.cs +++ b/src/NadekoBot/Modules/Xp/Xp.cs @@ -123,6 +123,7 @@ namespace NadekoBot.Modules.Xp [NadekoCommand, Aliases] [UserPerm(GuildPerm.Administrator)] + [BotPerm(GuildPerm.ManageRoles)] [RequireContext(ContextType.Guild)] [Priority(2)] public async Task XpRoleReward(int level) @@ -133,6 +134,7 @@ namespace NadekoBot.Modules.Xp [NadekoCommand, Aliases] [UserPerm(GuildPerm.Administrator)] + [BotPerm(GuildPerm.ManageRoles)] [RequireContext(ContextType.Guild)] [Priority(1)] public async Task XpRoleReward(int level, AddRemove action, [Leftover] IRole role)