fix webhook func AssertionError
This commit is contained in:
+18
-21
@@ -1,6 +1,6 @@
|
|||||||
import shelve
|
import shelve
|
||||||
from datetime import datetime as dt
|
from datetime import datetime as dt
|
||||||
from flask import Flask, request, abort
|
from flask import request, abort
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
from time import sleep
|
from time import sleep
|
||||||
@@ -15,20 +15,8 @@ from .helpers import get_me, represent_as_get, detect_args
|
|||||||
from .filters import *
|
from .filters import *
|
||||||
from .config import *
|
from .config import *
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(commands=['start', 'links', 'начни', 'ссылки'])
|
|
||||||
def start(message: types.Message):
|
|
||||||
""" What to begin with. """
|
|
||||||
log_msg = f'[START] {message.from_user.id} {message.from_user.first_name}'
|
|
||||||
logging.warning(log_msg)
|
|
||||||
markup = types.InlineKeyboardMarkup([[RULES], [FAQ], [LIB]], 1)
|
|
||||||
send_or_reply(message, "Начни с прочтения", reply_markup=markup)
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
[ ANTISPAM FILTERS ]
|
[ ANTISPAM ]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@@ -67,6 +55,15 @@ def delete_message(message: types.Message):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@bot.message_handler(commands=['start', 'links', 'ссылки'])
|
||||||
|
def start(message: types.Message):
|
||||||
|
""" What to begin with. """
|
||||||
|
log_msg = f'[START] {message.from_user.id} {message.from_user.first_name}'
|
||||||
|
logging.warning(log_msg)
|
||||||
|
markup = types.InlineKeyboardMarkup([[RULES], [FAQ], [LIB]], 1)
|
||||||
|
send_or_reply(message, "Начни с прочтения", reply_markup=markup)
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(commands=['rules', 'rule', 'r', 'правила', 'правило', 'п'])
|
@bot.message_handler(commands=['rules', 'rule', 'r', 'правила', 'правило', 'п'])
|
||||||
def send_rules(message):
|
def send_rules(message):
|
||||||
markup = types.InlineKeyboardMarkup([[RULES]], 1)
|
markup = types.InlineKeyboardMarkup([[RULES]], 1)
|
||||||
@@ -96,7 +93,7 @@ def send_lutz(message):
|
|||||||
caption="вот, не позорься")
|
caption="вот, не позорься")
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(commands=['bdmtss', 'бдмтсс'])
|
@bot.message_handler(commands=['bdmtss'])
|
||||||
def send_bdmtss_audio(message):
|
def send_bdmtss_audio(message):
|
||||||
bot.send_voice(message.chat.id, 'AwACAgIAAxkBAAIJrWOg2WUvLwrf7ahyJxQHB8_nqllwAAL5JQAC2_IJSbhfQIO5YnVmLAQ')
|
bot.send_voice(message.chat.id, 'AwACAgIAAxkBAAIJrWOg2WUvLwrf7ahyJxQHB8_nqllwAAL5JQAC2_IJSbhfQIO5YnVmLAQ')
|
||||||
|
|
||||||
@@ -206,7 +203,7 @@ def tease_nongrata(message: types.Message):
|
|||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
[ INLINE QUERIES ]
|
[ INLINE ]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@@ -218,7 +215,7 @@ def default_query(inline_query):
|
|||||||
q = inline_query.query.casefold()
|
q = inline_query.query.casefold()
|
||||||
if phrase.casefold().startswith(q) or ' ' + q in phrase.casefold():
|
if phrase.casefold().startswith(q) or ' ' + q in phrase.casefold():
|
||||||
zen.append(types.InlineQueryResultArticle(
|
zen.append(types.InlineQueryResultArticle(
|
||||||
f"{id_p + 7000}", f'The Zen of Python #{id_p + 1}', types.InputTextMessageContent(
|
f"{id_p}", f'The Zen of Python #{id_p + 1}', types.InputTextMessageContent(
|
||||||
f"<i>{phrase}</i>"), description=phrase))
|
f"<i>{phrase}</i>"), description=phrase))
|
||||||
|
|
||||||
bot.answer_inline_query(inline_query.id, zen, cache_time=1200)
|
bot.answer_inline_query(inline_query.id, zen, cache_time=1200)
|
||||||
@@ -296,7 +293,7 @@ def remove_stan_quote(message):
|
|||||||
with open('Stan.txt', 'w', encoding='utf8') as stan_quotes:
|
with open('Stan.txt', 'w', encoding='utf8') as stan_quotes:
|
||||||
quotes.remove(message.reply_to_message.text + '\n')
|
quotes.remove(message.reply_to_message.text + '\n')
|
||||||
stan_quotes.writelines(quotes)
|
stan_quotes.writelines(quotes)
|
||||||
bot.send_message(message.chat.id, f'✅ <b>Удолил</b>\n └ <i>{message.reply_to_message.text}</i>')
|
bot.send_message(message.chat.id, f'✅ <b>Удалил</b>\n └ <i>{message.reply_to_message.text}</i>')
|
||||||
else:
|
else:
|
||||||
bot.send_message(message.chat.id, f'⛔️ <b>Нет такого</b>\n └ <i>{message.reply_to_message.text}</i>')
|
bot.send_message(message.chat.id, f'⛔️ <b>Нет такого</b>\n └ <i>{message.reply_to_message.text}</i>')
|
||||||
|
|
||||||
@@ -324,7 +321,7 @@ def send_stats(message: types.Message):
|
|||||||
|
|
||||||
|
|
||||||
def send_quote(after_sec, message, quote):
|
def send_quote(after_sec, message, quote):
|
||||||
""" Imitate Reading first, then imitate Typing. """
|
""" Pretend Reading, pretend Typing, send. """
|
||||||
if message.text:
|
if message.text:
|
||||||
sleep(len(message.text) * 0.13 / 4) # Reading time is quarter of the same text writing time
|
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')
|
||||||
@@ -352,12 +349,12 @@ def handle_msg(message: types.Message):
|
|||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
[ WEBHOOK ROUTE ]
|
[ WEBHOOK ]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@app.route(f"/bot{TOKEN}/", methods=['POST'])
|
@app.route(f"/bot{TOKEN}/", methods=['POST'])
|
||||||
def webhook():
|
def bot_webhook():
|
||||||
""" Parse POST requests from Telegram. """
|
""" Parse POST requests from Telegram. """
|
||||||
if request.headers.get('content-type') == 'application/json':
|
if request.headers.get('content-type') == 'application/json':
|
||||||
json_string = request.get_data().decode('utf-8')
|
json_string = request.get_data().decode('utf-8')
|
||||||
|
|||||||
+4
-1
@@ -1,19 +1,22 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
|
from flask import Flask
|
||||||
from telebot import TeleBot, logger, types
|
from telebot import TeleBot, logger, types
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s', datefmt='%Y.%m.%d %H:%M:%S')
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s', datefmt='%Y.%m.%d %H:%M:%S')
|
||||||
logging.critical('STAN STARTED!')
|
logging.critical('STAN STARTED!')
|
||||||
|
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.DEBUG)
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
TOKEN = os.environ.get('LUTZPYBOT', 'Token not in ENVIRON')
|
TOKEN = os.environ.get('LUTZPYBOT', 'Token not in ENVIRON')
|
||||||
bot = TeleBot(TOKEN, 'HTML', disable_web_page_preview=True, allow_sending_without_reply=True,
|
bot = TeleBot(TOKEN, 'HTML', disable_web_page_preview=True, allow_sending_without_reply=True,
|
||||||
colorful_logs=True)
|
colorful_logs=True)
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
DATA = 'data/chat'
|
DATA = 'data/chat'
|
||||||
|
|
||||||
ADMIN_ID = 280887861 # Rykov7
|
ADMIN_ID = 280887861 # Rykov7
|
||||||
|
|||||||
Reference in New Issue
Block a user