mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
Added Use button on sucessful .xpshopbuy or when a user already owns the item
This commit is contained in:
@@ -17,8 +17,6 @@ public class DiscordUser : DbEntity
|
|||||||
public bool IsClubAdmin { get; set; }
|
public bool IsClubAdmin { get; set; }
|
||||||
|
|
||||||
public long TotalXp { 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 XpNotificationLocation NotifyOnLevelUp { get; set; }
|
||||||
|
|
||||||
public long CurrencyAmount { get; set; }
|
public long CurrencyAmount { get; set; }
|
||||||
|
@@ -8,7 +8,6 @@ public class UserXpStats : DbEntity
|
|||||||
public long Xp { get; set; }
|
public long Xp { get; set; }
|
||||||
public long AwardedXp { get; set; }
|
public long AwardedXp { get; set; }
|
||||||
public XpNotificationLocation NotifyOnLevelUp { get; set; }
|
public XpNotificationLocation NotifyOnLevelUp { get; set; }
|
||||||
public DateTime LastLevelUp { get; set; } = DateTime.UtcNow;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum XpNotificationLocation { None, Dm, Channel }
|
public enum XpNotificationLocation { None, Dm, Channel }
|
@@ -10,10 +10,6 @@ public sealed class MysqlContext : NadekoContext
|
|||||||
|
|
||||||
protected override string CurrencyTransactionOtherIdDefaultValue
|
protected override string CurrencyTransactionOtherIdDefaultValue
|
||||||
=> "NULL";
|
=> "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")
|
public MysqlContext(string connStr = "Server=localhost", string version = "8.0")
|
||||||
{
|
{
|
||||||
|
@@ -65,8 +65,6 @@ public abstract class NadekoContext : DbContext
|
|||||||
#region Mandatory Provider-Specific Values
|
#region Mandatory Provider-Specific Values
|
||||||
|
|
||||||
protected abstract string CurrencyTransactionOtherIdDefaultValue { get; }
|
protected abstract string CurrencyTransactionOtherIdDefaultValue { get; }
|
||||||
protected abstract string DiscordUserLastXpGainDefaultValue { get; }
|
|
||||||
protected abstract string LastLevelUpDefaultValue { get; }
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -166,12 +164,6 @@ public abstract class NadekoContext : DbContext
|
|||||||
du.Property(x => x.NotifyOnLevelUp)
|
du.Property(x => x.NotifyOnLevelUp)
|
||||||
.HasDefaultValue(XpNotificationLocation.None);
|
.HasDefaultValue(XpNotificationLocation.None);
|
||||||
|
|
||||||
du.Property(x => x.LastXpGain)
|
|
||||||
.HasDefaultValueSql(DiscordUserLastXpGainDefaultValue);
|
|
||||||
|
|
||||||
du.Property(x => x.LastLevelUp)
|
|
||||||
.HasDefaultValueSql(LastLevelUpDefaultValue);
|
|
||||||
|
|
||||||
du.Property(x => x.TotalXp)
|
du.Property(x => x.TotalXp)
|
||||||
.HasDefaultValue(0);
|
.HasDefaultValue(0);
|
||||||
|
|
||||||
@@ -213,9 +205,6 @@ public abstract class NadekoContext : DbContext
|
|||||||
})
|
})
|
||||||
.IsUnique();
|
.IsUnique();
|
||||||
|
|
||||||
xps.Property(x => x.LastLevelUp)
|
|
||||||
.HasDefaultValueSql(LastLevelUpDefaultValue);
|
|
||||||
|
|
||||||
xps.HasIndex(x => x.UserId);
|
xps.HasIndex(x => x.UserId);
|
||||||
xps.HasIndex(x => x.GuildId);
|
xps.HasIndex(x => x.GuildId);
|
||||||
xps.HasIndex(x => x.Xp);
|
xps.HasIndex(x => x.Xp);
|
||||||
|
@@ -8,10 +8,6 @@ public sealed class PostgreSqlContext : NadekoContext
|
|||||||
|
|
||||||
protected override string CurrencyTransactionOtherIdDefaultValue
|
protected override string CurrencyTransactionOtherIdDefaultValue
|
||||||
=> "NULL";
|
=> "NULL";
|
||||||
protected override string DiscordUserLastXpGainDefaultValue
|
|
||||||
=> "timezone('utc', now()) - interval '-1 year'";
|
|
||||||
protected override string LastLevelUpDefaultValue
|
|
||||||
=> "timezone('utc', now())";
|
|
||||||
|
|
||||||
public PostgreSqlContext(string connStr = "Host=localhost")
|
public PostgreSqlContext(string connStr = "Host=localhost")
|
||||||
{
|
{
|
||||||
|
@@ -9,10 +9,6 @@ public sealed class SqliteContext : NadekoContext
|
|||||||
|
|
||||||
protected override string CurrencyTransactionOtherIdDefaultValue
|
protected override string CurrencyTransactionOtherIdDefaultValue
|
||||||
=> "NULL";
|
=> "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)
|
public SqliteContext(string connectionString = "Data Source=data/NadekoBot.db", int commandTimeout = 60)
|
||||||
{
|
{
|
||||||
|
@@ -432,7 +432,7 @@ public partial class Xp : NadekoModule<XpService>
|
|||||||
var button = new ButtonBuilder(ownedItem.IsUsing
|
var button = new ButtonBuilder(ownedItem.IsUsing
|
||||||
? GetText(strs.in_use)
|
? GetText(strs.in_use)
|
||||||
: GetText(strs.use),
|
: GetText(strs.use),
|
||||||
"XP_SHOP_USE",
|
"xpshop:use",
|
||||||
emote: Emoji.Parse("👐"),
|
emote: Emoji.Parse("👐"),
|
||||||
isDisabled: ownedItem.IsUsing);
|
isDisabled: ownedItem.IsUsing);
|
||||||
|
|
||||||
@@ -446,7 +446,7 @@ public partial class Xp : NadekoModule<XpService>
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var button = new ButtonBuilder(GetText(strs.buy),
|
var button = new ButtonBuilder(GetText(strs.buy),
|
||||||
"XP_SHOP_BUY",
|
"xpshop:buy",
|
||||||
emote: Emoji.Parse("💰"));
|
emote: Emoji.Parse("💰"));
|
||||||
|
|
||||||
var inter = new SimpleInteraction<(string key, XpShopItemType type)?>(
|
var inter = new SimpleInteraction<(string key, XpShopItemType type)?>(
|
||||||
@@ -467,12 +467,22 @@ public partial class Xp : NadekoModule<XpService>
|
|||||||
{
|
{
|
||||||
var result = await _service.BuyShopItemAsync(ctx.User.Id, (XpShopItemType)type, key);
|
var result = await _service.BuyShopItemAsync(ctx.User.Id, (XpShopItemType)type, key);
|
||||||
|
|
||||||
|
NadekoInteraction GetUseInteraction()
|
||||||
|
{
|
||||||
|
return _inter.Create(ctx.User.Id,
|
||||||
|
new SimpleInteraction<object>(
|
||||||
|
new ButtonBuilder(label: "Use", customId: "xpshop:use_item", emote: Emoji.Parse("👐")),
|
||||||
|
async (smc, _) => await XpShopUse(type, key)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
if (result != BuyResult.Success)
|
if (result != BuyResult.Success)
|
||||||
{
|
{
|
||||||
var _ = result switch
|
var _ = result switch
|
||||||
{
|
{
|
||||||
|
BuyResult.XpShopDisabled => await ReplyErrorLocalizedAsync(strs.xp_shop_disabled),
|
||||||
BuyResult.InsufficientFunds => await ReplyErrorLocalizedAsync(strs.not_enough(_gss.Data.Currency.Sign)),
|
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.UnknownItem => await ReplyErrorLocalizedAsync(strs.xpshop_item_not_found),
|
||||||
BuyResult.InsufficientPatronTier => await ReplyErrorLocalizedAsync(strs.patron_insuff_tier),
|
BuyResult.InsufficientPatronTier => await ReplyErrorLocalizedAsync(strs.patron_insuff_tier),
|
||||||
_ => throw new ArgumentOutOfRangeException()
|
_ => throw new ArgumentOutOfRangeException()
|
||||||
@@ -481,7 +491,8 @@ public partial class Xp : NadekoModule<XpService>
|
|||||||
}
|
}
|
||||||
|
|
||||||
await ReplyConfirmLocalizedAsync(strs.xpshop_buy_success(type.ToString().ToLowerInvariant(),
|
await ReplyConfirmLocalizedAsync(strs.xpshop_buy_success(type.ToString().ToLowerInvariant(),
|
||||||
key.ToLowerInvariant()));
|
key.ToLowerInvariant()),
|
||||||
|
GetUseInteraction());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
|
@@ -1394,7 +1394,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
|
|||||||
var conf = _xpConfig.Data;
|
var conf = _xpConfig.Data;
|
||||||
|
|
||||||
if (!conf.Shop.IsEnabled)
|
if (!conf.Shop.IsEnabled)
|
||||||
return BuyResult.UnknownItem;
|
return BuyResult.XpShopDisabled;
|
||||||
|
|
||||||
var req = type == XpShopItemType.Background
|
var req = type == XpShopItemType.Background
|
||||||
? conf.Shop.BgsTierRequirement
|
? conf.Shop.BgsTierRequirement
|
||||||
@@ -1545,6 +1545,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
|
|||||||
public enum BuyResult
|
public enum BuyResult
|
||||||
{
|
{
|
||||||
Success,
|
Success,
|
||||||
|
XpShopDisabled,
|
||||||
AlreadyOwned,
|
AlreadyOwned,
|
||||||
InsufficientFunds,
|
InsufficientFunds,
|
||||||
UnknownItem,
|
UnknownItem,
|
||||||
|
Reference in New Issue
Block a user