From 90eb51f5db539541396cfd95bced07274563b7d7 Mon Sep 17 00:00:00 2001 From: Pentacene Date: Sun, 21 Mar 2021 15:25:26 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=9B=9E=E5=A4=8DSticker?= =?UTF-8?q?=20v1.0.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- autoreplysticker.py | 181 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 autoreplysticker.py diff --git a/autoreplysticker.py b/autoreplysticker.py new file mode 100644 index 0000000..f2f2044 --- /dev/null +++ b/autoreplysticker.py @@ -0,0 +1,181 @@ +""" Pagermaid Plugins AutoReplySticker """ +# ______ _ +# | ___ \ | | +# | |_/ /__ _ __ | |_ __ _ ___ ___ _ __ ___ +# | __/ _ \ '_ \| __/ _` |/ __/ _ \ '_ \ / _ \ +# | | | __/ | | | || (_| | (_| __/ | | | __/ +# \_| \___|_| |_|\__\__,_|\___\___|_| |_|\___| +# + +from os import mkdir +from os.path import exists +from asyncio import sleep +from random import randint +import yaml +from telethon.tl.functions.messages import GetAllStickersRequest +from telethon.tl.functions.messages import GetStickerSetRequest +from telethon.tl.types import InputStickerSetID +from pagermaid import log +from pagermaid.listener import listener + +async def ars_check(context): + try: + config = yaml.load(open(r"./plugins/autoreplysticker/config.yml"), Loader=yaml.FullLoader) + except FileNotFoundError: + await context.edit("自动回复贴纸的相关设置不存在。\n请使用 `-ars help` 查看设置方法") + return + _sticker_id = config['sticker_id'] + _sticker_hash = config['sticker_hash'] + _num = config['num'] + _time = config['time'] + _noti = await context.reply( + '您当前的设置为:\n' + f'sticker_id: {_sticker_id}\n' + f'sticker_hash: {_sticker_hash}\n' + f'time: {_time}\n' + f'num: {_num}') + await context.delete() + await sleep(15) + await _noti.delete() + +async def ars_getall(context): + sticker_sets = await context.client(GetAllStickersRequest(0)) + sticker_pack_list = [] + for sticker_set in sticker_sets.sets: + if len(sticker_pack_list) < 10: + text = "我发现了一个Sticker Pack,名为\n" + sticker_set.title + "\n" + "ID为: `" + \ + str(sticker_set.id) + "` \n" + "Hash为: `" + str(sticker_set.access_hash) + \ + "` \n" + "共有" + str(sticker_set.count) + "张" + sticker_pack_list.extend([text]) + else: + sticker_pack_list_old = sticker_pack_list + send_text = '\n\n'.join(sticker_pack_list_old) + await context.client.send_message(context.chat_id, send_text) + sticker_pack_list = [] + await sleep(2) + sendtext = '\n\n'.join(sticker_pack_list) + await context.client.send_message(context.chat_id, sendtext) + await context.delete() + +async def ars_help(context): + await context.reply('111') + await context.delete() + +def set_state(name, state): + file_name = "./plugins/autoreplysticker/config.yml" + if exists(file_name): + with open(file_name) as f: + doc = yaml.safe_load(f) + doc[name] = state + with open(file_name, 'w') as f: + yaml.safe_dump(doc, f, default_flow_style=False) + else: + dc = {name: state} + with open(file_name, 'w', encoding='utf-8') as f: + yaml.dump(dc, f) + +def get_name(sender): + """ + get_name(Message.sender) + """ + username = sender.username + first_name = sender.first_name + last_name = sender.last_name + _id = sender.id + if username == None: + if last_name == None: + name = f'[{first_name}](tg://user?id={_id})' + else: + name = f'[{first_name}{last_name}](tg://user?id={_id})' + else: + name = f'@{username}' + return name + +def process_link(chatid, msgid): + """ + process_link(chat_id, message_id) + return https://t.me/c/chat_id/message_id + """ + if chatid < 0: + if chatid < -1000000000000: + chatid *= -1 + chatid -= 1000000000000 + else: + chatid *= -1 + link = f'https://t.me/c/{chatid}/{msgid}' + return link + +@listener(is_plugin=True, outgoing=True, command="ars") +async def ars(context): + if not exists('./plugins/autoreplysticker'): + mkdir('./plugins/autoreplysticker') + + if context.parameter[0] == 'set': + if len(context.parameter) < 5: + await context.reply('请正确输入 `-ars set`