2
0
mirror of https://github.com/Nick80835/microbot synced 2025-08-22 18:19:16 +00:00

improve/fix moderation mentions

This commit is contained in:
Nick80835 2023-10-21 20:35:06 -04:00
parent 4aae840a8c
commit 0119698e81
3 changed files with 15 additions and 6 deletions

View File

@ -6,7 +6,8 @@ from telethon.events.inlinequery import InlineQuery
from telethon.events.newmessage import NewMessage from telethon.events.newmessage import NewMessage
from telethon.tl.types import (DocumentAttributeFilename, from telethon.tl.types import (DocumentAttributeFilename,
DocumentAttributeImageSize, DocumentAttributeImageSize,
DocumentAttributeSticker) DocumentAttributeSticker,
MessageEntityMentionName)
from ubot.command import (CallbackQueryCommand, Command, InlineArticleCommand, from ubot.command import (CallbackQueryCommand, Command, InlineArticleCommand,
InlinePhotoCommand) InlinePhotoCommand)
@ -24,6 +25,10 @@ class ExtendedNewMessage(NewMessage.Event):
other_args: tuple # any groups between the args group and the command itself other_args: tuple # any groups between the args group and the command itself
nsfw_disabled: bool # only set if pass_nsfw is True; this value is the opposite of nsfw_enabled in chat_db nsfw_disabled: bool # only set if pass_nsfw is True; this value is the opposite of nsfw_enabled in chat_db
@property
def has_user_entities(self) -> bool:
return any([i for i in self.entities if isinstance(i, MessageEntityMentionName)]) if self.entities else False
async def get_text(self, return_msg=False, default=""): async def get_text(self, return_msg=False, default=""):
if self.args: if self.args:
if return_msg: if return_msg:

View File

@ -4,7 +4,7 @@ from telethon.tl.types import Channel, Chat, MessageEntityMentionName
async def get_user(event, allow_channel=False): async def get_user(event, allow_channel=False):
if mention_entities := [i for i in event.get_entities_text() if isinstance(i, MessageEntityMentionName)]: if mention_entities := [i for i in event.entities if isinstance(i, MessageEntityMentionName)] if event.entities else False:
if len(mention_entities) > 1: if len(mention_entities) > 1:
await event.reply("You provided too many arguments!") await event.reply("You provided too many arguments!")
return return

View File

@ -18,7 +18,7 @@ async def kick_user(event):
await event.reply("I can't kick users in this chat.") await event.reply("I can't kick users in this chat.")
return return
if time_regex.sub("", event.args).strip().lower() == "me": if time_regex.sub("", event.args).strip().lower() == "me" and not event.has_user_entities:
self_harm = True self_harm = True
user_to_kick = await event.get_sender() user_to_kick = await event.get_sender()
else: else:
@ -63,7 +63,7 @@ async def ban_user(event):
if time_match := time_regex.search(event.args): if time_match := time_regex.search(event.args):
event.args = time_regex.sub("", event.args).strip() event.args = time_regex.sub("", event.args).strip()
if time_regex.sub("", event.args).strip().lower() == "me": if time_regex.sub("", event.args).strip().lower() == "me" and not event.has_user_entities:
await event.reply("I don't think I should do that…") await event.reply("I don't think I should do that…")
return return
@ -105,6 +105,10 @@ async def ban_user(event):
@ldr.add("unban", moderation=True, help="Unban a user.") @ldr.add("unban", moderation=True, help="Unban a user.")
@ldr.add(f"{bot_name}(,|) unban", moderation=True, simple_pattern=True, hide_help=True) @ldr.add(f"{bot_name}(,|) unban", moderation=True, simple_pattern=True, hide_help=True)
async def unban_user(event): async def unban_user(event):
if event.args.lower() == "me" and not event.has_user_entities:
await event.reply("You probably aren't banned.")
return
if not (await event.client.get_permissions(event.chat, "me")).ban_users: if not (await event.client.get_permissions(event.chat, "me")).ban_users:
await event.reply("I can't unban users in this chat.") await event.reply("I can't unban users in this chat.")
return return
@ -135,7 +139,7 @@ async def mute_user(event):
if time_match := time_regex.search(event.args): if time_match := time_regex.search(event.args):
event.args = time_regex.sub("", event.args).strip() event.args = time_regex.sub("", event.args).strip()
if time_regex.sub("", event.args).strip().lower() == "me": if time_regex.sub("", event.args).strip().lower() == "me" and not event.has_user_entities:
self_harm = True self_harm = True
user_to_mute = await event.get_sender() user_to_mute = await event.get_sender()
else: else:
@ -186,7 +190,7 @@ async def mute_user(event):
@ldr.add("unmute", moderation=True, help="Unmute a user.") @ldr.add("unmute", moderation=True, help="Unmute a user.")
@ldr.add(f"{bot_name}(,|) unmute", moderation=True, simple_pattern=True, hide_help=True) @ldr.add(f"{bot_name}(,|) unmute", moderation=True, simple_pattern=True, hide_help=True)
async def unmute_user(event): async def unmute_user(event):
if event.args.lower() == "me": if event.args.lower() == "me" and not event.has_user_entities:
await event.reply("You probably aren't muted.") await event.reply("You probably aren't muted.")
return return