improve comments, add start action

This commit is contained in:
Rykov7
2022-12-22 09:24:20 +03:00
parent 64ee76e7f3
commit 1109f84537
+40 -18
View File
@@ -13,19 +13,25 @@ from .me import get_me
from .filters import * from .filters import *
from .config import * from .config import *
app = Flask(__name__) app = Flask(__name__)
@bot.message_handler(commands=['start']) @bot.message_handler(commands=['start'])
def start(message: types.Message): def start(message: types.Message):
""" Start """ """ Just write log. Nothing happen. """
log_msg = f'[START] {message.from_user.id} {message.from_user.first_name}' log_msg = f'[START] {message.from_user.id} {message.from_user.first_name}'
if message.from_user.last_name: if message.from_user.last_name:
log_msg += f' {message.from_user.last_name}' log_msg += f' {message.from_user.last_name}'
bot.send_message(message.chat.id,
f'Привет, {message.from_user.first_name}\nЗдесь можно опробовать команды из меню.')
logging.warning(log_msg) logging.warning(log_msg)
"""
[ ANTISPAM FILTERS ]
"""
@bot.edited_message_handler(func=check_spam_list) @bot.edited_message_handler(func=check_spam_list)
@bot.message_handler(func=check_spam_list) @bot.message_handler(func=check_spam_list)
def moderate_messages(message: types.Message): def moderate_messages(message: types.Message):
@@ -56,6 +62,11 @@ def delete_message(message: types.Message):
s['Deleted'] += 1 s['Deleted'] += 1
"""
[ COMMANDS ]
"""
@bot.message_handler(commands=['links']) @bot.message_handler(commands=['links'])
def send_links(message): def send_links(message):
send_or_reply(message, f"{RULES}\n{FAQ}\n{LIB}") send_or_reply(message, f"{RULES}\n{FAQ}\n{LIB}")
@@ -97,20 +108,6 @@ def translate_layout(message):
bot.send_message(message.chat.id, message.reply_to_message.text.translate(ENG_RUS_TABLE)) bot.send_message(message.chat.id, message.reply_to_message.text.translate(ENG_RUS_TABLE))
@bot.inline_handler(lambda query: True)
def default_query(inline_query):
""" Inline the Zen of Python. """
zen = []
for id_p, phrase in enumerate(ZEN):
q = inline_query.query.casefold()
if phrase.casefold().startswith(q) or ' ' + q in phrase.casefold():
zen.append(types.InlineQueryResultArticle(
f"{id_p + 7000}", f'The Zen of Python #{id_p + 1}', types.InputTextMessageContent(
f"<i>{phrase}</i>"), description=phrase))
bot.answer_inline_query(inline_query.id, zen, cache_time=1200)
@bot.message_handler(commands=['me']) @bot.message_handler(commands=['me'])
def command_me(message): def command_me(message):
""" Send info about user and chat id [Service]. """ """ Send info about user and chat id [Service]. """
@@ -207,6 +204,25 @@ def tease_nongrata(message: types.Message):
bot.reply_to(message, f'у нас тут таких не любят') bot.reply_to(message, f'у нас тут таких не любят')
"""
[ INLINE QUERIES ]
"""
@bot.inline_handler(lambda query: True)
def default_query(inline_query):
""" Inline the Zen of Python. """
zen = []
for id_p, phrase in enumerate(ZEN):
q = inline_query.query.casefold()
if phrase.casefold().startswith(q) or ' ' + q in phrase.casefold():
zen.append(types.InlineQueryResultArticle(
f"{id_p + 7000}", f'The Zen of Python #{id_p + 1}', types.InputTextMessageContent(
f"<i>{phrase}</i>"), description=phrase))
bot.answer_inline_query(inline_query.id, zen, cache_time=1200)
""" """
[ ADMIN PANEL ] [ ADMIN PANEL ]
""" """
@@ -274,9 +290,10 @@ def send_stats(message: types.Message):
def send_quote(after_sec, message, quote): def send_quote(after_sec, message, quote):
sleep(after_sec/3) """ Imitate Reading first, then imitate Typing. """
sleep(len(message.text) * 0.13 / 4) # Reading time is quarter of the same text writing time
bot.send_chat_action(message.chat.id, action='typing') bot.send_chat_action(message.chat.id, action='typing')
sleep(after_sec) sleep(after_sec) # Typing time
bot.send_message(message.chat.id, quote) bot.send_message(message.chat.id, quote)
@@ -299,6 +316,11 @@ def handle_msg(message: types.Message):
threading.Thread(target=send_quote, args=(len(quote) * 0.13, message, quote)).start() threading.Thread(target=send_quote, args=(len(quote) * 0.13, message, quote)).start()
"""
[ WEBHOOK ROUTE ]
"""
@app.route(f"/bot{TOKEN}/", methods=['POST']) @app.route(f"/bot{TOKEN}/", methods=['POST'])
def webhook(): def webhook():
""" Parse POST requests from Telegram. """ """ Parse POST requests from Telegram. """