2022-06-20 13:55:14 +00:00
|
|
|
""" PagerMaid module for different ways to avoid users. """
|
|
|
|
|
2024-09-28 13:57:55 +00:00
|
|
|
from pagermaid.dependence import sqlite
|
2022-09-01 08:35:19 +00:00
|
|
|
from pagermaid.enums import Client, Message
|
2024-09-28 13:57:55 +00:00
|
|
|
from pagermaid.enums.command import CommandHandler
|
2022-06-20 13:55:14 +00:00
|
|
|
from pagermaid.listener import listener
|
2024-09-28 13:57:55 +00:00
|
|
|
from pagermaid.utils import lang
|
|
|
|
from pagermaid.utils.bot_utils import log
|
2022-06-20 13:55:14 +00:00
|
|
|
|
|
|
|
|
2023-03-12 03:56:01 +00:00
|
|
|
@listener(
|
|
|
|
is_plugin=False,
|
|
|
|
outgoing=True,
|
|
|
|
command="ghost",
|
|
|
|
description=lang("ghost_des"),
|
|
|
|
parameters="<true|false|status>",
|
|
|
|
)
|
2024-04-29 14:05:03 +00:00
|
|
|
async def ghost(message: Message):
|
2023-03-12 03:56:01 +00:00
|
|
|
"""Toggles ghosting of a user."""
|
2022-06-20 13:55:14 +00:00
|
|
|
if len(message.parameter) != 1:
|
|
|
|
await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
|
|
|
return
|
2024-04-29 14:05:03 +00:00
|
|
|
await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
|
|
|
|
|
|
|
|
|
|
|
ghost: "CommandHandler"
|
|
|
|
|
|
|
|
|
|
|
|
@ghost.sub_command(
|
|
|
|
is_plugin=False,
|
|
|
|
outgoing=True,
|
|
|
|
command="true",
|
|
|
|
)
|
|
|
|
async def ghost_true(client: Client, message: Message):
|
2022-09-01 08:35:19 +00:00
|
|
|
myself = await client.get_me()
|
2022-06-20 13:55:14 +00:00
|
|
|
self_user_id = myself.id
|
2024-04-29 14:05:03 +00:00
|
|
|
if message.chat.id == self_user_id:
|
|
|
|
return await message.edit(lang("ghost_e_mark"))
|
|
|
|
sqlite[f"ghosted.chat_id.{str(message.chat.id)}"] = True
|
|
|
|
await message.safe_delete()
|
|
|
|
await log(
|
|
|
|
f"{lang('ghost_set_f')} ChatID {str(message.chat.id)} {lang('ghost_set_l')}"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@ghost.sub_command(
|
|
|
|
is_plugin=False,
|
|
|
|
outgoing=True,
|
|
|
|
command="false",
|
|
|
|
)
|
|
|
|
async def ghost_false(client: Client, message: Message):
|
|
|
|
myself = await client.get_me()
|
|
|
|
self_user_id = myself.id
|
|
|
|
if message.chat.id == self_user_id:
|
|
|
|
await message.edit(lang("ghost_e_mark"))
|
|
|
|
return
|
|
|
|
try:
|
|
|
|
del sqlite[f"ghosted.chat_id.{str(message.chat.id)}"]
|
|
|
|
except KeyError:
|
|
|
|
return await message.edit(lang("ghost_e_noexist"))
|
|
|
|
await message.safe_delete()
|
|
|
|
await log(
|
|
|
|
f"{lang('ghost_set_f')} ChatID {str(message.chat.id)} {lang('ghost_cancel')}"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@ghost.sub_command(
|
|
|
|
is_plugin=False,
|
|
|
|
outgoing=True,
|
|
|
|
command="status",
|
|
|
|
)
|
|
|
|
async def ghost_status(message: Message):
|
|
|
|
if sqlite.get(f"ghosted.chat_id.{str(message.chat.id)}", None):
|
|
|
|
await message.edit(lang("ghost_e_exist"))
|
2022-06-20 13:55:14 +00:00
|
|
|
else:
|
2024-04-29 14:05:03 +00:00
|
|
|
await message.edit(lang("ghost_e_noexist"))
|
2022-06-20 13:55:14 +00:00
|
|
|
|
|
|
|
|
2023-03-12 03:56:01 +00:00
|
|
|
@listener(
|
|
|
|
is_plugin=False,
|
|
|
|
outgoing=True,
|
|
|
|
command="deny",
|
|
|
|
need_admin=True,
|
|
|
|
description=lang("deny_des"),
|
|
|
|
parameters="<true|false|status>",
|
|
|
|
)
|
2024-04-29 14:05:03 +00:00
|
|
|
async def deny(message: Message):
|
2023-03-12 03:56:01 +00:00
|
|
|
"""Toggles denying of a user."""
|
2022-06-20 13:55:14 +00:00
|
|
|
if len(message.parameter) != 1:
|
|
|
|
await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
|
|
|
return
|
2024-04-29 14:05:03 +00:00
|
|
|
await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
|
|
|
|
|
|
|
|
|
|
|
deny: "CommandHandler"
|
|
|
|
|
|
|
|
|
|
|
|
@deny.sub_command(
|
|
|
|
is_plugin=False,
|
|
|
|
outgoing=True,
|
|
|
|
need_admin=True,
|
|
|
|
command="true",
|
|
|
|
)
|
|
|
|
async def deny_true(client: Client, message: Message):
|
2022-09-01 08:35:19 +00:00
|
|
|
myself = await client.get_me()
|
2022-06-20 13:55:14 +00:00
|
|
|
self_user_id = myself.id
|
2024-04-29 14:05:03 +00:00
|
|
|
if message.chat.id == self_user_id:
|
|
|
|
return await message.edit(lang("ghost_e_mark"))
|
|
|
|
sqlite[f"denied.chat_id.{str(message.chat.id)}"] = True
|
|
|
|
await message.safe_delete()
|
|
|
|
await log(f"ChatID {str(message.chat.id)} {lang('deny_set')}")
|
|
|
|
|
|
|
|
|
|
|
|
@deny.sub_command(
|
|
|
|
is_plugin=False,
|
|
|
|
outgoing=True,
|
|
|
|
need_admin=True,
|
|
|
|
command="false",
|
|
|
|
)
|
|
|
|
async def deny_false(client: Client, message: Message):
|
|
|
|
myself = await client.get_me()
|
|
|
|
self_user_id = myself.id
|
|
|
|
if message.chat.id == self_user_id:
|
|
|
|
await message.edit(lang("ghost_e_mark"))
|
|
|
|
return
|
|
|
|
try:
|
|
|
|
del sqlite[f"denied.chat_id.{str(message.chat.id)}"]
|
|
|
|
except KeyError:
|
|
|
|
return await message.edit(lang("deny_e_noexist"))
|
|
|
|
await message.safe_delete()
|
|
|
|
await log(f"ChatID {str(message.chat.id)} {lang('deny_cancel')}")
|
|
|
|
|
|
|
|
|
|
|
|
@deny.sub_command(
|
|
|
|
is_plugin=False,
|
|
|
|
outgoing=True,
|
|
|
|
need_admin=True,
|
|
|
|
command="status",
|
|
|
|
)
|
|
|
|
async def deny_status(message: Message):
|
|
|
|
if sqlite.get(f"denied.chat_id.{str(message.chat.id)}", None):
|
|
|
|
await message.edit(lang("deny_e_exist"))
|
2022-06-20 13:55:14 +00:00
|
|
|
else:
|
2024-04-29 14:05:03 +00:00
|
|
|
await message.edit(lang("deny_e_noexist"))
|
2022-06-20 13:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
@listener(is_plugin=False, incoming=True, outgoing=False, ignore_edited=True)
|
2022-09-01 08:35:19 +00:00
|
|
|
async def set_read_acknowledgement(client: Client, message: Message):
|
2023-03-12 03:56:01 +00:00
|
|
|
"""Event handler to infinitely read ghosted messages."""
|
2022-06-20 13:55:14 +00:00
|
|
|
if sqlite.get(f"ghosted.chat_id.{str(message.chat.id)}", None):
|
2022-09-01 08:35:19 +00:00
|
|
|
await client.read_chat_history(message.chat.id)
|
2022-06-20 13:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
@listener(is_plugin=False, incoming=True, outgoing=False, ignore_edited=True)
|
|
|
|
async def message_removal(message: Message):
|
2023-03-12 03:56:01 +00:00
|
|
|
"""Event handler to infinitely delete denied messages."""
|
2022-06-20 13:55:14 +00:00
|
|
|
if sqlite.get(f"denied.chat_id.{str(message.chat.id)}", None):
|
|
|
|
await message.safe_delete()
|