Exception messages implemented

This commit is contained in:
Profitroll 2022-12-13 14:33:22 +01:00
parent a54d78ccb6
commit 04093d0a20
2 changed files with 57 additions and 50 deletions

View File

@ -1,3 +1,4 @@
from traceback import print_exc
from app import app, isAnAdmin from app import app, isAnAdmin
from typing import Any, List, Union from typing import Any, List, Union
from pyrogram.types import User, ChatMember, ChatPrivileges, Chat, Message, Photo, Video, Document, Animation, Voice from pyrogram.types import User, ChatMember, ChatPrivileges, Chat, Message, Photo, Video, Document, Animation, Voice
@ -72,8 +73,8 @@ class HoloUser():
logWrite(f"Set attribute {key} of user {self.id} to {value}") logWrite(f"Set attribute {key} of user {self.id} to {value}")
async def message(self, async def message(self,
context: Message,
origin: Union[Message, None] = None, origin: Union[Message, None] = None,
context: Union[Message, None] = None,
text: Union[str, None] = None, text: Union[str, None] = None,
caption: Union[str, None] = None, caption: Union[str, None] = None,
photo: Union[str, Photo, None] = None, photo: Union[str, Photo, None] = None,
@ -108,60 +109,64 @@ class HoloUser():
else: else:
caption = locale("message_reply_notice", "message") caption = locale("message_reply_notice", "message")
if origin is not None: try:
if origin is not None:
if photo is not None:
if isinstance(photo, Photo):
photo = photo.file_id
new_message = await origin.reply_photo(photo, caption=caption, quote=True)
elif video is not None:
if isinstance(video, Video):
video = video.file_id
new_message = await origin.reply_video(video, caption=caption, quote=True)
elif file is not None:
if isinstance(file, Document):
file = file.file_id
new_message = await origin.reply_document(file, caption=caption, quote=True)
elif animation is not None:
if isinstance(animation, Animation):
animation = animation.file_id
new_message = await origin.reply_animation(animation, caption=caption, quote=True)
elif voice is not None:
if isinstance(voice, Voice):
voice = voice.file_id
new_message = await origin.reply_voice(voice, caption=caption, quote=True)
else:
new_message = await origin.reply_text(text, quote=True)
if photo is not None:
if isinstance(photo, Photo):
photo = photo.file_id
new_message = await origin.reply_photo(photo, caption=caption, quote=True)
elif video is not None:
if isinstance(video, Video):
video = video.file_id
new_message = await origin.reply_video(video, caption=caption, quote=True)
elif file is not None:
if isinstance(file, Document):
file = file.file_id
new_message = await origin.reply_document(file, caption=caption, quote=True)
elif animation is not None:
if isinstance(animation, Animation):
animation = animation.file_id
new_message = await origin.reply_animation(animation, caption=caption, quote=True)
elif voice is not None:
if isinstance(voice, Voice):
voice = voice.file_id
new_message = await origin.reply_voice(voice, caption=caption, quote=True)
else: else:
new_message = await origin.reply_text(text, quote=True)
else: if photo is not None:
if isinstance(photo, Photo):
photo = photo.file_id
new_message = await app.send_photo(self.id, photo, caption=caption)
elif video is not None:
if isinstance(video, Video):
video = video.file_id
new_message = await app.send_video(self.id, video, caption=caption)
elif file is not None:
if isinstance(file, Document):
file = file.file_id
new_message = await app.send_document(self.id, file, caption=caption)
elif animation is not None:
if isinstance(animation, Animation):
animation = animation.file_id
new_message = await app.send_animation(animation, caption=caption, quote=True)
elif voice is not None:
if isinstance(voice, Voice):
voice = voice.file_id
new_message = await app.send_voice(voice, caption=caption, quote=True)
else:
new_message = await app.send_message(self.id, text)
if photo is not None: await context.reply_text(locale("message_sent", "message"), quote=should_quote(context))
if isinstance(photo, Photo): col_messages.insert_one({"origin": {"chat": context.chat.id, "id": context.id}, "destination": {"chat": new_message.chat.id, "id": new_message.id}})
photo = photo.file_id
new_message = await app.send_photo(self.id, photo, caption=caption)
elif video is not None:
if isinstance(video, Video):
video = video.file_id
new_message = await app.send_video(self.id, video, caption=caption)
elif file is not None:
if isinstance(file, Document):
file = file.file_id
new_message = await app.send_document(self.id, file, caption=caption)
elif animation is not None:
if isinstance(animation, Animation):
animation = animation.file_id
new_message = await app.send_animation(animation, caption=caption, quote=True)
elif voice is not None:
if isinstance(voice, Voice):
voice = voice.file_id
new_message = await app.send_voice(voice, caption=caption, quote=True)
else:
new_message = await app.send_message(self.id, text)
# new_message = await app.send_message(self.id, text+locale("message_reply_notice", "message")) except Exception as exp:
await context.reply_text(locale("message_sent", "message"), quote=should_quote(context)) await context.reply_text(locale("message_traceback", "message").format(context.from_user.id, self.id, exp, print_exc()))
await context.reply_text(locale("message_error", "message"), quote=should_quote(context))
col_messages.insert_one({"origin": {"chat": context.chat.id, "id": context.id}, "destination": {"chat": new_message.chat.id, "id": new_message.id}})
async def set_label(self, chat: Chat, label: str): async def set_label(self, chat: Chat, label: str):
"""Set label in destination group """Set label in destination group

View File

@ -60,6 +60,8 @@
"message_invalid_syntax": "Неправильний синтаксис!\nТреба: `/message ID ПОВІДОМЛЕННЯ`", "message_invalid_syntax": "Неправильний синтаксис!\nТреба: `/message ID ПОВІДОМЛЕННЯ`",
"message_from": "Повідомлення від **{0}** (`{1}`):\n\n", "message_from": "Повідомлення від **{0}** (`{1}`):\n\n",
"message_reply_notice": "\n\n**Щоб надіслати відповідь на це повідомлення, тегніть його.**", "message_reply_notice": "\n\n**Щоб надіслати відповідь на це повідомлення, тегніть його.**",
"message_error": "⚠️ **Сталась помилка**\nНе вдалось надіслати ваше повідомлення. Розробника повідомлено про цю помилку.",
"message_traceback": "⚠️ **Сталась помилка**\nПомилка повідомлень: `{0}` -> `{1}`\nПомилка: `{2}`\n\nTraceback:\n```\n{3}\n```",
"question_titles": { "question_titles": {
"question1": "Ім'я/звертання:", "question1": "Ім'я/звертання:",
"question2": "День народження:", "question2": "День народження:",