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

@@ -42,6 +42,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();
} }
} }
@@ -384,4 +388,17 @@ 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
@@ -51,6 +51,14 @@ public sealed partial class BotConfig : ICloneable<BotConfig>
This option will only work when ForwardToAllOwners is set to false This option will only work when ForwardToAllOwners is set to false
""")] """)]
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

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,21 +31,24 @@ 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,
IServiceProvider services) IServiceProvider services)
{ {
_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,15 +148,15 @@ 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
User: {User} User: {User}
Server: {Server} Server: {Server}
Channel: {Channel} Channel: {Channel}
Message: {Message} Message: {Message}
""", """,
string.Join("/", execPoints.Select(x => (x * ONE_THOUSANDTH).ToString("F3"))), string.Join("/", execPoints.Select(x => (x * ONE_THOUSANDTH).ToString("F3"))),
usrMsg.Author + " [" + usrMsg.Author.Id + "]", usrMsg.Author + " [" + usrMsg.Author.Id + "]",
channel is null ? "PRIVATE" : channel.Guild.Name + " [" + channel.Guild.Id + "]", channel is null ? "PRIVATE" : channel.Guild.Name + " [" + channel.Guild.Id + "]",
@@ -179,16 +181,16 @@ 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
User: {User} User: {User}
Server: {Guild} Server: {Guild}
Channel: {Channel} Channel: {Channel}
Message: {Message} Message: {Message}
Error: {ErrorMessage} Error: {ErrorMessage}
""", """,
string.Join("/", execPoints.Select(x => (x * ONE_THOUSANDTH).ToString("F3"))), string.Join("/", execPoints.Select(x => (x * ONE_THOUSANDTH).ToString("F3"))),
usrMsg.Author + " [" + usrMsg.Author.Id + "]", usrMsg.Author + " [" + usrMsg.Author.Id + "]",
channel is null ? "DM" : channel.Guild.Name + " [" + channel.Guild.Id + "]", channel is null ? "DM" : channel.Guild.Name + " [" + channel.Guild.Id + "]",
@@ -199,9 +201,9 @@ public class CommandHandler : INService, IReadyExecutor, ICommandHandler
else else
{ {
Log.Warning(""" Log.Warning("""
Err | g:{GuildId} | c: {ChannelId} | u: {UserId} | msg: {Message} Err | g:{GuildId} | c: {ChannelId} | u: {UserId} | msg: {Message}
Err: {ErrorMessage} Err: {ErrorMessage}
""", """,
channel?.Guild.Id.ToString() ?? "-", channel?.Guild.Id.ToString() ?? "-",
channel?.Id.ToString() ?? "-", channel?.Id.ToString() ?? "-",
usrMsg.Author.Id, usrMsg.Author.Id,
@@ -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)
@@ -267,7 +276,7 @@ public class CommandHandler : INService, IReadyExecutor, ICommandHandler
isPrefixCommand ? 1 : prefix.Length, isPrefixCommand ? 1 : prefix.Length,
_services, _services,
MultiMatchHandling.Best); MultiMatchHandling.Best);
startTime = Environment.TickCount - startTime; startTime = Environment.TickCount - startTime;
// if a command is found // if a command is found
@@ -287,10 +296,10 @@ public class CommandHandler : INService, IReadyExecutor, ICommandHandler
{ {
error = HumanizeError(error); error = HumanizeError(error);
LogErroredExecution(error, usrMsg, channel as ITextChannel, blockTime, startTime); LogErroredExecution(error, usrMsg, channel as ITextChannel, blockTime, startTime);
if (guild is not null) if (guild is not null)
await CommandErrored(info, channel as ITextChannel, error); await CommandErrored(info, channel as ITextChannel, error);
return; return;
} }
} }
@@ -355,9 +364,9 @@ public class CommandHandler : INService, IReadyExecutor, ICommandHandler
{ {
case MultiMatchHandling.Best: case MultiMatchHandling.Best:
argList = parseResult.ArgValues argList = parseResult.ArgValues
.Map(x => x.Values.MaxBy(y => y.Score)); .Map(x => x.Values.MaxBy(y => y.Score));
paramList = parseResult.ParamValues paramList = parseResult.ParamValues
.Map(x => x.Values.MaxBy(y => y.Score)); .Map(x => x.Values.MaxBy(y => y.Score));
parseResult = ParseResult.FromSuccess(argList, paramList); parseResult = ParseResult.FromSuccess(argList, paramList);
break; break;
} }

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)
@@ -7,7 +7,7 @@ version: 5
# To get color's hex, you can go here https://htmlcolorcodes.com/ # To get color's hex, you can go here https://htmlcolorcodes.com/
# and copy the hex code fo your selected color (marked as #) # and copy the hex code fo your selected color (marked as #)
color: color:
# Color used for embed responses when command successfully executes # Color used for embed responses when command successfully executes
ok: 00e584 ok: 00e584
# Color used for embed responses when command has an error # Color used for embed responses when command has an error
error: ee281f error: ee281f
@@ -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)
@@ -16,13 +16,13 @@ minBet: 0
maxBet: 0 maxBet: 0
# Settings for betflip command # Settings for betflip command
betFlip: betFlip:
# Bet multiplier if user guesses correctly # Bet multiplier if user guesses correctly
multiplier: 1.95 multiplier: 1.95
# Settings for betroll command # Settings for betroll command
betRoll: betRoll:
# When betroll is played, user will roll a number 0-100. # When betroll is played, user will roll a number 0-100.
# This setting will describe which multiplier is used for when the roll is higher than the given number. # This setting will describe which multiplier is used for when the roll is higher than the given number.
# Doesn't have to be ordered. # Doesn't have to be ordered.
pairs: pairs:
- whenAbove: 99 - whenAbove: 99
multiplyBy: 10 multiplyBy: 10
@@ -32,9 +32,9 @@ betRoll:
multiplyBy: 2 multiplyBy: 2
# Automatic currency generation settings. # Automatic currency generation settings.
generation: generation:
# when currency is generated, should it also have a random password # when currency is generated, should it also have a random password
# associated with it which users have to type after the .pick command # associated with it which users have to type after the .pick command
# in order to get it # in order to get it
hasPassword: true hasPassword: true
# Every message sent has a certain % chance to generate the currency # Every message sent has a certain % chance to generate the currency
# specify the percentage here (1 being 100%, 0 being 0% - for example # specify the percentage here (1 being 100%, 0 being 0% - for example
@@ -50,16 +50,16 @@ generation:
# Settings for timely command # Settings for timely command
# (letting people claim X amount of currency every Y hours) # (letting people claim X amount of currency every Y hours)
timely: timely:
# How much currency will the users get every time they run .timely command # How much currency will the users get every time they run .timely command
# setting to 0 or less will disable this feature # setting to 0 or less will disable this feature
amount: 120 amount: 120
# How often (in hours) can users claim currency with .timely command # How often (in hours) can users claim currency with .timely command
# setting to 0 or less will disable this feature # setting to 0 or less will disable this feature
cooldown: 12 cooldown: 12
# How much will each user's owned currency decay over time. # How much will each user's owned currency decay over time.
decay: decay:
# Percentage of user's current currency which will be deducted every 24h. # Percentage of user's current currency which will be deducted every 24h.
# 0 - 1 (1 is 100%, 0.5 50%, 0 disabled) # 0 - 1 (1 is 100%, 0.5 50%, 0 disabled)
percent: 0 percent: 0
# Maximum amount of user's currency that can decay at each interval. 0 for unlimited. # Maximum amount of user's currency that can decay at each interval. 0 for unlimited.
maxDecay: 0 maxDecay: 0
@@ -67,9 +67,17 @@ 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.
multipliers: multipliers:
- 2.4 - 2.4
- 1.7 - 1.7
@@ -81,12 +89,12 @@ luckyLadder:
- 0.1 - 0.1
# Settings related to waifus # Settings related to waifus
waifu: waifu:
# Minimum price a waifu can have # Minimum price a waifu can have
minPrice: 50 minPrice: 50
multipliers: multipliers:
# Multiplier for waifureset. Default 150. # Multiplier for waifureset. Default 150.
# Formula (at the time of writing this): # Formula (at the time of writing this):
# price = (waifu_price * 1.25f) + ((number_of_divorces + changes_of_heart + 2) * WaifuReset) rounded up # price = (waifu_price * 1.25f) + ((number_of_divorces + changes_of_heart + 2) * WaifuReset) rounded up
waifuReset: 150 waifuReset: 150
# The minimum amount of currency that you have to pay # The minimum amount of currency that you have to pay
# in order to buy a waifu who doesn't have a crush on you. # in order to buy a waifu who doesn't have a crush on you.
@@ -117,9 +125,9 @@ waifu:
# Settings for periodic waifu price decay. # Settings for periodic waifu price decay.
# Waifu price decays only if the waifu has no claimer. # Waifu price decays only if the waifu has no claimer.
decay: decay:
# Percentage (0 - 100) of the waifu value to reduce. # Percentage (0 - 100) of the waifu value to reduce.
# Set 0 to disable # Set 0 to disable
# For example if a waifu has a price of 500$, setting this value to 10 would reduce the waifu value by 10% (50$) # For example if a waifu has a price of 500$, setting this value to 10 would reduce the waifu value by 10% (50$)
percent: 0 percent: 0
# How often to decay waifu values, in hours # How often to decay waifu values, in hours
hourInterval: 24 hourInterval: 24
@@ -257,5 +265,5 @@ patreonCurrencyPerCent: 1
voteReward: 100 voteReward: 100
# Slot config # Slot config
slots: slots:
# Hex value of the color which the numbers on the slot image will have. # Hex value of the color which the numbers on the slot image will have.
currencyFontColor: ff0000 currencyFontColor: ff0000