From 6b9a858f280be48130bf9956d47717b95dd438ba Mon Sep 17 00:00:00 2001 From: Kwoth Date: Mon, 8 Aug 2022 16:17:30 +0200 Subject: [PATCH] Added Use button on sucessful .xpshopbuy or when a user already owns the item --- src/NadekoBot/Db/Models/DiscordUser.cs | 2 -- src/NadekoBot/Db/Models/UserXpStats.cs | 1 - src/NadekoBot/Db/MysqlContext.cs | 4 ---- src/NadekoBot/Db/NadekoContext.cs | 11 ----------- src/NadekoBot/Db/PostgreSqlContext.cs | 4 ---- src/NadekoBot/Db/SqliteContext.cs | 4 ---- src/NadekoBot/Modules/Xp/Xp.cs | 19 +++++++++++++++---- src/NadekoBot/Modules/Xp/XpService.cs | 3 ++- 8 files changed, 17 insertions(+), 31 deletions(-) diff --git a/src/NadekoBot/Db/Models/DiscordUser.cs b/src/NadekoBot/Db/Models/DiscordUser.cs index 2e14ffcdf..61622a53c 100644 --- a/src/NadekoBot/Db/Models/DiscordUser.cs +++ b/src/NadekoBot/Db/Models/DiscordUser.cs @@ -17,8 +17,6 @@ public class DiscordUser : DbEntity public bool IsClubAdmin { get; set; } public long TotalXp { get; set; } - public DateTime LastLevelUp { get; set; } = DateTime.UtcNow; - public DateTime LastXpGain { get; set; } = DateTime.MinValue; public XpNotificationLocation NotifyOnLevelUp { get; set; } public long CurrencyAmount { get; set; } diff --git a/src/NadekoBot/Db/Models/UserXpStats.cs b/src/NadekoBot/Db/Models/UserXpStats.cs index e9d3f01fb..0e99eaba9 100644 --- a/src/NadekoBot/Db/Models/UserXpStats.cs +++ b/src/NadekoBot/Db/Models/UserXpStats.cs @@ -8,7 +8,6 @@ public class UserXpStats : DbEntity public long Xp { get; set; } public long AwardedXp { get; set; } public XpNotificationLocation NotifyOnLevelUp { get; set; } - public DateTime LastLevelUp { get; set; } = DateTime.UtcNow; } public enum XpNotificationLocation { None, Dm, Channel } \ No newline at end of file diff --git a/src/NadekoBot/Db/MysqlContext.cs b/src/NadekoBot/Db/MysqlContext.cs index 77fdcc014..186324b89 100644 --- a/src/NadekoBot/Db/MysqlContext.cs +++ b/src/NadekoBot/Db/MysqlContext.cs @@ -10,10 +10,6 @@ public sealed class MysqlContext : NadekoContext protected override string CurrencyTransactionOtherIdDefaultValue => "NULL"; - protected override string DiscordUserLastXpGainDefaultValue - => "(UTC_TIMESTAMP - INTERVAL 1 year)"; - protected override string LastLevelUpDefaultValue - => "(UTC_TIMESTAMP)"; public MysqlContext(string connStr = "Server=localhost", string version = "8.0") { diff --git a/src/NadekoBot/Db/NadekoContext.cs b/src/NadekoBot/Db/NadekoContext.cs index 429825b54..4e6959634 100644 --- a/src/NadekoBot/Db/NadekoContext.cs +++ b/src/NadekoBot/Db/NadekoContext.cs @@ -65,8 +65,6 @@ public abstract class NadekoContext : DbContext #region Mandatory Provider-Specific Values protected abstract string CurrencyTransactionOtherIdDefaultValue { get; } - protected abstract string DiscordUserLastXpGainDefaultValue { get; } - protected abstract string LastLevelUpDefaultValue { get; } #endregion @@ -166,12 +164,6 @@ public abstract class NadekoContext : DbContext du.Property(x => x.NotifyOnLevelUp) .HasDefaultValue(XpNotificationLocation.None); - du.Property(x => x.LastXpGain) - .HasDefaultValueSql(DiscordUserLastXpGainDefaultValue); - - du.Property(x => x.LastLevelUp) - .HasDefaultValueSql(LastLevelUpDefaultValue); - du.Property(x => x.TotalXp) .HasDefaultValue(0); @@ -213,9 +205,6 @@ public abstract class NadekoContext : DbContext }) .IsUnique(); - xps.Property(x => x.LastLevelUp) - .HasDefaultValueSql(LastLevelUpDefaultValue); - xps.HasIndex(x => x.UserId); xps.HasIndex(x => x.GuildId); xps.HasIndex(x => x.Xp); diff --git a/src/NadekoBot/Db/PostgreSqlContext.cs b/src/NadekoBot/Db/PostgreSqlContext.cs index 2212f2181..08999a178 100644 --- a/src/NadekoBot/Db/PostgreSqlContext.cs +++ b/src/NadekoBot/Db/PostgreSqlContext.cs @@ -8,10 +8,6 @@ public sealed class PostgreSqlContext : NadekoContext protected override string CurrencyTransactionOtherIdDefaultValue => "NULL"; - protected override string DiscordUserLastXpGainDefaultValue - => "timezone('utc', now()) - interval '-1 year'"; - protected override string LastLevelUpDefaultValue - => "timezone('utc', now())"; public PostgreSqlContext(string connStr = "Host=localhost") { diff --git a/src/NadekoBot/Db/SqliteContext.cs b/src/NadekoBot/Db/SqliteContext.cs index 83627a945..3a2d4bf1e 100644 --- a/src/NadekoBot/Db/SqliteContext.cs +++ b/src/NadekoBot/Db/SqliteContext.cs @@ -9,10 +9,6 @@ public sealed class SqliteContext : NadekoContext protected override string CurrencyTransactionOtherIdDefaultValue => "NULL"; - protected override string DiscordUserLastXpGainDefaultValue - => "datetime('now', '-1 years')"; - protected override string LastLevelUpDefaultValue - => "datetime('now')"; public SqliteContext(string connectionString = "Data Source=data/NadekoBot.db", int commandTimeout = 60) { diff --git a/src/NadekoBot/Modules/Xp/Xp.cs b/src/NadekoBot/Modules/Xp/Xp.cs index 108088137..39dce3bc4 100644 --- a/src/NadekoBot/Modules/Xp/Xp.cs +++ b/src/NadekoBot/Modules/Xp/Xp.cs @@ -432,7 +432,7 @@ public partial class Xp : NadekoModule var button = new ButtonBuilder(ownedItem.IsUsing ? GetText(strs.in_use) : GetText(strs.use), - "XP_SHOP_USE", + "xpshop:use", emote: Emoji.Parse("👐"), isDisabled: ownedItem.IsUsing); @@ -446,7 +446,7 @@ public partial class Xp : NadekoModule else { var button = new ButtonBuilder(GetText(strs.buy), - "XP_SHOP_BUY", + "xpshop:buy", emote: Emoji.Parse("💰")); var inter = new SimpleInteraction<(string key, XpShopItemType type)?>( @@ -467,12 +467,22 @@ public partial class Xp : NadekoModule { var result = await _service.BuyShopItemAsync(ctx.User.Id, (XpShopItemType)type, key); + NadekoInteraction GetUseInteraction() + { + return _inter.Create(ctx.User.Id, + new SimpleInteraction( + new ButtonBuilder(label: "Use", customId: "xpshop:use_item", emote: Emoji.Parse("👐")), + async (smc, _) => await XpShopUse(type, key) + )); + } + if (result != BuyResult.Success) { var _ = result switch { + BuyResult.XpShopDisabled => await ReplyErrorLocalizedAsync(strs.xp_shop_disabled), BuyResult.InsufficientFunds => await ReplyErrorLocalizedAsync(strs.not_enough(_gss.Data.Currency.Sign)), - BuyResult.AlreadyOwned => await ReplyErrorLocalizedAsync(strs.xpshop_already_owned), + BuyResult.AlreadyOwned => await ReplyErrorLocalizedAsync(strs.xpshop_already_owned, GetUseInteraction()), BuyResult.UnknownItem => await ReplyErrorLocalizedAsync(strs.xpshop_item_not_found), BuyResult.InsufficientPatronTier => await ReplyErrorLocalizedAsync(strs.patron_insuff_tier), _ => throw new ArgumentOutOfRangeException() @@ -481,7 +491,8 @@ public partial class Xp : NadekoModule } await ReplyConfirmLocalizedAsync(strs.xpshop_buy_success(type.ToString().ToLowerInvariant(), - key.ToLowerInvariant())); + key.ToLowerInvariant()), + GetUseInteraction()); } [Cmd] diff --git a/src/NadekoBot/Modules/Xp/XpService.cs b/src/NadekoBot/Modules/Xp/XpService.cs index 1177ba64e..34640038f 100644 --- a/src/NadekoBot/Modules/Xp/XpService.cs +++ b/src/NadekoBot/Modules/Xp/XpService.cs @@ -1394,7 +1394,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand var conf = _xpConfig.Data; if (!conf.Shop.IsEnabled) - return BuyResult.UnknownItem; + return BuyResult.XpShopDisabled; var req = type == XpShopItemType.Background ? conf.Shop.BgsTierRequirement @@ -1545,6 +1545,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand public enum BuyResult { Success, + XpShopDisabled, AlreadyOwned, InsufficientFunds, UnknownItem,