mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-12 10:18:27 -04:00
Finished implementing xp shop. It allows users to buy frames and backgrounds if the user enables the feature in data/xp.yml. It can also be available only to patrons
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#nullable disable
|
||||
#nullable disable warnings
|
||||
using Cloneable;
|
||||
using NadekoBot.Common.Yml;
|
||||
using NadekoBot.Db.Models;
|
||||
using NadekoBot.Modules.Utility.Patronage;
|
||||
|
||||
namespace NadekoBot.Modules.Xp;
|
||||
|
||||
@@ -8,7 +10,7 @@ namespace NadekoBot.Modules.Xp;
|
||||
public sealed partial class XpConfig : ICloneable<XpConfig>
|
||||
{
|
||||
[Comment(@"DO NOT CHANGE")]
|
||||
public int Version { get; set; } = 2;
|
||||
public int Version { get; set; } = 3;
|
||||
|
||||
[Comment(@"How much XP will the users receive per message")]
|
||||
public int XpPerMessage { get; set; } = 3;
|
||||
@@ -24,4 +26,64 @@ public sealed partial class XpConfig : ICloneable<XpConfig>
|
||||
|
||||
[Comment(@"The maximum amount of minutes the bot will keep track of a user in a voice channel")]
|
||||
public int VoiceMaxMinutes { get; set; } = 720;
|
||||
|
||||
[Comment(@"Xp Shop config")]
|
||||
public ShopConfig Shop { get; set; } = new();
|
||||
|
||||
public sealed class ShopConfig
|
||||
{
|
||||
[Comment(@"Whether the xp shop is enabled
|
||||
True -> Users can access the xp shop using .xpshop command
|
||||
False -> Users can't access the xp shop")]
|
||||
public bool IsEnabled { get; set; } = false;
|
||||
|
||||
[Comment(@"Which patron tier do users need in order to use the .xpshop command
|
||||
Leave at 'None' if patron system is disabled or you don't want any restrictions")]
|
||||
public PatronTier TierRequirement { get; set; } = PatronTier.None;
|
||||
|
||||
[Comment(@"Frames available for sale. Keys are unique IDs.
|
||||
Do not change keys as they are not publicly visible. Only change properties (name, price, id)
|
||||
Removing a key compeltely means all previous purchases will also be unusable.
|
||||
To remove an item from the shop, but keep previous purchases, set the price to -1")]
|
||||
public Dictionary<string, ShopItemInfo>? Frames { get; set; } = new()
|
||||
{
|
||||
{"default", new() {Name = "No frame", Price = 0, Url = string.Empty}}
|
||||
};
|
||||
|
||||
[Comment(@"Backgrounds available for sale. Keys are unique IDs.
|
||||
Do not change keys as they are not publicly visible. Only change properties (name, price, id)
|
||||
Removing a key compeltely means all previous purchases will also be unusable.
|
||||
To remove an item from the shop, but keep previous purchases, set the price to -1")]
|
||||
public Dictionary<string, ShopItemInfo>? Bgs { get; set; } = new()
|
||||
{
|
||||
{"default", new() {Name = "Default Background", Price = 0, Url = string.Empty}}
|
||||
};
|
||||
}
|
||||
|
||||
public sealed class ShopItemInfo
|
||||
{
|
||||
[Comment(@"Visible name of the item")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Comment(@"Price of the item. Set to -1 if you no longer want to sell the item but want the users to be able to keep their old purchase")]
|
||||
public int Price { get; set; }
|
||||
|
||||
[Comment(@"Direct url to the .png image which will be applied to the user's XP card")]
|
||||
public string Url { get; set; }
|
||||
|
||||
[Comment(@"Optional description of the item")]
|
||||
public string Desc { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
public static class XpShopConfigExtensions
|
||||
{
|
||||
public static string? GetItemUrl(this XpConfig.ShopConfig sc, XpShopItemType type, string key)
|
||||
=> (type switch
|
||||
{
|
||||
XpShopItemType.Background => sc.Bgs,
|
||||
_ => sc.Frames
|
||||
})?.TryGetValue(key, out var item) ?? false
|
||||
? item.Url
|
||||
: null;
|
||||
}
|
Reference in New Issue
Block a user