added botcut setting to gambling.yml in which you can configure shopcut for now (how much money the bot takes when something is sold in the shop)

This commit is contained in:
Kwoth
2024-05-03 18:20:23 +00:00
parent 6327e242ca
commit 7637de8fed
9 changed files with 125 additions and 61 deletions

View File

@@ -33,6 +33,8 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
- Added `.clubrename` command to uh rename your club - Added `.clubrename` command to uh rename your club
- For self-hosters: - For self-hosters:
- Added `.sqlselectcsv` which will return results in a csv file instead of an embed. - Added `.sqlselectcsv` which will return results in a csv file instead of an embed.
- You can now configure whether nadeko ignores other bots in `bot.yml`
- You can now configure shop sale cut in `gambling.yml`
- Added a page parameter to `.feedlist` - Added a page parameter to `.feedlist`
- Added seconds/sec/s to .convert command - Added seconds/sec/s to .convert command

View File

@@ -43,6 +43,9 @@ public sealed partial class GamblingConfig : ICloneable<GamblingConfig>
[Comment("""How much will each user's owned currency decay over time.""")] [Comment("""How much will each user's owned currency decay over time.""")]
public DecayConfig Decay { get; set; } public DecayConfig Decay { get; set; }
[Comment("""What is the bot's cut on some transactions""")]
public BotCutConfig BotCuts { get; set; }
[Comment("""Settings for LuckyLadder command""")] [Comment("""Settings for LuckyLadder command""")]
public LuckyLadderSettings LuckyLadder { get; set; } public LuckyLadderSettings LuckyLadder { get; set; }
@@ -75,6 +78,7 @@ public sealed partial class GamblingConfig : ICloneable<GamblingConfig>
Decay = new(); Decay = new();
Slots = new(); Slots = new();
LuckyLadder = new(); LuckyLadder = new();
BotCuts = new();
} }
} }
@@ -385,3 +389,16 @@ public sealed partial class BetRollPair
public int WhenAbove { get; set; } public int WhenAbove { get; set; }
public float MultiplyBy { get; set; } public float MultiplyBy { get; set; }
} }
[Cloneable]
public sealed partial class BotCutConfig
{
[Comment("""
Shop sale cut percentage.
Whenever a user buys something from the shop, bot will take a cut equal to this percentage.
The rest goes to the user who posted the item/role/whatever to the shop.
This is a good way to reduce the amount of currency in circulation therefore keeping the inflation in check.
Default 0.1 (10%).
""")]
public decimal ShopSaleCut { get; set; } = 0.1m;
}

View File

@@ -182,5 +182,13 @@ public sealed class GamblingConfigService : ConfigServiceBase<GamblingConfig>
c.Version = 6; c.Version = 6;
}); });
} }
if (data.Version < 7)
{
ModifyConfig(c =>
{
c.Version = 7;
});
}
} }
} }

View File

@@ -283,8 +283,8 @@ public partial class Gambling
} }
} }
private static long GetProfitAmount(int price) private long GetProfitAmount(int price)
=> (int)Math.Ceiling(0.90 * price); => (int)Math.Ceiling((1.0m - Config.BotCuts.ShopSaleCut) * price);
[Cmd] [Cmd]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]

View File

