PagerMaid-Pyro/pagermaid/modules/avoid.py

105 lines
3.9 KiB
Python
Raw Normal View History

2022-06-20 13:55:14 +00:00
""" PagerMaid module for different ways to avoid users. """
from pagermaid import log
from pagermaid.single_utils import sqlite
2022-09-01 08:35:19 +00:00
from pagermaid.utils import lang
from pagermaid.enums import Client, Message
2022-06-20 13:55:14 +00:00
from pagermaid.listener import listener
2023-03-12 03:56:01 +00:00
@listener(
is_plugin=False,
outgoing=True,
command="ghost",
description=lang("ghost_des"),
parameters="<true|false|status>",
)
2022-09-01 08:35:19 +00:00
async def ghost(client: Client, 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
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
if message.parameter[0] == "true":
if message.chat.id == self_user_id:
2023-03-12 03:56:01 +00:00
return await message.edit(lang("ghost_e_mark"))
2022-06-30 07:16:06 +00:00
sqlite[f"ghosted.chat_id.{str(message.chat.id)}"] = True
2022-06-20 13:55:14 +00:00
await message.safe_delete()
2023-03-12 03:56:01 +00:00
await log(
f"{lang('ghost_set_f')} ChatID {str(message.chat.id)} {lang('ghost_set_l')}"
)
2022-06-20 13:55:14 +00:00
elif message.parameter[0] == "false":
2022-06-30 07:16:06 +00:00
if message.chat.id == self_user_id:
2023-03-12 03:56:01 +00:00
await message.edit(lang("ghost_e_mark"))
2022-06-20 13:55:14 +00:00
return
try:
2022-06-30 07:16:06 +00:00
del sqlite[f"ghosted.chat_id.{str(message.chat.id)}"]
2022-06-20 13:55:14 +00:00
except KeyError:
2023-03-12 03:56:01 +00:00
return await message.edit(lang("ghost_e_noexist"))
2022-06-20 13:55:14 +00:00
await message.safe_delete()
2023-03-12 03:56:01 +00:00
await log(
f"{lang('ghost_set_f')} ChatID {str(message.chat.id)} {lang('ghost_cancel')}"
)
2022-06-20 13:55:14 +00:00
elif message.parameter[0] == "status":
2022-06-30 07:16:06 +00:00
if sqlite.get(f"ghosted.chat_id.{str(message.chat.id)}", None):
2023-03-12 03:56:01 +00:00
await message.edit(lang("ghost_e_exist"))
2022-06-20 13:55:14 +00:00
else:
2023-03-12 03:56:01 +00:00
await message.edit(lang("ghost_e_noexist"))
2022-06-20 13:55:14 +00:00
else:
await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
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>",
)
2022-09-01 08:35:19 +00:00
async def deny(client: Client, 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
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
if message.parameter[0] == "true":
if message.chat.id == self_user_id:
2023-03-12 03:56:01 +00:00
return await message.edit(lang("ghost_e_mark"))
2022-06-30 07:16:06 +00:00
sqlite[f"denied.chat_id.{str(message.chat.id)}"] = True
2022-06-20 13:55:14 +00:00
await message.safe_delete()
2022-06-30 07:16:06 +00:00
await log(f"ChatID {str(message.chat.id)} {lang('deny_set')}")
2022-06-20 13:55:14 +00:00
elif message.parameter[0] == "false":
2022-06-30 07:16:06 +00:00
if message.chat.id == self_user_id:
2023-03-12 03:56:01 +00:00
await message.edit(lang("ghost_e_mark"))
2022-06-20 13:55:14 +00:00
return
try:
2022-06-30 07:16:06 +00:00
del sqlite[f"denied.chat_id.{str(message.chat.id)}"]
2022-06-20 13:55:14 +00:00
except KeyError:
2023-03-12 03:56:01 +00:00
return await message.edit(lang("deny_e_noexist"))
2022-06-20 13:55:14 +00:00
await message.safe_delete()
2022-06-30 07:16:06 +00:00
await log(f"ChatID {str(message.chat.id)} {lang('deny_cancel')}")
2022-06-20 13:55:14 +00:00
elif message.parameter[0] == "status":
2022-06-30 07:16:06 +00:00
if sqlite.get(f"denied.chat_id.{str(message.chat.id)}", None):
2023-03-12 03:56:01 +00:00
await message.edit(lang("deny_e_exist"))
2022-06-20 13:55:14 +00:00
else:
2023-03-12 03:56:01 +00:00
await message.edit(lang("deny_e_noexist"))
2022-06-20 13:55:14 +00:00
else:
await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
@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()