From 389df9d1158312d416c6f1a60bfbc22ee5f14ae3 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 18 Aug 2025 22:27:58 +0200 Subject: [PATCH 1/2] Create cowsay.py --- tux/cogs/fun/cowsay.py | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tux/cogs/fun/cowsay.py diff --git a/tux/cogs/fun/cowsay.py b/tux/cogs/fun/cowsay.py new file mode 100644 index 000000000..7c8b3b531 --- /dev/null +++ b/tux/cogs/fun/cowsay.py @@ -0,0 +1,53 @@ +import time +import cowsay +from discord.ext import commands +from tux.bot import Tux +from tux.utils.functions import generate_usage + +# Initialize cooldown tracking +user_cooldowns = {} +cooldown_duration = 180 # seconds + +class Cowsay(commands.Cog): + def __init__(self, bot: Tux) -> None: + self.bot = bot + self.cowsay_command.usage = generate_usage(self.cowsay_command) + + @commands.hybrid_command( + name="cowsay", + description="Make the cow say something.", + ) + @commands.guild_only() + async def cowsay_command( + self, + ctx: commands.Context[Tux], + *, + text: str + ) -> None: + user_id = ctx.author.id + now = time.time() + + if user_id in user_cooldowns: + elapsed = now - user_cooldowns[user_id] + if elapsed < cooldown_duration: + remaining = int(cooldown_duration - elapsed) + await ctx.respond( + f"⏳ You're on cooldown! Try again in {remaining} seconds.", + ephemeral=True + ) + return + + user_cooldowns[user_id] = now + + # Enforce character limit and sanitize input + max_length = 200 + sanitized_text = ''.join(c for c in text if c.isprintable()).strip() + if len(sanitized_text) > max_length: + await ctx.send(content=f"❌ Input too long! Please limit your message to {max_length} characters.") + return + + cow_text = cowsay.get_output_string("cow", sanitized_text) + await ctx.send(content=f"```{cow_text}```") + +async def setup(bot: Tux) -> None: + await bot.add_cog(Cowsay(bot)) From 901d9dc181c0a24123401ec256a6845d28dde7de Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Aug 2025 20:29:13 +0000 Subject: [PATCH 2/2] style: auto fixes from pre-commit hooks --- tux/cogs/fun/cowsay.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tux/cogs/fun/cowsay.py b/tux/cogs/fun/cowsay.py index 7c8b3b531..ff5659f4a 100644 --- a/tux/cogs/fun/cowsay.py +++ b/tux/cogs/fun/cowsay.py @@ -1,6 +1,8 @@ import time + import cowsay from discord.ext import commands + from tux.bot import Tux from tux.utils.functions import generate_usage @@ -8,6 +10,7 @@ user_cooldowns = {} cooldown_duration = 180 # seconds + class Cowsay(commands.Cog): def __init__(self, bot: Tux) -> None: self.bot = bot @@ -19,10 +22,10 @@ def __init__(self, bot: Tux) -> None: ) @commands.guild_only() async def cowsay_command( - self, - ctx: commands.Context[Tux], - *, - text: str + self, + ctx: commands.Context[Tux], + *, + text: str, ) -> None: user_id = ctx.author.id now = time.time() @@ -32,22 +35,23 @@ async def cowsay_command( if elapsed < cooldown_duration: remaining = int(cooldown_duration - elapsed) await ctx.respond( - f"⏳ You're on cooldown! Try again in {remaining} seconds.", - ephemeral=True + f"⏳ You're on cooldown! Try again in {remaining} seconds.", + ephemeral=True, ) return - + user_cooldowns[user_id] = now - + # Enforce character limit and sanitize input max_length = 200 - sanitized_text = ''.join(c for c in text if c.isprintable()).strip() + sanitized_text = "".join(c for c in text if c.isprintable()).strip() if len(sanitized_text) > max_length: await ctx.send(content=f"❌ Input too long! Please limit your message to {max_length} characters.") return - + cow_text = cowsay.get_output_string("cow", sanitized_text) await ctx.send(content=f"```{cow_text}```") + async def setup(bot: Tux) -> None: await bot.add_cog(Cowsay(bot))