-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.py
More file actions
43 lines (34 loc) · 951 Bytes
/
utils.py
File metadata and controls
43 lines (34 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import itertools
from typing import Optional, List
from pyrogram import Client
from pyrogram.raw.types import Updates
from pyrogram.types import Message, InlineKeyboardButton
async def parse_message(client: Client, updates: Updates) -> Message:
message = await Message._parse(
client,
updates.updates[-1].message,
{user.id: user for user in updates.users},
{chat.id: chat for chat in updates.chats},
)
return message
def process_button(button: InlineKeyboardButton) -> str:
d = {
'⬜': ' ',
'❌': 'X',
'⭕': 'O'
}
return d.get(button.text, ' ')
def extract_game(message: Message) -> Optional[List[str]]:
buttons = list(
itertools.chain(
*message.reply_markup.inline_keyboard
)
)
if len(buttons) != 9:
return None
game = list(
map(
process_button, buttons
)
)
return game