Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions techsupport_bot/commands/duck.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@

await channel.send(embed=embed)

async def handle_winner(

Check notice on line 226 in techsupport_bot/commands/duck.py

View check run for this annotation

codefactor.io / CodeFactor

techsupport_bot/commands/duck.py#L226

Too many positional arguments (6/5) (too-many-positional-arguments)
self: Self,
winner: discord.Member,
guild: discord.Guild,
Expand Down Expand Up @@ -312,7 +312,7 @@
random_line = random.choice(lines)
return random_line.strip()

def message_check(

Check notice on line 315 in techsupport_bot/commands/duck.py

View check run for this annotation

codefactor.io / CodeFactor

techsupport_bot/commands/duck.py#L315

Too many positional arguments (6/5) (too-many-positional-arguments)
self: Self,
config: munch.Munch,
channel: discord.abc.GuildChannel,
Expand Down Expand Up @@ -362,14 +362,9 @@
)
return False

weights = (
config.extensions.duck.success_rate.value,
100 - config.extensions.duck.success_rate.value,
)

# Check to see if random failure
choice_ = random.choice(random.choices([True, False], weights=weights, k=1000))
if not choice_:
choice = self.random_choice(config)
if not choice:
time = message.created_at - duck_message.created_at
duration_exact = float(str(time.seconds) + "." + str(time.microseconds))
cooldowns[message.author.id] = datetime.datetime.now()
Expand Down Expand Up @@ -399,7 +394,7 @@
)
)

return choice_
return choice

async def get_duck_user(
self: Self, user_id: int, guild_id: int
Expand Down Expand Up @@ -761,12 +756,7 @@

await duck_user.update(befriend_count=duck_user.befriend_count - 1).apply()

weights = (
config.extensions.duck.success_rate.value,
100 - config.extensions.duck.success_rate.value,
)

passed = random.choice(random.choices([True, False], weights=weights, k=1000))
passed = self.random_choice(config)
if not passed:
await auxiliary.send_deny_embed(
message="The duck got away before you could kill it.",
Expand Down Expand Up @@ -839,12 +829,7 @@

await duck_user.update(befriend_count=duck_user.befriend_count - 1).apply()

weights = (
config.extensions.duck.success_rate.value,
100 - config.extensions.duck.success_rate.value,
)

passed = random.choice(random.choices([True, False], weights=weights, k=1000))
passed = self.random_choice(config)
if not passed:
await auxiliary.send_deny_embed(
message="The duck got away before you could donate it.",
Expand Down Expand Up @@ -933,3 +918,25 @@
message="It looks like you don't have permissions to spawn a duck",
channel=ctx.channel,
)

def random_choice(self: Self, config: munch.Munch) -> bool:
"""A function to pick true or false randomly based on the success_rate in the config

Args:
config (munch.Munch): The config for the guild

Returns:
bool: Whether the random choice should succeed or not
"""

weights = (
config.extensions.duck.success_rate.value,
100 - config.extensions.duck.success_rate.value,
)

# Check to see if random failure
choice_ = random.choice(
random.choices([True, False], weights=weights, k=100000)
)

return choice_
Loading