From 467e049d543cb0e259e717aa16ab39a99e1f7f51 Mon Sep 17 00:00:00 2001 From: Pentacene Date: Wed, 31 Mar 2021 01:34:57 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=97=A0log=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- autoreplysticker.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/autoreplysticker.py b/autoreplysticker.py index 7f494c6..cf7b98a 100644 --- a/autoreplysticker.py +++ b/autoreplysticker.py @@ -180,9 +180,6 @@ async def process_message(context): reply_to=context.id) await sleep(_time) await sticker.delete() - if context.chat_id < 0: - await log( - f'#被回复\n在 [{context.chat.title}]({process_link(context.chat_id, context.id)})\n' - f'获得了 {get_name(context.sender)} 的回复') + await log(f'#被回复\n在 [{context.chat.title}]({process_link(context.chat_id, context.id)})\n获得了 {get_name(context.sender)} 的回复') except: pass From 63fa830fda6ad286e0c4eeca9fbfb0c481bf31f7 Mon Sep 17 00:00:00 2001 From: Pentacene Date: Wed, 31 Mar 2021 01:35:46 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=97=A0log=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/list.json b/list.json index f642bbc..83a3a81 100644 --- a/list.json +++ b/list.json @@ -362,7 +362,7 @@ }, { "name": "autoreplysticker", - "version": "1.02", + "version": "1.03", "section": "chat", "maintainer": "Pentacene", "size": "6.8 kb", From 49922bc8647888abeeecbe129074d5ff5c190387 Mon Sep 17 00:00:00 2001 From: Pentacene Date: Fri, 2 Apr 2021 11:56:39 +0800 Subject: [PATCH 3/6] =?UTF-8?q?AutoReplySticker=20v1.10=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=BE=A4=E7=BB=84=E7=99=BD=E5=90=8D=E5=8D=95=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- autoreplysticker.py | 74 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 16 deletions(-) diff --git a/autoreplysticker.py b/autoreplysticker.py index cf7b98a..0d41a24 100644 --- a/autoreplysticker.py +++ b/autoreplysticker.py @@ -12,34 +12,39 @@ from os.path import exists from asyncio import sleep from random import randint import yaml +from telethon.tl.custom.message import Message 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): +async def ars_check(message: Message) -> None: try: config = yaml.load(open(r"./plugins/autoreplysticker/config.yml"), Loader=yaml.FullLoader) except FileNotFoundError: - await context.edit("自动回复贴纸的相关设置不存在。\n请使用 `-ars help` 查看设置方法") + await message.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( + _white = config['whitelist'] + _noti = await message.reply( '您当前的设置为:\n' f'sticker_id: {_sticker_id}\n' f'sticker_hash: {_sticker_hash}\n' f'time: {_time}\n' - f'num: {_num}') - await context.delete() + f'num: {_num}\n' + f'白名单群组id: {_white}\n' + '\n' + '本消息15秒后自动删除') + await message.delete() await sleep(15) await _noti.delete() -async def ars_getall(context): - sticker_sets = await context.client(GetAllStickersRequest(0)) +async def ars_getall(message: Message) -> None: + sticker_sets = await message.client(GetAllStickersRequest(0)) sticker_pack_list = [] for sticker_set in sticker_sets.sets: if len(sticker_pack_list) < 10: @@ -50,25 +55,51 @@ async def ars_getall(context): 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) + await message.client.send_message(message.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() + await message.client.send_message(message.chat_id, sendtext) + await message.delete() -async def ars_help(context): - await context.reply( +async def ars_help(message: Message) -> None: + await message.reply( '欢迎使用自动回复贴纸\n' '设置方法为\n' '先使用 `-ars getall` 获取贴纸包的id和hash\n' '之后使用 `-ars set` 贴纸包id 贴纸包hash 自动删除时间 第i张贴纸 第j张贴纸 ...\n' '比如 `-ars set 000 001 10 0 1 2 3` 的意义为\n' '设置贴纸包id为000, hash为001, 自动回复10秒后删除, 随机从第0, 1, 2, 3张贴纸中选择一张自动回复\n\n' + '如果您想要在某个群内设置自动回复白名单,请在该群中回复`-ars w`' '如有使用问题,请前往 [这里](https://t.me/PagerMaid_Modify) 请求帮助') - await context.delete() + await message.delete() -def set_state(name, state): +async def ars_whitelist(message: Message) -> None: + chat_id = str(message.chat_id) + try: + config = yaml.load(open(r"./plugins/autoreplysticker/config.yml"), Loader=yaml.FullLoader) + except FileNotFoundError: + await message.edit("自动回复贴纸的相关设置不存在。\n请使用 `-ars help` 查看设置方法") + return + try: + _white = config['whitelist'] + except: + white_list = ['0'] + set_state('whitelist', white_list) + _white = config['whitelist'] + + _white.append(chat_id) + try: + _white.remove('0') + except: + pass + _white = list(set(_white)) + set_state('whitelist', _white) + _noti = await message.edit('OK') + await sleep(5) + await _noti.delete() + +def set_state(name: str, state: list) -> None: file_name = "./plugins/autoreplysticker/config.yml" if exists(file_name): with open(file_name) as f: @@ -81,7 +112,7 @@ def set_state(name, state): with open(file_name, 'w', encoding='utf-8') as f: yaml.dump(dc, f) -def get_name(sender): +def get_name(sender: Message.sender) -> str: """ get_name(Message.sender) """ @@ -98,7 +129,7 @@ def get_name(sender): name = f'@{username}' return name -def process_link(chatid, msgid): +def process_link(chatid: int, msgid: int) -> str: """ process_link(chat_id, message_id) return https://t.me/c/chat_id/message_id @@ -116,6 +147,9 @@ def process_link(chatid, msgid): async def ars(context): if not exists('./plugins/autoreplysticker'): mkdir('./plugins/autoreplysticker') + + if len(context.parameter) == 0: + await ars_help(context) if context.parameter[0] == 'set': if len(context.parameter) < 5: @@ -130,6 +164,8 @@ async def ars(context): for i in range(4, len(context.parameter)): num_list.append(context.parameter[i]) set_state('num', num_list) + white_list = ['0'] + set_state('whitelist', white_list) except: await context.reply('设置失败,请手动设置`./plugins/autoreplysticker/config.yml`') return @@ -144,6 +180,8 @@ async def ars(context): await ars_getall(context) elif context.parameter[0] == 'help': await ars_help(context) + elif context.parameter[0] == 'w': + await ars_whitelist(context) @listener(incoming=True, ignore_edited=True) async def process_message(context): @@ -164,9 +202,13 @@ async def process_message(context): _sticker_hash = int(config['sticker_hash']) _num = config['num'] _time = int(config['time']) + _whitelist = config['whitelist'] except: return + if str(context.chat_id) in _whitelist: + return + if (reply and reply_user_id == me.id): stickers = await context.client( GetStickerSetRequest( From 4d918f94106ba9360b5be4f62670c38d897bd513 Mon Sep 17 00:00:00 2001 From: Pentacene Date: Fri, 2 Apr 2021 11:57:17 +0800 Subject: [PATCH 4/6] =?UTF-8?q?AutoReplySticker=20v1.10=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=BE=A4=E7=BB=84=E7=99=BD=E5=90=8D=E5=8D=95=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/list.json b/list.json index 83a3a81..bc59d67 100644 --- a/list.json +++ b/list.json @@ -362,10 +362,10 @@ }, { "name": "autoreplysticker", - "version": "1.03", + "version": "1.10", "section": "chat", "maintainer": "Pentacene", - "size": "6.8 kb", + "size": "8.3 kb", "supported": true, "des-short": "自动回复sticker", "des": "-ars" From 0c43a7e92f322f094af1a7475a28fea46d64adc9 Mon Sep 17 00:00:00 2001 From: Pentacene Date: Tue, 6 Apr 2021 11:17:18 +0800 Subject: [PATCH 5/6] Update autoreplysticker.py --- autoreplysticker.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/autoreplysticker.py b/autoreplysticker.py index 0d41a24..9ab1d9f 100644 --- a/autoreplysticker.py +++ b/autoreplysticker.py @@ -193,6 +193,8 @@ async def process_message(context): reply_user_id = reply.sender.id if context.sticker: return + if context.chat_id > 0: + return except: pass From c285aae1b014ec1196c4aa5b5b6b3e41edb0a406 Mon Sep 17 00:00:00 2001 From: Pentacene Date: Tue, 6 Apr 2021 11:17:51 +0800 Subject: [PATCH 6/6] Update list.json --- list.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/list.json b/list.json index bc59d67..ff0695b 100644 --- a/list.json +++ b/list.json @@ -362,7 +362,7 @@ }, { "name": "autoreplysticker", - "version": "1.10", + "version": "1.11", "section": "chat", "maintainer": "Pentacene", "size": "8.3 kb",