-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
69 lines (48 loc) · 3.39 KB
/
Copy pathutil.py
File metadata and controls
69 lines (48 loc) · 3.39 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Message, BotCommand, MenuButtonCommands, BotCommandScopeChat, MenuButtonDefault
from telegram import Update
from telegram.constants import ParseMode
from telegram.ext import ContextTypes
def dialog_user_info_to_str(user) -> str:
result = ""
map = {"name": "Имя", "sex": "Пол", "age": "Возраст", "city": "Город", "occupation": "Профессия", "hobby": "Хобби", "goals": "Цели знакомства",
"handsome": "Красота, привлекательность в баллах (максимум 10 баллов)", "wealth": "Доход, богатство", "annoys": "В людях раздражает"}
for key, name in map.items():
if key in user:
result += name + ": " + user[key] + "\n"
return result
async def send_text(update: Update, context: ContextTypes.DEFAULT_TYPE, text: str) -> Message:
if text.count('_') % 2 != 0:
message = f"Строка '{text}' является невалидной с точки зрения markdown. Воспользуйтесь методом send_html()"
print(message)
return await update.message.reply_text(message)
text = text.encode('utf16', errors='surrogatepass').decode('utf16')
return await context.bot.send_message(chat_id=update.effective_chat.id, text=text, parse_mode=ParseMode.MARKDOWN)
async def send_html(update: Update, context: ContextTypes.DEFAULT_TYPE, text: str) -> Message:
text = text.encode('utf16', errors='surrogatepass').decode('utf16')
return await context.bot.send_message(chat_id=update.effective_chat.id, text=text, parse_mode=ParseMode.HTML)
async def send_text_buttons(update: Update, context: ContextTypes.DEFAULT_TYPE, text: str, buttons: dict) -> Message:
text = text.encode('utf16', errors='surrogatepass').decode('utf16')
keyboard = []
for key, value in buttons.items():
button = InlineKeyboardButton(str(value), callback_data=str(key))
keyboard.append([button])
reply_markup = InlineKeyboardMarkup(keyboard)
return await update.message.reply_text(text, reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN)
async def send_photo(update: Update, context: ContextTypes.DEFAULT_TYPE, name: str) -> Message:
with open('resources/images/' + name + ".jpg", 'rb') as photo:
return await context.bot.send_photo(chat_id=update.effective_chat.id, photo=photo)
async def show_main_menu(update: Update, context: ContextTypes.DEFAULT_TYPE, commands: dict):
command_list = [BotCommand(key, value) for key, value in commands.items()]
await context.bot.set_my_commands(command_list, scope=BotCommandScopeChat(chat_id=update.effective_chat.id))
await context.bot.set_chat_menu_button(menu_button=MenuButtonCommands(), chat_id=update.effective_chat.id)
async def hide_main_menu(update: Update, context: ContextTypes.DEFAULT_TYPE):
await context.bot.delete_my_commands(scope=BotCommandScopeChat(chat_id=update.effective_chat.id))
await context.bot.set_chat_menu_button(menu_button=MenuButtonDefault(), chat_id=update.effective_chat.id)
def load_message(name):
with open("resources/messages/" + name + ".txt", "r", encoding="utf8") as file:
return file.read()
def load_prompt(name):
with open("resources/prompts/" + name + ".txt", "r", encoding="utf8") as file:
return file.read()
class Dialog:
pass