diff --git a/CHANGELOG.md b/CHANGELOG.md index dd248ad..667b05c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [0.0.12] +- исправления в коммандах /ask и /my +- исправление обработки случая без фото +- + ## [0.0.11] - отображение одобренности заявки на кнопке diff --git a/README.md b/README.md index faf3216..9f03157 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,4 @@ - BOT_TOKEN - токен бота созданный с помощью @BotFather - FEEDBACK_CHAT_ID - айди чата для обратной связи + - REDIS_URL diff --git a/tgbot/api.py b/src/api.py similarity index 97% rename from tgbot/api.py rename to src/api.py index f4e6f75..1cb1691 100644 --- a/tgbot/api.py +++ b/src/api.py @@ -2,15 +2,14 @@ import requests import aiohttp import json import os +from config import BOT_TOKEN, WEBHOOK + -TOKEN = os.environ.get('BOT_TOKEN') apiBase = f"https://api.telegram.org/bot{TOKEN}/" -def register_webhook(url): - r = requests.get( - apiBase + f'setWebhook?url={url}' - ) +def register_webhook(): + r = requests.get(apiBase + f'setWebhook?url={WEBHOOK}') return r.json() diff --git a/tgbot/config.py b/src/config.py similarity index 100% rename from tgbot/config.py rename to src/config.py diff --git a/tgbot/handlers/callback_unlink.py b/src/handlers/callback_unlink.py similarity index 89% rename from tgbot/handlers/callback_unlink.py rename to src/handlers/callback_unlink.py index ffad6ac..3fb6180 100644 --- a/tgbot/handlers/callback_unlink.py +++ b/src/handlers/callback_unlink.py @@ -1,7 +1,7 @@ -from tgbot.api import send_message, delete_message, kick_member -from tgbot.handlers.command_my import handle_command_my -from tgbot.utils.mention import userdata_extract -from tgbot.storage import Profile +from api import send_message, delete_message, kick_member +from handlers.command_my import handle_command_my +from utils.mention import userdata_extract +from storage import Profile # remove link of callback sender # from member vouched before diff --git a/tgbot/handlers/callback_vouch.py b/src/handlers/callback_vouch.py similarity index 93% rename from tgbot/handlers/callback_vouch.py rename to src/handlers/callback_vouch.py index 6f56dea..1bd8d41 100644 --- a/tgbot/handlers/callback_vouch.py +++ b/src/handlers/callback_vouch.py @@ -1,6 +1,6 @@ -from tgbot.api import send_message, forward_message, delete_message, \ +from api import send_message, forward_message, delete_message, \ approve_chat_join_request, edit_replymarkup, get_chat -from tgbot.storage import Profile, storage +from storage import Profile, storage def update_button(chat_id, member_id, text='❤️'): diff --git a/tgbot/handlers/command_ask.py b/src/handlers/command_ask.py similarity index 73% rename from tgbot/handlers/command_ask.py rename to src/handlers/command_ask.py index a288d6a..b4a2313 100644 --- a/tgbot/handlers/command_ask.py +++ b/src/handlers/command_ask.py @@ -1,6 +1,6 @@ -from tgbot.storage import Profile -from tgbot.handlers.send_button import show_request_msg -from tgbot.api import get_member +from storage import Profile +from handlers.send_button import show_request_msg +from api import get_member def handle_command_ask(msg): print(f'handling request resend') diff --git a/tgbot/handlers/command_graph.py b/src/handlers/command_graph.py similarity index 66% rename from tgbot/handlers/command_graph.py rename to src/handlers/command_graph.py index 9dd0a9c..dbbed9d 100644 --- a/tgbot/handlers/command_graph.py +++ b/src/handlers/command_graph.py @@ -1,6 +1,6 @@ -from tgbot.utils.graph import generate_chart -from tgbot.api import send_document -from tgbot.storage import storage, scan +from utils.graph import generate_chart +from api import send_document +from storage import storage, scan import json diff --git a/tgbot/handlers/command_my.py b/src/handlers/command_my.py similarity index 89% rename from tgbot/handlers/command_my.py rename to src/handlers/command_my.py index 57a62ea..a73caf2 100644 --- a/tgbot/handlers/command_my.py +++ b/src/handlers/command_my.py @@ -1,6 +1,6 @@ -from tgbot.storage import Profile, scan -from tgbot.api import get_member, send_message, get_chat_administrators -from tgbot.utils.mention import userdata_extract +from storage import Profile, scan +from api import get_member, send_message, get_chat_administrators +from utils.mention import userdata_extract def construct_unlink_buttons(actor): diff --git a/tgbot/handlers/handle_default.py b/src/handlers/handle_default.py similarity index 86% rename from tgbot/handlers/handle_default.py rename to src/handlers/handle_default.py index 165e7c7..23fba1a 100644 --- a/tgbot/handlers/handle_default.py +++ b/src/handlers/handle_default.py @@ -1,7 +1,7 @@ -from tgbot.api import send_message, delete_message, get_chat_administrators -from tgbot.storage import Profile -from tgbot.handlers.send_button import show_request_msg -from tgbot.storage import storage +from api import send_message, delete_message, get_chat_administrators +from storage import Profile +from handlers.send_button import show_request_msg +from storage import storage def handle_default(msg): print(f'default handler for all messages') diff --git a/tgbot/handlers/handle_feedback.py b/src/handlers/handle_feedback.py similarity index 83% rename from tgbot/handlers/handle_feedback.py rename to src/handlers/handle_feedback.py index d35ec3a..631dc50 100644 --- a/tgbot/handlers/handle_feedback.py +++ b/src/handlers/handle_feedback.py @@ -1,10 +1,10 @@ import json -from tgbot.api import send_message, forward_message, delete_message, get_chat_administrators -from tgbot.handlers.send_button import show_request_msg -from tgbot.utils.mention import userdata_extract -from tgbot.storage import storage, Profile -from tgbot.config import FEEDBACK_CHAT_ID +from api import send_message, forward_message, delete_message, get_chat_administrators +from handlers.send_button import show_request_msg +from utils.mention import userdata_extract +from storage import storage, Profile +from config import FEEDBACK_CHAT_ID def handle_feedback(msg): diff --git a/tgbot/handlers/handle_join_request.py b/src/handlers/handle_join_request.py similarity index 74% rename from tgbot/handlers/handle_join_request.py rename to src/handlers/handle_join_request.py index a23e498..f7dda29 100644 --- a/tgbot/handlers/handle_join_request.py +++ b/src/handlers/handle_join_request.py @@ -1,6 +1,6 @@ -from tgbot.api import approve_chat_join_request, delete_message -from tgbot.handlers.send_button import show_request_msg -from tgbot.storage import Profile, storage +from api import approve_chat_join_request, delete_message +from handlers.send_button import show_request_msg +from storage import Profile, storage def handle_join_request(msg): diff --git a/tgbot/handlers/handle_members_change.py b/src/handlers/handle_members_change.py similarity index 89% rename from tgbot/handlers/handle_members_change.py rename to src/handlers/handle_members_change.py index f0a8f00..22ddff8 100644 --- a/tgbot/handlers/handle_members_change.py +++ b/src/handlers/handle_members_change.py @@ -1,7 +1,7 @@ -from tgbot.handlers.send_button import show_request_msg -from tgbot.api import delete_message -from tgbot.storage import Profile, storage -from tgbot.config import FEEDBACK_CHAT_ID +from handlers.send_button import show_request_msg +from api import delete_message +from storage import Profile, storage +from config import FEEDBACK_CHAT_ID def handle_join(msg): chat_id = str(msg['chat']['id']) diff --git a/tgbot/handlers/handle_startup.py b/src/handlers/handle_startup.py similarity index 83% rename from tgbot/handlers/handle_startup.py rename to src/handlers/handle_startup.py index 312340e..24caf22 100644 --- a/tgbot/handlers/handle_startup.py +++ b/src/handlers/handle_startup.py @@ -1,7 +1,7 @@ -from tgbot.storage import scan, Profile -from tgbot.api import approve_chat_join_request, kick_member -from tgbot.handlers.callback_vouch import update_button -from tgbot.utils.mention import userdata_extract +from storage import scan, Profile +from api import approve_chat_join_request, kick_member +from handlers.callback_vouch import update_button +from utils.mention import userdata_extract # устанавливает соответствие данных def handle_startup(): diff --git a/tgbot/handlers/send_button.py b/src/handlers/send_button.py similarity index 91% rename from tgbot/handlers/send_button.py rename to src/handlers/send_button.py index 73b5d41..2dfaf30 100644 --- a/tgbot/handlers/send_button.py +++ b/src/handlers/send_button.py @@ -1,6 +1,6 @@ -from tgbot.api import send_message, send_photo, get_userphotos -from tgbot.utils.mention import mention, userdata_extract -from tgbot.storage import storage +from api import send_message, send_photo, get_userphotos +from utils.mention import mention, userdata_extract +from storage import storage def show_request_msg(msg): chat_id = str(msg['chat']['id']) diff --git a/tgbot/storage/__init__.py b/src/storage/__init__.py similarity index 90% rename from tgbot/storage/__init__.py rename to src/storage/__init__.py index a263b38..5a95b77 100644 --- a/tgbot/storage/__init__.py +++ b/src/storage/__init__.py @@ -1,6 +1,6 @@ import redis -from tgbot.storage.profile import Profile as ProfileObj -from tgbot.config import REDIS_URL +from storage.profile import Profile as ProfileObj +from config import REDIS_URL import json diff --git a/tgbot/storage/profile.py b/src/storage/profile.py similarity index 100% rename from tgbot/storage/profile.py rename to src/storage/profile.py diff --git a/tgbot/utils/graph.py b/src/utils/graph.py similarity index 100% rename from tgbot/utils/graph.py rename to src/utils/graph.py diff --git a/tgbot/utils/mention.py b/src/utils/mention.py similarity index 100% rename from tgbot/utils/mention.py rename to src/utils/mention.py diff --git a/api/webhook.py b/src/webhook.py similarity index 77% rename from api/webhook.py rename to src/webhook.py index 0b30157..b34cd61 100644 --- a/api/webhook.py +++ b/src/webhook.py @@ -1,20 +1,17 @@ from sanic import Sanic from sanic.response import text - -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 -from tgbot.handlers.handle_join_request import handle_join_request -from tgbot.handlers.handle_default import handle_default -from tgbot.handlers.command_my import handle_command_my -from tgbot.handlers.command_graph import handle_command_graph -from tgbot.handlers.command_ask import handle_command_ask -from tgbot.handlers.callback_vouch import handle_button -from tgbot.handlers.callback_unlink import handle_unlink -from tgbot.handlers.handle_startup import handle_startup -from tgbot.api import register_webhook, send_message - +from handlers.handle_feedback import handle_feedback, handle_answer +from handlers.handle_members_change import handle_join, handle_left +from handlers.handle_join_request import handle_join_request +from handlers.handle_default import handle_default +from handlers.command_my import handle_command_my +from handlers.command_graph import handle_command_graph +from handlers.command_ask import handle_command_ask +from handlers.callback_vouch import handle_button +from handlers.callback_unlink import handle_unlink +from handlers.handle_startup import handle_startup +from api import register_webhook, send_message +from config import FEEDBACK_CHAT_ID app = Sanic(name="welcomecenter") app.config.REGISTERED = False diff --git a/vercel.json b/vercel.json index e2e757a..5428422 100755 --- a/vercel.json +++ b/vercel.json @@ -1,7 +1,7 @@ { "version": 2, "functions": { - "api/webhook.py": { + "src/webhook.py": { "memory": 1024, "maxDuration": 10 } @@ -9,7 +9,7 @@ "routes": [ { "src": "/", - "dest": "/api/webhook.py" + "dest": "/src/webhook.py" } ] }