antichannelpin 自动取消关联频道消息置顶

This commit is contained in:
xtaodada 2021-08-06 22:04:06 +08:00
parent cecb75dc90
commit ce96c3a1fb
No known key found for this signature in database
GPG Key ID: EE4DC37B55E24736
2 changed files with 87 additions and 0 deletions

67
antichannelpin.py Normal file
View File

@ -0,0 +1,67 @@
""" PagerMaid module to anti channel pin. """
from telethon.errors import ChatAdminRequiredError
from telethon.tl.types import Channel
from asyncio import sleep
from pagermaid import redis, log, redis_status
from pagermaid.utils import lang, alias_command
from pagermaid.listener import listener
@listener(is_plugin=False, outgoing=True, command=alias_command('antichannelpin'),
description='开启对话的自动取消频道置顶功能,需要 Redis',
parameters="<true|false|status>")
async def antichannelpin(context):
if not redis_status():
await context.edit(f"{lang('error_prefix')}{lang('redis_dis')}")
return
if len(context.parameter) != 1:
await context.edit(f"{lang('error_prefix')}{lang('arg_error')}")
return
myself = await context.client.get_me()
self_user_id = myself.id
if context.parameter[0] == "true":
if context.chat_id == self_user_id:
await context.edit(lang('ghost_e_mark'))
return
redis.set("antichannelpin." + str(context.chat_id), "true")
await context.edit(f"已成功开启群组 {str(context.chat_id)} 的自动取消频道置顶功能。")
await log(f"已成功开启群组 {str(context.chat_id)} 的自动取消频道置顶功能。")
elif context.parameter[0] == "false":
if context.chat_id == self_user_id:
await context.edit(lang('ghost_e_mark'))
return
try:
redis.delete("antichannelpin." + str(context.chat_id))
except:
await context.edit('emm...当前对话不存在于自动取消频道置顶功能列表中。')
return
await context.edit(f"已成功关闭群组 {str(context.chat_id)} 的自动取消频道置顶功能。")
await log(f"已成功关闭群组 {str(context.chat_id)} 的自动取消频道置顶功能。")
elif context.parameter[0] == "status":
if redis.get("antichannelpin." + str(context.chat_id)):
await context.edit('当前对话存在于自动取消频道置顶功能列表中。')
else:
await context.edit('当前对话不存在于自动取消频道置顶功能列表中。')
else:
await context.edit(f"{lang('error_prefix')}{lang('arg_error')}")
@listener(is_plugin=False, incoming=True, ignore_edited=True)
async def unpin_link_channel_message(context):
""" Event handler to unpin linked channel messages. """
if not redis_status():
return
if not redis.get("antichannelpin." + str(context.chat_id)):
return
try:
if not isinstance(context.sender, Channel):
return
except:
return
await sleep(1)
try:
await context.unpin()
except ChatAdminRequiredError:
redis.delete("antichannelpin." + str(context.chat_id))
except:
pass

View File

@ -709,6 +709,26 @@
"supported": true, "supported": true,
"des-short": "将回复的消息转换成语录图片", "des-short": "将回复的消息转换成语录图片",
"des": "将回复的消息转换成语录图片。\n指令-yvlu" "des": "将回复的消息转换成语录图片。\n指令-yvlu"
},
{
"name": "antichannelpin",
"version": "1.0",
"section": "chat",
"maintainer": "xtaodada",
"size": "2.8 kb",
"supported": true,
"des-short": "自动取消关联频道消息置顶",
"des": "自动取消关联频道消息置顶。\n指令-antichannelpin"
},
{
"name": "shift",
"version": "1.0",
"section": "daily",
"maintainer": "xtaodada",
"size": "5.3 kb",
"supported": true,
"des-short": "自动转发/备份频道消息",
"des": "自动转发频道新消息或者从零开始备份频道。\n指令-shift\n查看帮助-help shift"
} }
] ]
} }