diff --git a/api/webhook.py b/api/webhook.py index dda8426..0b30157 100644 --- a/api/webhook.py +++ b/api/webhook.py @@ -1,7 +1,7 @@ from sanic import Sanic from sanic.response import text -from tgbot.config import WEBHOOK, FEEDBACK_CHAT_ID +from tgbot.config import FEEDBACK_CHAT_ID from tgbot.handlers.handle_feedback import handle_feedback, handle_answer from tgbot.handlers.handle_members_change import handle_join, handle_left @@ -20,17 +20,13 @@ app = Sanic(name="welcomecenter") app.config.REGISTERED = False -@app.route('/', methods=["GET"]) +@app.get('/') async def register(req): - res = 'skipped' if not app.config.REGISTERED: - r = register_webhook(WEBHOOK) - print(f'\n\t\t\tWEBHOOK REGISTERED:\n{r}') + print(register_webhook()) app.config.REGISTERED = True - print(r) - res = 'ok' handle_startup() - return text(res) + return text('ok') @app.post('/') @@ -43,6 +39,8 @@ async def handle(req): # видимые сообщения msg = update.get('message', update.get('edited_message')) if msg: + if 'edited_message' in update: + msg['edit'] = True if 'text' in msg: if msg['chat']['id'] == msg['from']['id']: print('private chat message') diff --git a/tgbot/api.py b/tgbot/api.py index b51dc38..f4e6f75 100644 --- a/tgbot/api.py +++ b/tgbot/api.py @@ -151,7 +151,7 @@ def get_chat_administrators(chat_id): # https://core.telegram.org/bots/api#getchatmember def get_member(chat_id, member_id): - url = apiBase + f"getChatMember?chat_id={chat_id}&user_id={member_id}" + url = apiBase + f"getChatMember?chat_id={member_id}&user_id={member_id}" r = requests.get(url) return r.json() diff --git a/tgbot/config.py b/tgbot/config.py index 3dd9205..b884c81 100644 --- a/tgbot/config.py +++ b/tgbot/config.py @@ -1,6 +1,6 @@ import os - +BOT_TOKEN = os.environ.get('BOT_TOKEN') or '' WEBHOOK = os.environ.get('VERCEL_URL') or 'http://localhost:8000' REDIS_URL = os.environ.get('REDIS_URL') or 'redis://localhost:6379' FEEDBACK_CHAT_ID = os.environ.get('FEEDBACK_CHAT_ID').replace("-", "-100") \ No newline at end of file diff --git a/tgbot/handlers/callback_vouch.py b/tgbot/handlers/callback_vouch.py index cf6d02f..6f56dea 100644 --- a/tgbot/handlers/callback_vouch.py +++ b/tgbot/handlers/callback_vouch.py @@ -4,25 +4,27 @@ from tgbot.storage import Profile, storage def update_button(chat_id, member_id, text='❤️'): - print('update reply markup') - prevmsg_id = storage.get(f'btn-{chat_id}-{member_id}') - if prevmsg_id: - premsg_id = prevmsg_id.decode('utf-8') - newcomer = Profile.get(member_id) - amount = len(newcomer['parents']) + 1 - text += f' {amount}' - rm = { - "inline_keyboard": [ - [ - { - "text": text, - "callback_data": 'vouch' + member_id - } + button_message_id = storage.get(f'btn-{chat_id}-{member_id}') + print(f'button_message_id: {button_message_id}') + if button_message_id: + button_message_id = button_message_id.decode('utf-8') + print(f'button_message_id: {button_message_id}') + print('update reply markup') + newcomer = Profile.get(member_id) + amount = len(newcomer['parents']) + 1 + text += f' {amount}' + rm = { + "inline_keyboard": [ + [ + { + "text": text, + "callback_data": 'vouch' + member_id + } + ] ] - ] - } - r = edit_replymarkup(chat_id, prevmsg_id, reply_markup=rm) - print(r) + } + r = edit_replymarkup(chat_id, button_message_id, reply_markup=rm) + print(r) def handle_button(callback_query):