Passed
Pull Request — main (#176)
by Yohann
01:56
created

guessing_game   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 31
dl 0
loc 44
rs 10
c 0
b 0
f 0

1 Method

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