build.handlers.users.dice   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 20
dl 0
loc 48
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A bot_message() 0 28 3
1
# -*- coding: utf-8 -*-
2
3
4
from utils.misc.throttling import rate_limit
5
from aiogram import types
6
from loader import dp
7
import asyncio
8
9
10
"""
11
12
    Created on 29.09.2021
13
14
    @author: Nikita
15
16
17
"""
18
19
20
@rate_limit(5, 'dice')
21
@dp.message_handler(commands='dice')
22
async def bot_message(message: types.Message):
23
24
    """
25
26
    The function is designed for tossing a dice.
27
28
    """
29
30
    await types.ChatActions.typing()
31
32
    user = await message.bot.send_dice(chat_id=message.chat.id)
33
    await asyncio.sleep(1)
34
35
    bot = await message.bot.send_dice(chat_id=message.chat.id)
36
    await asyncio.sleep(3)
37
38
    await asyncio.sleep(1)
39
    if user.dice.value > bot.dice.value:
40
        await message.answer(f"Выиграл {message.from_user.first_name}!")
41
42
    elif user.dice.value < bot.dice.value:
43
        bot_name = await message.bot.get_me()
44
        await message.answer(f"Выиграл {bot_name.first_name}!")
45
46
    else:
47
        await message.answer("Ничья!")
48