@@ -13,7 +13,7 @@ namespace NadekoBot.Common.Configs;
public sealed partial class BotConfig : ICloneable<BotConfig> public sealed partial class BotConfig : ICloneable<BotConfig>
{ {
[Comment("""DO NOT CHANGE""")] [Comment("""DO NOT CHANGE""")]
public int Version { get; set; } = 6; public int Version { get; set; } = 7;
[Comment(""" [Comment("""
Most commands, when executed, have a small colored line Most commands, when executed, have a small colored line
@@ -52,6 +52,14 @@ public sealed partial class BotConfig : ICloneable<BotConfig>
""")] """)]
public ulong? ForwardToChannel { get; set; } public ulong? ForwardToChannel { get; set; }
[Comment("""
Should the bot ignore messages from other bots?
Settings this to false might get your bot banned if it gets into a spam loop with another bot.
This will only affect command executions, other features will still block bots from access.
Default true
""")]
public bool IgnoreOtherBots { get; set; }
[Comment(""" [Comment("""
When a user DMs the bot with a message which is not a command When a user DMs the bot with a message which is not a command
they will receive this message. Leave empty for no response. The string which will be sent whenever someone DMs the bot. they will receive this message. Leave empty for no response. The string which will be sent whenever someone DMs the bot.

View File

@@ -23,7 +23,7 @@ public class CommandHandler : INService, IReadyExecutor, ICommandHandler
private readonly DiscordSocketClient _client; private readonly DiscordSocketClient _client;
private readonly CommandService _commandService; private readonly CommandService _commandService;
private readonly BotConfigService _bss; private readonly BotConfigService _bcs;
private readonly IBot _bot; private readonly IBot _bot;
private readonly IBehaviorHandler _behaviorHandler; private readonly IBehaviorHandler _behaviorHandler;
private readonly IServiceProvider _services; private readonly IServiceProvider _services;
@@ -31,13 +31,15 @@ public class CommandHandler : INService, IReadyExecutor, ICommandHandler
private readonly ConcurrentDictionary<ulong, string> _prefixes; private readonly ConcurrentDictionary<ulong, string> _prefixes;
private readonly DbService _db; private readonly DbService _db;
private readonly BotConfig _bc;
// private readonly InteractionService _interactions; // private readonly InteractionService _interactions;
public CommandHandler( public CommandHandler(
DiscordSocketClient client, DiscordSocketClient client,
DbService db, DbService db,
CommandService commandService, CommandService commandService,
BotConfigService bss, BotConfigService bcs,
IBot bot, IBot bot,
IBehaviorHandler behaviorHandler, IBehaviorHandler behaviorHandler,
// InteractionService interactions, // InteractionService interactions,
@@ -45,7 +47,8 @@ public class CommandHandler : INService, IReadyExecutor, ICommandHandler
{ {
_client = client; _client = client;
_commandService = commandService; _commandService = commandService;
_bss = bss; _bc = bcs.Data;
_bcs = bcs;
_bot = bot; _bot = bot;
_behaviorHandler = behaviorHandler; _behaviorHandler = behaviorHandler;
_db = db; _db = db;
@@ -55,7 +58,6 @@ public class CommandHandler : INService, IReadyExecutor, ICommandHandler
_prefixes = bot.AllGuildConfigs.Where(x => x.Prefix is not null) _prefixes = bot.AllGuildConfigs.Where(x => x.Prefix is not null)
.ToDictionary(x => x.GuildId, x => x.Prefix) .ToDictionary(x => x.GuildId, x => x.Prefix)
.ToConcurrent(); .ToConcurrent();
} }
public async Task OnReadyAsync() public async Task OnReadyAsync()
@@ -72,7 +74,7 @@ public class CommandHandler : INService, IReadyExecutor, ICommandHandler
public string GetPrefix(ulong? id = null) public string GetPrefix(ulong? id = null)
{ {
if (id is null || !_prefixes.TryGetValue(id.Value, out var prefix)) if (id is null || !_prefixes.TryGetValue(id.Value, out var prefix))
return _bss.Data.Prefix; return _bcs.Data.Prefix;
return prefix; return prefix;
} }
@@ -82,7 +84,7 @@ public class CommandHandler : INService, IReadyExecutor, ICommandHandler
if (string.IsNullOrWhiteSpace(prefix)) if (string.IsNullOrWhiteSpace(prefix))
throw new ArgumentNullException(nameof(prefix)); throw new ArgumentNullException(nameof(prefix));
_bss.ModifyConfig(bs => _bcs.ModifyConfig(bs =>
{ {
bs.Prefix = prefix; bs.Prefix = prefix;
}); });
@@ -146,7 +148,7 @@ public class CommandHandler : INService, IReadyExecutor, ICommandHandler
private Task LogSuccessfulExecution(IUserMessage usrMsg, ITextChannel channel, params int[] execPoints) private Task LogSuccessfulExecution(IUserMessage usrMsg, ITextChannel channel, params int[] execPoints)
{ {
if (_bss.Data.ConsoleOutputType == ConsoleOutputType.Normal) if (_bcs.Data.ConsoleOutputType == ConsoleOutputType.Normal)
{ {
Log.Information(""" Log.Information("""
Command Executed after {ExecTime}s Command Executed after {ExecTime}s
@@ -179,7 +181,7 @@ public class CommandHandler : INService, IReadyExecutor, ICommandHandler
ITextChannel channel, ITextChannel channel,
params int[] execPoints) params int[] execPoints)
{ {
if (_bss.Data.ConsoleOutputType == ConsoleOutputType.Normal) if (_bcs.Data.ConsoleOutputType == ConsoleOutputType.Normal)
{ {
Log.Warning(""" Log.Warning("""
Command Errored after {ExecTime}s Command Errored after {ExecTime}s
@@ -212,8 +214,15 @@ public class CommandHandler : INService, IReadyExecutor, ICommandHandler
private Task MessageReceivedHandler(SocketMessage msg) private Task MessageReceivedHandler(SocketMessage msg)
{ {
//no bots, wait until bot connected and initialized if (!_bot.IsReady)
if (msg.Author.IsBot || !_bot.IsReady) return Task.CompletedTask;
if (_bc.IgnoreOtherBots)
{
if (msg.Author.IsBot)
return Task.CompletedTask;
}
else if (msg.Author.Id == _client.CurrentUser.Id)
return Task.CompletedTask; return Task.CompletedTask;
if (msg is not SocketUserMessage usrMsg) if (msg is not SocketUserMessage usrMsg)

View File

@@ -62,5 +62,12 @@ public sealed class BotConfigService : ConfigServiceBase<BotConfig>
{ {
c.Version = 5; c.Version = 5;
}); });
if(data.Version < 7)
ModifyConfig(c =>
{
c.Version = 7;
c.IgnoreOtherBots = true;
});
} }
} }

View File

@@ -1,5 +1,5 @@
# DO NOT CHANGE # DO NOT CHANGE
version: 5 version: 7
# Most commands, when executed, have a small colored line # Most commands, when executed, have a small colored line
# next to the response. The color depends whether the command # next to the response. The color depends whether the command
# is completed, errored or in progress (pending) # is completed, errored or in progress (pending)
@@ -28,6 +28,11 @@ forwardToAllOwners: false
# Any messages sent by users in Bot's DM to be forwarded to the specified channel. # Any messages sent by users in Bot's DM to be forwarded to the specified channel.
# This option will only work when ForwardToAllOwners is set to false # This option will only work when ForwardToAllOwners is set to false
forwardToChannel: forwardToChannel:
# Should the bot ignore messages from other bots?
# Settings this to false might get your bot banned if it gets into a spam loop with another bot.
# This will only affect command executions, other features will still block bots from access.
# Default true
ignoreOtherBots: true
# When a user DMs the bot with a message which is not a command # When a user DMs the bot with a message which is not a command
# they will receive this message. Leave empty for no response. The string which will be sent whenever someone DMs the bot. # they will receive this message. Leave empty for no response. The string which will be sent whenever someone DMs the bot.
# Supports embeds. How it looks: https://puu.sh/B0BLV.png # Supports embeds. How it looks: https://puu.sh/B0BLV.png

View File

@@ -1,12 +1,12 @@
# DO NOT CHANGE # DO NOT CHANGE
version: 6 version: 7
# Currency settings # Currency settings
currency: currency:
# What is the emoji/character which represents the currency # What is the emoji/character which represents the currency
sign: "🌸" sign: "🌸"
# What is the name of the currency # What is the name of the currency
name: Nadeko Flower name: Nadeko Flower
# For how long will the transactions be kept in the database (curtrs) # For how long (in days) will the transactions be kept in the database (curtrs)
# Set 0 to disable cleanup (keep transactions forever) # Set 0 to disable cleanup (keep transactions forever)
transactionsLifetime: 0 transactionsLifetime: 0
# Minimum amount users can bet (>=0) # Minimum amount users can bet (>=0)
@@ -67,6 +67,14 @@ decay:
minThreshold: 99 minThreshold: 99
# How often, in hours, does the decay run. Default is 24 hours # How often, in hours, does the decay run. Default is 24 hours
hourInterval: 24 hourInterval: 24
# What is the bot's cut on some transactions
botCuts:
# Shop sale cut percentage.
# Whenever a user buys something from the shop, bot will take a cut equal to this percentage.
# The rest goes to the user who posted the item/role/whatever to the shop.
# This is a good way to reduce the amount of currency in circulation therefore keeping the inflation in check.
# Default 0.1 (10%).
shopSaleCut: 0.1
# Settings for LuckyLadder command # Settings for LuckyLadder command
luckyLadder: luckyLadder:
# Self-Explanatory. Has to have 8 values, otherwise the command won't work. # Self-Explanatory. Has to have 8 values, otherwise the command won't work.