-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.py
More file actions
77 lines (56 loc) · 1.92 KB
/
Copy pathapp.py
File metadata and controls
77 lines (56 loc) · 1.92 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
70
71
72
73
74
75
76
77
import os
import telebot
from config import Config
from messages import message_turbine
from utils import (
check_press_button_user,
get_markup_pubg,
translate,
update_text,
with_remove,
)
config = Config()
bot = telebot.TeleBot(os.environ.get(config.env_key, None))
@bot.message_handler(commands=["pubg"])
def send_pubg_request(message):
if message.chat.type == "private":
return
chat_id = message.chat.id
active_poll = config.press_button.pop(chat_id, None)
if active_poll:
bot.delete_message(chat_id, active_poll.get("message"))
title = (
translate(config.pubg_mess)
if message.from_user.username in config.users
else config.pubg_mess
)
mess = bot.send_message(chat_id, title, reply_markup=get_markup_pubg())
config.press_button[chat_id] = {"message": mess.message_id, "users": []}
@bot.callback_query_handler(func=lambda call: call.data in ["yes", "no"])
def pubg_poll_call(call):
chat_id = call.message.chat.id
is_exists, is_all = check_press_button_user(call)
if not is_exists:
bot.delete_message(chat_id, config.press_button[chat_id]["message"])
mess = bot.send_message(
chat_id,
update_text(call),
reply_markup=None if is_all else get_markup_pubg(),
)
config.press_button[chat_id]["message"] = mess.message_id
if is_all:
config.press_button.pop(chat_id)
bot.answer_callback_query(call.id, text="")
@bot.message_handler(content_types=["text"])
def send_text(message):
bot_msg = message_turbine(message)
if bot_msg:
msg = bot_msg.get_message(message.text)
if bot_msg.type == "sticker":
bot.send_sticker(message.chat.id, msg)
elif bot_msg.type == "reply":
bot.reply_to(message, msg)
else:
bot.send_message(message.chat.id, msg)
if __name__ == "__main__":
bot.polling()