dokku-comp

This commit is contained in:
2023-09-11 23:04:53 +03:00
parent 4be2dc3a45
commit b9a98f1e56
25 changed files with 646 additions and 460 deletions

View File

@@ -1,16 +1,10 @@
from bot.handlers.handle_feedback import handle_feedback, handle_answer
from bot.handlers.handle_members_change import handle_join, handle_left
from bot.handlers.handle_join_request import handle_join_request
from bot.handlers.handle_default import handle_default
from bot.handlers.command_my import handle_command_my
from bot.handlers.command_graph import handle_command_graph
from bot.handlers.command_ask import handle_command_ask
from bot.handlers.routing import handle_routing
from bot.handlers.callback_vouch import handle_button
from bot.handlers.callback_unlink import handle_unlink
from bot.handlers.handle_startup import handle_startup
from bot.handlers.handle_join_request import handle_join_request
from bot.api import register_webhook, send_message
from bot.config import FEEDBACK_CHAT_ID
from bot.state import State
from sanic.app import Sanic
app = Sanic(name="welcomecenter")
@@ -19,16 +13,16 @@ app.config.REGISTERED = False
state = State()
@app.get('/')
@app.get("/")
async def register(req):
if not app.config.REGISTERED:
print(register_webhook())
app.config.REGISTERED = True
handle_startup()
return text('ok')
await handle_startup()
return text("ok")
@app.post('/')
@app.post("/")
async def handle(req):
print(req)
try:
@@ -36,57 +30,27 @@ async def handle(req):
print(update)
# видимые сообщения
msg = update.get('message', update.get('edited_message'))
msg = update.get("message", update.get("edited_message"))
if msg:
msg['edit'] = 'edited_message' in update
if msg['chat']['id'] == msg['from']['id']:
# сообщения в личке с ботом
print('private chat message')
if msg['text'].startswith('/my'):
handle_command_my(msg)
elif msg['text'].startswith('/unlink'):
handle_unlink(msg)
else:
handle_feedback(msg, state)
elif str(msg['chat']['id']) == FEEDBACK_CHAT_ID:
# сообщения из группы обратной связи
print('feedback chat message')
if 'reply_to_message' in msg:
handle_answer(msg)
elif msg['text'] == '/graph':
await handle_command_graph(msg)
elif msg['text'].startswith('/ask'):
handle_command_ask(msg)
else:
# сообщения из всех остальных групп
cid = msg['chat']['id']
print(f'group {cid} chat message')
if 'text' in msg:
handle_default(msg)
elif 'new_chat_member' in msg:
handle_join(msg)
elif 'left_chat_member' in msg:
handle_left(msg)
msg["edit"] = "edited_message" in update
await handle_routing(msg)
# кнопки
elif 'callback_query' in update:
data = update['callback_query']['data']
if data.startswith('vouch'):
handle_button(update['callback_query'])
elif data.startswith('unlink'):
handle_unlink(update['callback_query'])
elif "callback_query" in update:
data = update["callback_query"]["data"]
if data.startswith("vouch"):
await handle_button(update["callback_query"])
elif data.startswith("unlink"):
await handle_unlink(update["callback_query"])
# заявки
elif 'chat_join_request' in update:
print('chat join request')
handle_join_request(update['chat_join_request'])
elif "chat_join_request" in update:
print("chat join request")
await handle_join_request(update["chat_join_request"])
except Exception:
import traceback
r = send_message(FEEDBACK_CHAT_ID, f'<pre>\n{traceback.format_exc()}\n</pre>')
await send_message(FEEDBACK_CHAT_ID, f"<pre>\n{traceback.format_exc()}\n</pre>")
traceback.print_exc()
return text('ok')
return text("ok")