From 1dbde24525dde02ec6987edd1d484c8a12852517 Mon Sep 17 00:00:00 2001 From: blank X Date: Thu, 24 Dec 2020 16:40:29 +0700 Subject: [PATCH] Anonymous admin support for log_forwards and log_reports --- sukuinote/plugins/log_forwards.py | 33 ++++++++++++++++++------------- sukuinote/plugins/log_reports.py | 28 +++++++++++++++----------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/sukuinote/plugins/log_forwards.py b/sukuinote/plugins/log_forwards.py index 246178e..073f681 100644 --- a/sukuinote/plugins/log_forwards.py +++ b/sukuinote/plugins/log_forwards.py @@ -12,7 +12,7 @@ lock = asyncio.Lock() async def log_forwards(client, message): if not config['config'].get('log_forwards'): return - if not message.from_user or message.from_user.id in app_user_ids: + if getattr(message.from_user, 'id', None) in app_user_ids: return for i in app_user_ids: if message.forward_from: @@ -41,19 +41,24 @@ async def log_forwards(client, message): chat_text += '[SUPPORT] ' if message.chat.is_scam: chat_text += '[SCAM] ' - text += f'[{message.chat.id}]\n- Forwarder: ' - user_text = message.from_user.first_name - if message.from_user.last_name: - user_text += f' {message.from_user.last_name}' - user_text = '[DELETED]' if message.from_user.is_deleted else html.escape(user_text or 'Empty???') - if message.from_user.is_verified: - user_text += ' [VERIFIED]' - if message.from_user.is_support: - user_text += ' [SUPPORT]' - if message.from_user.is_scam: - user_text += ' [SCAM]' - text += f'{user_text} [{message.from_user.id}]\n' - text += f'- Message' + text += f'[{message.chat.id}]' + if message.chat.type != 'channel': + if message.from_user: + user_text = message.from_user.first_name + if message.from_user.last_name: + user_text += f' {message.from_user.last_name}' + user_text = '[DELETED]' if message.from_user.is_deleted else html.escape(user_text or 'Empty???') + if message.from_user.is_verified: + user_text += ' [VERIFIED]' + if message.from_user.is_support: + user_text += ' [SUPPORT]' + if message.from_user.is_scam: + user_text += ' [SCAM]' + user_text += f' [{message.from_user.id}]' + else: + user_text = 'Anonymous' + text += f'\n- Forwarder: {user_text}' + text += f'\n- Message' mtext = (message.text or message.caption or '').strip() if mtext: text += ':' diff --git a/sukuinote/plugins/log_reports.py b/sukuinote/plugins/log_reports.py index 8f34cc6..2b15383 100644 --- a/sukuinote/plugins/log_reports.py +++ b/sukuinote/plugins/log_reports.py @@ -27,17 +27,21 @@ async def log_reports(client, message): if message.chat.is_scam: chat_text += '[SCAM] ' text += f'[{message.chat.id}]\n- Reporter: ' - user_text = message.from_user.first_name - if message.from_user.last_name: - user_text += f' {message.from_user.last_name}' - user_text = '[DELETED]' if message.from_user.is_deleted else html.escape(user_text or 'Empty???') - if message.from_user.is_verified: - user_text += ' [VERIFIED]' - if message.from_user.is_support: - user_text += ' [SUPPORT]' - if message.from_user.is_scam: - user_text += ' [SCAM]' - text += f'{user_text} [{message.from_user.id}]\n' + if message.from_user: + user_text = message.from_user.first_name + if message.from_user.last_name: + user_text += f' {message.from_user.last_name}' + user_text = '[DELETED]' if message.from_user.is_deleted else html.escape(user_text or 'Empty???') + if message.from_user.is_verified: + user_text += ' [VERIFIED]' + if message.from_user.is_support: + user_text += ' [SUPPORT]' + if message.from_user.is_scam: + user_text += ' [SCAM]' + user_text += f' [{message.from_user.id}]' + else: + user_text = 'Anonymous' + text += f'{user_text}\n' start, end = message.matches[0].span() text += f'- Report Message' mtext = (message.text or message.caption or '').strip() @@ -62,7 +66,7 @@ async def log_reports(client, message): user_text += ' [SCAM]' user_text += f' [{reply.from_user.id}]' else: - user_text = 'None???' + user_text = 'Anonymous' text += f'{user_text}\n- Reported Message' mtext = reply.text or reply.caption or '' if mtext.strip():