| Total Complexity | 7 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import random |
||
| 2 | |||
| 3 | from pincer import Client, command |
||
| 4 | from pincer.objects import Intents, MessageContext |
||
| 5 | |||
| 6 | |||
| 7 | class Bot(Client): |
||
| 8 | |||
| 9 | @command() |
||
| 10 | async def guess(self, ctx: MessageContext, biggest_number: int): |
||
| 11 | |||
| 12 | await ctx.reply(f"Starting the guessing game! Picker a number between 0 and {biggest_number}.") |
||
| 13 | channel = await self.get_channel(ctx.channel_id) |
||
| 14 | number = random.randint(0, biggest_number) |
||
| 15 | |||
| 16 | try: |
||
| 17 | async for next_message, in self.loop_for('on_message'): |
||
| 18 | if next_message.author.bot: |
||
| 19 | continue |
||
| 20 | |||
| 21 | try: |
||
| 22 | guessed_number = int(next_message.content) |
||
| 23 | except ValueError: |
||
| 24 | await channel.send(f"{next_message.content} is not a number. Try again!") |
||
| 25 | continue |
||
| 26 | |||
| 27 | if guessed_number > number: |
||
| 28 | await channel.send("Number is too high!") |
||
| 29 | elif guessed_number < number: |
||
| 30 | await channel.send("Number is too low!") |
||
| 31 | else: |
||
| 32 | await next_message.react("🚀") |
||
| 33 | await channel.send("Number is correct!") |
||
| 34 | |||
| 35 | except TimeoutError: |
||
| 36 | channel.send("Game timed out") |
||
| 37 | |||
| 38 | |||
| 39 | if __name__ == "__main__": |
||
| 40 | bot = Bot("XXXYOURBOTTOKENHEREXXX", intents=Intents.GUILD_MESSAGES) |
||
| 41 | bot.run() |
||
| 42 |