From 2bc248c3b38b1ecd32604e5f48df9c3f7183ba6b Mon Sep 17 00:00:00 2001 From: perforat Date: Sat, 4 Apr 2026 04:03:34 +0000 Subject: [PATCH] randomizer cog --- cogs/random/config.json | 8 ++++++++ cogs/random/random.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 cogs/random/config.json create mode 100644 cogs/random/random.py diff --git a/cogs/random/config.json b/cogs/random/config.json new file mode 100644 index 0000000..e3bd31c --- /dev/null +++ b/cogs/random/config.json @@ -0,0 +1,8 @@ +{ + "description": "Random number and choice generators.", + "usages": [ + "rng [maximum]", + "choose ..." + ], + "hidden": false +} diff --git a/cogs/random/random.py b/cogs/random/random.py new file mode 100644 index 0000000..89648bf --- /dev/null +++ b/cogs/random/random.py @@ -0,0 +1,35 @@ +import random +import logging +from discord.ext import commands + +logger = logging.getLogger(__name__) + +class RandomizerCog(commands.Cog): + def __init__(self, bot: commands.Bot): + self.bot = bot + logger.info("Randomizer cog loaded successfully") + + @commands.command(name="rng") + async def rng(self, ctx: commands.Context, maximum: int = 100): + if maximum < 1: + await ctx.send("Please provide a maximum number greater than 0.") + return + + result = random.randint(1, maximum) + await ctx.send(f" I rolled a **{result}** (from 1-{maximum}).") + + @commands.command(name="choose") + async def choose(self, ctx: commands.Context, *options: str): + if not options: + await ctx.send("No options provided.") + return + + if len(options) == 1: + await ctx.send(f"I choose **{options[0]}**.") + return + + choice = random.choice(options) + await ctx.send(f"Out of those options, I have chosen **{choice}**.") + +async def setup(bot: commands.Bot): + await bot.add_cog(RandomizerCog(bot)) \ No newline at end of file