From a19aed852ac37159b84cea920414646573e961ef Mon Sep 17 00:00:00 2001 From: Julian Marcos Date: Sun, 14 Jan 2024 01:32:41 +0100 Subject: [PATCH 1/3] ducks-fine is now a percentage of the total The old behaviour is removed, and this is a BREAKING change, as the config option was mentioning a amount, while now mentions a percentage of the total. It also rounds the number to the acceptable units, that's why I imported decimal. --- ducks.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ducks.py b/ducks.py index d8a13ab..9885963 100644 --- a/ducks.py +++ b/ducks.py @@ -3,6 +3,7 @@ #--depends-on coins import random, re, time +import decimal from src import EventManager, ModuleManager, utils DUCK = "・゜゜・。。・゜゜\_o< QUACK!" @@ -72,13 +73,16 @@ class Module(ModuleManager.BaseModule): channel.duck_lines = 0 channel.send_message(DUCK) - def _duck_action(self, channel, user, action, setting, fine_enabled=False): + def _duck_action(self, channel, user, action, setting, event, fine_enabled=False): if channel.get_setting("ducks-fine", 0) != 0 and fine_enabled: coins = self.bot.modules.modules['coins'].module - fine_amount = channel.get_setting("ducks-fine",1) + interest_percentage = channel.get_setting("ducks-fine",1) + total_coins = decimal.Decimal(sum(coins._all_coins(event['server']).values())) + fine_amount = total_coins*(decimal.Decimal(0.01)*interest_percentage) + fine_amount = fine_amount.quantize(decimal.Decimal('.01'), rounding=decimal.ROUND_05UP) # Round number to appropriate units user_coins = coins._get_user_coins(user) if user_coins < fine_amount: - return f"There was a duck, but you didn't have coins to pay the fine of {fine_amount-user_coins} so you can't shoot the duck." + return f"There was a duck, but you didn't have coins to pay the fine of {fine_amount} coins so you can't shoot the duck." else: new_user_coins = user_coins - fine_amount coins._set_user_coins(user, new_user_coins) @@ -119,7 +123,7 @@ class Module(ModuleManager.BaseModule): def befriend(self, event): if event["target"].duck_active: action = self._duck_action(event["target"], event["user"], - "befriended", "ducks-befriended") + "befriended", event, "ducks-befriended") event["stdout"].write(action) else: self._no_duck(event["target"], event["user"], event["stderr"]) @@ -130,7 +134,7 @@ class Module(ModuleManager.BaseModule): def trap(self, event): if event["target"].duck_active: action = self._duck_action(event["target"], event["user"], - "trapped", "ducks-shot", fine_enabled=True) + "trapped", "ducks-shot", event, fine_enabled=True) event["stdout"].write(action) else: self._no_duck(event["target"], event["user"], event["stderr"]) @@ -141,7 +145,7 @@ class Module(ModuleManager.BaseModule): def bang(self, event): if event["target"].duck_active: action = self._duck_action(event["target"], event["user"], - "shot", "ducks-shot", fine_enabled=True) + "shot", "ducks-shot", event, fine_enabled=True) event["stdout"].write(action) else: self._no_duck(event["target"], event["user"], event["stderr"]) From ddbef430e49fbbc3744e90f7f699ef13fb8dac37 Mon Sep 17 00:00:00 2001 From: Julian Marcos Date: Sun, 14 Jan 2024 03:14:24 +0100 Subject: [PATCH 2/3] Limit fine percentage from 0% to 100% --- ducks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ducks.py b/ducks.py index 9885963..c42d163 100644 --- a/ducks.py +++ b/ducks.py @@ -18,7 +18,7 @@ DEFAULT_MIN_MESSAGES = 50 "Whether or not to kick someone talking to non-existent ducks")) @utils.export("channelset", utils.BoolSetting("ducks-prevent-highlight", "Whether or not to prevent highlighting users with !friends/!enemies")) -@utils.export("channelset", utils.IntRangeSetting(0, 100000, "ducks-fine", "The fine amount the users get fined when you shoot a duck")) +@utils.export("channelset", utils.IntRangeSetting(0, 100, "ducks-fine", "The fine amount the users get fined when you shoot a duck")) class Module(ModuleManager.BaseModule): @utils.hook("new.channel") From b2777b8e714f5c7be3a9292bb28d71b45b9b0bd1 Mon Sep 17 00:00:00 2001 From: Julian Marcos Date: Sun, 14 Jan 2024 03:15:05 +0100 Subject: [PATCH 3/3] Rename ducks-fine to clarify things --- ducks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ducks.py b/ducks.py index c42d163..b37aaa0 100644 --- a/ducks.py +++ b/ducks.py @@ -18,7 +18,7 @@ DEFAULT_MIN_MESSAGES = 50 "Whether or not to kick someone talking to non-existent ducks")) @utils.export("channelset", utils.BoolSetting("ducks-prevent-highlight", "Whether or not to prevent highlighting users with !friends/!enemies")) -@utils.export("channelset", utils.IntRangeSetting(0, 100, "ducks-fine", "The fine amount the users get fined when you shoot a duck")) +@utils.export("channelset", utils.IntRangeSetting(0, 100, "ducks-fine-percentage", "The fine amount the users get fined when you shoot a duck")) class Module(ModuleManager.BaseModule): @utils.hook("new.channel") @@ -74,9 +74,9 @@ class Module(ModuleManager.BaseModule): channel.send_message(DUCK) def _duck_action(self, channel, user, action, setting, event, fine_enabled=False): - if channel.get_setting("ducks-fine", 0) != 0 and fine_enabled: + if channel.get_setting("ducks-fine-percentage", 0) != 0 and fine_enabled: coins = self.bot.modules.modules['coins'].module - interest_percentage = channel.get_setting("ducks-fine",1) + interest_percentage = channel.get_setting("ducks-fine-percentage",1) total_coins = decimal.Decimal(sum(coins._all_coins(event['server']).values())) fine_amount = total_coins*(decimal.Decimal(0.01)*interest_percentage) fine_amount = fine_amount.quantize(decimal.Decimal('.01'), rounding=decimal.ROUND_05UP) # Round number to appropriate units