fixes-logs-imports

This commit is contained in:
2023-09-18 10:50:48 +03:00
parent cf4f13ae9b
commit 95071ec301
14 changed files with 98 additions and 61 deletions

View File

@@ -1,10 +1,13 @@
from api import send_message, send_photo, get_userphotos
from api import send_message, send_photo, get_userphotos, delete_message
from utils.mention import mention, userdata_extract
from storage import storage
import logging
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
async def show_request_msg(msg):
print("showing request with button")
logger.info("showing request with button")
chat_id = str(msg["chat"]["id"])
from_id = str(msg["from"]["id"])
lang = msg["from"].get("language_code", "ru")
@@ -17,12 +20,12 @@ async def show_request_msg(msg):
else "There is a newcomer, press the button if you are connected with "
)
r = await get_userphotos(user_id=from_id)
print(r)
logger.debug(r)
if r["ok"] and r["result"]["total_count"] > 0:
print("show button with photo")
file_id = r["result"]["photos"][0][0]["file_id"]
_uid, identity, username = userdata_extract(msg["from"])
r = send_photo(
r = await send_photo(
chat_id,
file_id,
caption=newcomer_message + f"{identity}{username}",
@@ -30,21 +33,21 @@ async def show_request_msg(msg):
reply_markup=reply_markup,
)
else:
print("show button without photo")
r = send_message(
logger.info("show button without photo")
r = await send_message(
chat_id,
newcomer_message + mention(msg["from"]),
reply_to=msg.get("message_id", ""),
reply_markup=reply_markup,
)
print(r)
logger.debug(r)
if "message_id" in r:
# удаляем предыдущее сообщение с кнопкой в этом чате
prevbtn = storage.get(f"btn-{chat_id}-{from_id}")
if prevbtn:
r = await delete_message(chat_id, prevbtn)
print(r)
logger.debug(r)
# создаём новое
newbtn = r["message_id"]
print(f"button message id: {newbtn}")
logger.info(f"button message id: {newbtn}")
storage.set(f"btn-{chat_id}-{from_id}", newbtn)