diff --git a/cogs/silly.py b/cogs/silly.py index a0eae5b..f326899 100644 --- a/cogs/silly.py +++ b/cogs/silly.py @@ -8,8 +8,6 @@ from utils.ids import COMMANDS -fact = 1 - class Silly(cmds.Cog, name="Silly commands"): """ Silly commands @@ -19,18 +17,19 @@ def __init__(self, bot: CustomBot): self.bot = bot async def __factorial(self, message: discord.Message, nb: int): - global fact if nb < 0 : await message.channel.send("number cannot be negative !") elif nb > 20 : await message.channel.send(f"!factorial {nb-1}\njust joking, I'm not doing that") - elif nb <= 1 : - await message.channel.send(f"result : {fact}") + else: fact = 1 - else : - fact *= nb - await asyncio.sleep(1) - await message.channel.send(f"!factorial {nb-1}") + while nb > 1 : + await asyncio.sleep(1) + await message.channel.send(f"!factorial {nb-1}") + fact *= nb + nb -= 1 + + await message.channel.send(f"result : {fact}") return async def __di_cri(self, message: discord.Message): @@ -47,13 +46,6 @@ async def on_message(self, message: discord.Message) : """ Parse every message to find if there is a silly thing to answer """ - - # Self responding : - - if message.author == self.bot.user: - if re.fullmatch(r"^\!factorial [0-9]+$", message.content) is not None: - nb = int(message.content.split(' ')[-1]) - await self.__factorial(message, nb) # To prevent self response if message.author == self.bot.user :