2020-02-19 15:31:39 +00:00
|
|
|
""" PagerMaid module for different ways to avoid users. """
|
|
|
|
|
|
|
|
from pagermaid import redis, log, redis_status
|
2021-06-15 04:31:05 +00:00
|
|
|
from pagermaid.utils import lang, alias_command
|
2020-02-19 15:31:39 +00:00
|
|
|
from pagermaid.listener import listener
|
|
|
|
|
|
|
|
|
2021-06-15 04:31:05 +00:00
|
|
|
@listener(is_plugin=False, outgoing=True, command=alias_command('ghost'),
|
2021-04-12 16:25:32 +00:00
|
|
|
description=lang('ghost_des'),
|
2020-02-19 15:31:39 +00:00
|
|
|
parameters="<true|false|status>")
|
|
|
|
async def ghost(context):
|
|
|
|
""" Toggles ghosting of a user. """
|
|
|
|
if not redis_status():
|
2021-04-12 16:25:32 +00:00
|
|
|
await context.edit(f"{lang('error_prefix')}{lang('redis_dis')}")
|
2020-02-19 15:31:39 +00:00
|
|
|
return
|
|
|
|
if len(context.parameter) != 1:
|
2021-04-12 16:25:32 +00:00
|
|
|
await context.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
2020-02-19 15:31:39 +00:00
|
|
|
return
|
|
|
|
myself = await context.client.get_me()
|
|
|
|
self_user_id = myself.id
|
|
|
|
if context.parameter[0] == "true":
|
|
|
|
if context.chat_id == self_user_id:
|
2021-04-12 16:25:32 +00:00
|
|
|
await context.edit(lang('ghost_e_mark'))
|
2020-02-19 15:31:39 +00:00
|
|
|
return
|
|
|
|
redis.set("ghosted.chat_id." + str(context.chat_id), "true")
|
|
|
|
await context.delete()
|
2021-04-12 16:25:32 +00:00
|
|
|
await log(f"{lang('ghost_set_f')} ChatID {str(context.chat_id)} {lang('ghost_set_l')}")
|
2020-02-19 15:31:39 +00:00
|
|
|
elif context.parameter[0] == "false":
|
|
|
|
if context.chat_id == self_user_id:
|
2021-04-12 16:25:32 +00:00
|
|
|
await context.edit(lang('ghost_e_mark'))
|
2020-02-19 15:31:39 +00:00
|
|
|
return
|
2020-04-30 11:38:40 +00:00
|
|
|
try:
|
|
|
|
redis.delete("ghosted.chat_id." + str(context.chat_id))
|
|
|
|
except:
|
2021-04-12 16:25:32 +00:00
|
|
|
await context.edit(lang('ghost_e_noexist'))
|
2020-04-30 11:38:40 +00:00
|
|
|
return
|
2020-02-19 15:31:39 +00:00
|
|
|
await context.delete()
|
2021-04-12 16:25:32 +00:00
|
|
|
await log(f"{lang('ghost_set_f')} ChatID {str(context.chat_id)} {lang('ghost_cancel')}")
|
2020-02-19 15:31:39 +00:00
|
|
|
elif context.parameter[0] == "status":
|
|
|
|
if redis.get("ghosted.chat_id." + str(context.chat_id)):
|
2021-04-12 16:25:32 +00:00
|
|
|
await context.edit(lang('ghost_e_exist'))
|
2020-02-19 15:31:39 +00:00
|
|
|
else:
|
2021-04-12 16:25:32 +00:00
|
|
|
await context.edit(lang('ghost_e_noexist'))
|
2020-02-19 15:31:39 +00:00
|
|
|
else:
|
2021-04-12 16:25:32 +00:00
|
|
|
await context.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
2020-02-19 15:31:39 +00:00
|
|
|
|
|
|
|
|
2021-06-15 04:31:05 +00:00
|
|
|
@listener(is_plugin=False, outgoing=True, command=alias_command('deny'),
|
2021-04-12 16:25:32 +00:00
|
|
|
description=lang('deny_des'),
|
2020-02-19 15:31:39 +00:00
|
|
|
parameters="<true|false|status>")
|
|
|
|
async def deny(context):
|
|
|
|
""" Toggles denying of a user. """
|
|
|
|
if not redis_status():
|
2021-04-12 16:25:32 +00:00
|
|
|
await context.edit(f"{lang('error_prefix')}{lang('redis_dis')}")
|
2020-02-19 15:31:39 +00:00
|
|
|
return
|
|
|
|
if len(context.parameter) != 1:
|
2021-04-12 16:25:32 +00:00
|
|
|
await context.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
2020-02-19 15:31:39 +00:00
|
|
|
return
|
|
|
|
myself = await context.client.get_me()
|
|
|
|
self_user_id = myself.id
|
|
|
|
if context.parameter[0] == "true":
|
|
|
|
if context.chat_id == self_user_id:
|
2021-04-12 16:25:32 +00:00
|
|
|
await context.edit(lang('ghost_e_mark'))
|
2020-02-19 15:31:39 +00:00
|
|
|
return
|
|
|
|
redis.set("denied.chat_id." + str(context.chat_id), "true")
|
|
|
|
await context.delete()
|
2021-04-12 16:25:32 +00:00
|
|
|
await log(f"ChatID {str(context.chat_id)} {lang('deny_set')}")
|
2020-02-19 15:31:39 +00:00
|
|
|
elif context.parameter[0] == "false":
|
|
|
|
if context.chat_id == self_user_id:
|
2021-04-12 16:25:32 +00:00
|
|
|
await context.edit(lang('ghost_e_mark'))
|
2020-02-19 15:31:39 +00:00
|
|
|
return
|
|
|
|
redis.delete("denied.chat_id." + str(context.chat_id))
|
|
|
|
await context.delete()
|
2021-04-12 16:25:32 +00:00
|
|
|
await log(f"ChatID {str(context.chat_id)} {lang('deny_cancel')}")
|
2020-02-19 15:31:39 +00:00
|
|
|
elif context.parameter[0] == "status":
|
|
|
|
if redis.get("denied.chat_id." + str(context.chat_id)):
|
2021-04-12 16:25:32 +00:00
|
|
|
await context.edit(lang('deny_e_exist'))
|
2020-02-19 15:31:39 +00:00
|
|
|
else:
|
2021-04-12 16:25:32 +00:00
|
|
|
await context.edit(lang('deny_e_noexist'))
|
2020-02-19 15:31:39 +00:00
|
|
|
else:
|
2021-04-12 16:25:32 +00:00
|
|
|
await context.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
2020-02-19 15:31:39 +00:00
|
|
|
|
|
|
|
|
2020-08-09 15:17:55 +00:00
|
|
|
@listener(is_plugin=False, incoming=True, ignore_edited=True)
|
2020-02-19 15:31:39 +00:00
|
|
|
async def set_read_acknowledgement(context):
|
|
|
|
""" Event handler to infinitely read ghosted messages. """
|
|
|
|
if not redis_status():
|
|
|
|
return
|
|
|
|
if redis.get("ghosted.chat_id." + str(context.chat_id)):
|
|
|
|
await context.client.send_read_acknowledge(context.chat_id)
|
|
|
|
|
|
|
|
|
2020-08-09 15:17:55 +00:00
|
|
|
@listener(is_plugin=False, incoming=True, ignore_edited=True)
|
2020-02-19 15:31:39 +00:00
|
|
|
async def message_removal(context):
|
|
|
|
""" Event handler to infinitely delete denied messages. """
|
|
|
|
if not redis_status():
|
|
|
|
return
|
|
|
|
if redis.get("denied.chat_id." + str(context.chat_id)):
|
|
|
|
await context.delete()
|