mirror of
https://github.com/Xtao-Labs/sticker-captcha-bot.git
synced 2024-11-22 07:07:51 +00:00
feat: remove fail user service message
This commit is contained in:
parent
b67926c83a
commit
ba68b86dbe
@ -8,6 +8,7 @@ from pyrogram.types import ChatMemberUpdated
|
|||||||
|
|
||||||
from pyromod.utils.errors import TimeoutConversationError
|
from pyromod.utils.errors import TimeoutConversationError
|
||||||
from sticker.scheduler import add_delete_message_job
|
from sticker.scheduler import add_delete_message_job
|
||||||
|
from sticker.service_message import ServiceMessage
|
||||||
from sticker.single_utils import Client
|
from sticker.single_utils import Client
|
||||||
from sticker import bot, log
|
from sticker import bot, log
|
||||||
|
|
||||||
@ -90,6 +91,7 @@ async def invite(client: Client, chat_member_updated: ChatMemberUpdated):
|
|||||||
)
|
)
|
||||||
with contextlib.suppress(Exception):
|
with contextlib.suppress(Exception):
|
||||||
await log(chat, user, "FAIL_ERROR")
|
await log(chat, user, "FAIL_ERROR")
|
||||||
|
await ServiceMessage.try_delete(user.id, chat.id)
|
||||||
else:
|
else:
|
||||||
with contextlib.suppress(Exception):
|
with contextlib.suppress(Exception):
|
||||||
await log(chat, user, "ACCEPT")
|
await log(chat, user, "ACCEPT")
|
||||||
@ -104,3 +106,4 @@ async def invite(client: Client, chat_member_updated: ChatMemberUpdated):
|
|||||||
)
|
)
|
||||||
with contextlib.suppress(Exception):
|
with contextlib.suppress(Exception):
|
||||||
await log(chat, user, "FAIL_TIMEOUT")
|
await log(chat, user, "FAIL_TIMEOUT")
|
||||||
|
await ServiceMessage.try_delete(user.id, chat.id)
|
||||||
|
31
plugins/service.py
Normal file
31
plugins/service.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
from pyrogram import filters
|
||||||
|
from pyrogram.enums import MessageServiceType
|
||||||
|
|
||||||
|
from sticker import bot
|
||||||
|
from sticker.service_message import ServiceMessage
|
||||||
|
from sticker.single_utils import Client, Message
|
||||||
|
|
||||||
|
|
||||||
|
@bot.on_message(filters.service)
|
||||||
|
async def service_message_handle(_: Client, message: Message):
|
||||||
|
if message.service != MessageServiceType.NEW_CHAT_MEMBERS:
|
||||||
|
return
|
||||||
|
cid = message.chat.id
|
||||||
|
if message.new_chat_members:
|
||||||
|
for i in message.new_chat_members:
|
||||||
|
if i.is_self:
|
||||||
|
return
|
||||||
|
user = (
|
||||||
|
message.new_chat_members[0] if message.new_chat_members else message.from_user
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
user.is_self
|
||||||
|
or user.is_verified
|
||||||
|
or user.is_bot
|
||||||
|
or user.is_deleted
|
||||||
|
or user.is_support
|
||||||
|
):
|
||||||
|
return
|
||||||
|
uid = user.id
|
||||||
|
mid = message.id
|
||||||
|
await ServiceMessage.set_cache(uid, cid, mid)
|
28
sticker/service_message.py
Normal file
28
sticker/service_message.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import contextlib
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
from cashews import cache
|
||||||
|
|
||||||
|
from sticker import bot
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceMessage:
|
||||||
|
@staticmethod
|
||||||
|
async def set_cache(uid: int, cid: int, mid: int):
|
||||||
|
old = await ServiceMessage.get_cache(uid, cid)
|
||||||
|
old.append(mid)
|
||||||
|
await cache.set(f"service_message:{uid}:{cid}", old, expire=600)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def get_cache(uid: int, cid: int) -> List[int]:
|
||||||
|
data = await cache.get(f"service_message:{uid}:{cid}")
|
||||||
|
if data:
|
||||||
|
return data
|
||||||
|
return []
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def try_delete(uid: int, cid: int):
|
||||||
|
mid = await ServiceMessage.get_cache(uid, cid)
|
||||||
|
if mid:
|
||||||
|
with contextlib.suppress(Exception):
|
||||||
|
await bot.delete_messages(cid, list(mid))
|
Loading…
Reference in New Issue
Block a user