Change how handled messages are stored

This commit is contained in:
blank X 2021-03-10 14:51:10 +07:00
parent f137a327ce
commit 12bc8afa43
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
3 changed files with 13 additions and 12 deletions

View File

@ -1,10 +1,11 @@
import html import html
import asyncio import asyncio
from collections import defaultdict
from pyrogram import Client, filters from pyrogram import Client, filters
from pyrogram.errors.exceptions.flood_420 import FloodWait from pyrogram.errors.exceptions.flood_420 import FloodWait
from .. import config, slave, log_errors, app_user_ids from .. import config, slave, log_errors, app_user_ids
logged = set() logged = defaultdict(set)
lock = asyncio.Lock() lock = asyncio.Lock()
@Client.on_message(~filters.forwarded & ~filters.chat(config['config']['log_chat']) & filters.incoming & filters.forwarded & (filters.group | filters.channel)) @Client.on_message(~filters.forwarded & ~filters.chat(config['config']['log_chat']) & filters.incoming & filters.forwarded & (filters.group | filters.channel))
@ -27,9 +28,8 @@ async def log_forwards(client, message):
break break
else: else:
return return
identifier = (message.chat.id, message.message_id)
async with lock: async with lock:
if identifier in logged: if message.message_id not in logged[message.chat.id]:
return return
chat_text = html.escape(message.chat.title) chat_text = html.escape(message.chat.title)
if message.chat.username: if message.chat.username:
@ -94,4 +94,4 @@ async def log_forwards(client, message):
await asyncio.sleep(ex.x + 1) await asyncio.sleep(ex.x + 1)
else: else:
break break
logged.add(identifier) logged[message.chat.id].add(message.message_id)

View File

@ -1,10 +1,11 @@
import html import html
import asyncio import asyncio
from collections import defaultdict
from pyrogram import Client, filters from pyrogram import Client, filters
from pyrogram.errors.exceptions.flood_420 import FloodWait from pyrogram.errors.exceptions.flood_420 import FloodWait
from .. import config, slave, log_errors from .. import config, slave, log_errors
reported = set() reported = defaultdict(set)
lock = asyncio.Lock() lock = asyncio.Lock()
@Client.on_message(~filters.forwarded & ~filters.chat(config['config']['log_chat']) & filters.regex(r'(?:^|\s+)@admins?(?:$|\W+)|^[/!](?:report|admins?)(?:$|\W+)') & filters.group) @Client.on_message(~filters.forwarded & ~filters.chat(config['config']['log_chat']) & filters.regex(r'(?:^|\s+)@admins?(?:$|\W+)|^[/!](?:report|admins?)(?:$|\W+)') & filters.group)
@ -12,9 +13,8 @@ lock = asyncio.Lock()
async def log_reports(client, message): async def log_reports(client, message):
if not config['config']['log_reports']: if not config['config']['log_reports']:
return return
identifier = (message.chat.id, message.message_id)
async with lock: async with lock:
if identifier in reported: if message.message_id in reported[message.chat.id]:
return return
chat_text = html.escape(message.chat.title) chat_text = html.escape(message.chat.title)
if message.chat.username: if message.chat.username:
@ -99,5 +99,5 @@ async def log_reports(client, message):
await asyncio.sleep(ex.x + 1) await asyncio.sleep(ex.x + 1)
else: else:
break break
reported.add(identifier) reported[message.chat.id].add(message.message_id)
reported.add((reply.chat.id, reply.message_id)) reported[reply.chat.id].add(reply.message_id)

View File

@ -1,5 +1,6 @@
import html import html
import asyncio import asyncio
from collections import defaultdict
from pyrogram import Client, ContinuePropagation from pyrogram import Client, ContinuePropagation
from pyrogram.errors.exceptions.flood_420 import FloodWait from pyrogram.errors.exceptions.flood_420 import FloodWait
from pyrogram.raw.types import UpdateNewChannelMessage, UpdateNewMessage, MessageService, PeerChat, PeerChannel, MessageActionChatAddUser, MessageActionChatJoinedByLink, PeerUser from pyrogram.raw.types import UpdateNewChannelMessage, UpdateNewMessage, MessageService, PeerChat, PeerChannel, MessageActionChatAddUser, MessageActionChatJoinedByLink, PeerUser
@ -11,7 +12,7 @@ def sexy_user_name(user):
text += ' ' + user.last_name text += ' ' + user.last_name
return f'{"<code>[DELETED]</code>" if user.deleted else html.escape(text or "Empty???")} [<code>{user.id}</code>]' return f'{"<code>[DELETED]</code>" if user.deleted else html.escape(text or "Empty???")} [<code>{user.id}</code>]'
handled = set() handled = defaultdict(set)
lock = asyncio.Lock() lock = asyncio.Lock()
@Client.on_raw_update() @Client.on_raw_update()
@log_errors @log_errors
@ -45,7 +46,7 @@ async def log_user_joins(client, update, users, chats):
atext = f'<a href="https://t.me/{chats[chat_id].username}">{atext}</a>' atext = f'<a href="https://t.me/{chats[chat_id].username}">{atext}</a>'
text += f"{atext} [<code>{sexy_chat_id}</code>]\n" text += f"{atext} [<code>{sexy_chat_id}</code>]\n"
async with lock: async with lock:
if (sexy_chat_id, message.id) not in handled: if message.id not in handled[sexy_chat_id]:
if isinstance(message.from_id, PeerUser): if isinstance(message.from_id, PeerUser):
adder = sexy_user_name(users[message.from_id.user_id]) adder = sexy_user_name(users[message.from_id.user_id])
else: else:
@ -65,6 +66,6 @@ async def log_user_joins(client, update, users, chats):
await asyncio.sleep(ex.x + 1) await asyncio.sleep(ex.x + 1)
else: else:
break break
handled.add((sexy_chat_id, message.id)) handled[sexy_chat_id].add(message.id)
return return
raise ContinuePropagation raise ContinuePropagation