From e74f374d1cc109627527b8fbeda98b1fb9f1e0f4 Mon Sep 17 00:00:00 2001 From: Xtao_dada Date: Sat, 28 Nov 2020 19:28:00 +0800 Subject: [PATCH 01/91] =?UTF-8?q?=F0=9F=93=A6=20whois=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=80=BB=E8=BE=91=20,=20=E4=BF=AE=E6=94=B9=E6=8E=AA=E8=BE=9E?= =?UTF-8?q?=20(#81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 📦 whois 优化逻辑 , 修改措辞 * Update list.json --- list.json | 2 +- whois.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/list.json b/list.json index 5f28fad..ca51184 100644 --- a/list.json +++ b/list.json @@ -192,7 +192,7 @@ }, { "name": "whois", - "version": "1.1", + "version": "1.11", "section": "daily", "maintainer": "KorenKrita", "size": "1.1 kb", diff --git a/whois.py b/whois.py index 2a75b35..f55786c 100644 --- a/whois.py +++ b/whois.py @@ -16,8 +16,8 @@ async def whois(context): return req = get("https://tenapi.cn/whois/?url=" + message) if req.status_code == 200: - data = json.loads(req.text) - res = '网址: ' + data['data']['url'] + '\n注册商: ' + str(data['data']['registrar']) + '\n联系人: ' + str(data['data']['registrant']) + '\n联系邮箱: ' + str(data['data']['mail']) + '\n注册时间: ' + str(data['data']['registration']) + '\n过期时间: ' + str(data['data']['expiration']) + '\nDNS: ' + str(data['data']['dns']) + data = json.loads(req.text)['data'] + res = '域名: `' + data['url'] + '`\n注册商: `' + str(data['registrar']) + '`\n联系人: `' + str(data['registrant']) + '`\n联系邮箱: `' + str(data['mail']) + '`\n注册时间: `' + str(data['registration']) + '`\n过期时间: `' + str(data['expiration']) + '`\nDNS: ' + str(data['dns']).replace('
', '\n') await context.edit(res) else: await context.edit("出错了呜呜呜 ~ 无法访问到 API 服务器 。") From 6f915679099fb9adfe0dce7b3aff85c585aa75d9 Mon Sep 17 00:00:00 2001 From: Xtao_dada Date: Sat, 28 Nov 2020 22:48:42 +0800 Subject: [PATCH 02/91] =?UTF-8?q?=F0=9F=90=9B=20xtao-some=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=20wiki=20=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xtao-some.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/xtao-some.py b/xtao-some.py index a8c6f71..1372591 100644 --- a/xtao-some.py +++ b/xtao-some.py @@ -1,6 +1,6 @@ """ Pagermaid plugin base. """ import json, requests, re -from googletrans import Translator +from translate import Translator as trans from urllib.parse import urlparse from pagermaid import bot, log from pagermaid.listener import listener, config @@ -59,8 +59,7 @@ async def admin(context): description="查询维基百科词条", parameters="<词组>") async def wiki(context): - translator = Translator() - lang = config['application_language'] + lang = config['application_language'].replace('zh-cn', 'zh') await context.edit("获取中 . . .") try: message = await obtain_message(context) @@ -79,7 +78,7 @@ async def wiki(context): wiki_time = wiki_json['query']['search'][0]['timestamp'].replace('T', ' ').replace('Z', ' ') try: await context.edit("正在生成翻译中 . . .") - wiki_content = translator.translate(clear_emojis(wiki_content), dest=lang) + wiki_content = trans(to_lang=lang).translate(clear_emojis(wiki_content)) message = '词条: [' + wiki_title + '](https://zh.wikipedia.org/zh-cn/' + wiki_title + ')\n\n' + wiki_content.text + '...\n\n此词条最后修订于 ' + wiki_time except ValueError: await context.edit("出错了呜呜呜 ~ 找不到目标语言,请更正配置文件中的错误。") From d52a7c93241ab74dc3c3556cc44e23a1ac25477b Mon Sep 17 00:00:00 2001 From: Xtao_dada Date: Sat, 28 Nov 2020 22:59:12 +0800 Subject: [PATCH 03/91] =?UTF-8?q?=F0=9F=90=9B=20xtao-some=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=20wiki=20=E6=97=A0=E6=B3=95=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xtao-some.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xtao-some.py b/xtao-some.py index 1372591..6168fb7 100644 --- a/xtao-some.py +++ b/xtao-some.py @@ -79,7 +79,7 @@ async def wiki(context): try: await context.edit("正在生成翻译中 . . .") wiki_content = trans(to_lang=lang).translate(clear_emojis(wiki_content)) - message = '词条: [' + wiki_title + '](https://zh.wikipedia.org/zh-cn/' + wiki_title + ')\n\n' + wiki_content.text + '...\n\n此词条最后修订于 ' + wiki_time + message = '词条: [' + wiki_title + '](https://zh.wikipedia.org/zh-cn/' + wiki_title + ')\n\n' + wiki_content + '...\n\n此词条最后修订于 ' + wiki_time except ValueError: await context.edit("出错了呜呜呜 ~ 找不到目标语言,请更正配置文件中的错误。") return From 9d7ba664d180164cda591099d56b4b5be1ddf594 Mon Sep 17 00:00:00 2001 From: Xtao_dada Date: Sat, 28 Nov 2020 23:07:56 +0800 Subject: [PATCH 04/91] =?UTF-8?q?=F0=9F=90=9B=20xtao-some=20wiki=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E8=85=BE=E8=AE=AF=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xtao-some.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xtao-some.py b/xtao-some.py index 6168fb7..60660c6 100644 --- a/xtao-some.py +++ b/xtao-some.py @@ -78,7 +78,9 @@ async def wiki(context): wiki_time = wiki_json['query']['search'][0]['timestamp'].replace('T', ' ').replace('Z', ' ') try: await context.edit("正在生成翻译中 . . .") - wiki_content = trans(to_lang=lang).translate(clear_emojis(wiki_content)) + USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:65.0) Gecko/20100101 Firefox/65.0" + headers = {"user-agent": USER_AGENT} + wiki_content = json.loads(requests.get("https://xtaolink.cn/git/m/t.php?lang=" + lang + '&text=' + clear_emojis(wiki_content), headers=headers).content.decode("utf-8"))['data']['target_text'] message = '词条: [' + wiki_title + '](https://zh.wikipedia.org/zh-cn/' + wiki_title + ')\n\n' + wiki_content + '...\n\n此词条最后修订于 ' + wiki_time except ValueError: await context.edit("出错了呜呜呜 ~ 找不到目标语言,请更正配置文件中的错误。") From 7572c8aa28099d68b57d368f832bff6110ed9456 Mon Sep 17 00:00:00 2001 From: AAA <35992542+TNTcraftHIM@users.noreply.github.com> Date: Mon, 30 Nov 2020 14:22:36 +0800 Subject: [PATCH 05/91] =?UTF-8?q?meizi=E6=8F=92=E4=BB=B6=E5=A4=A7=E5=B9=85?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9B=BE=E6=BA=90=20(#83)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: TNTcraftHIM --- list.json | 2 +- meizi.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/list.json b/list.json index 4ed4d17..16ddb27 100644 --- a/list.json +++ b/list.json @@ -222,7 +222,7 @@ }, { "name": "meizi", - "version": "1.7", + "version": "1.8", "section": "daily", "maintainer": "TNTcraftHIM", "size": "4.0 kb", diff --git a/meizi.py b/meizi.py index 5d6a66e..16417ea 100644 --- a/meizi.py +++ b/meizi.py @@ -21,25 +21,25 @@ async def mz(context): elif website == 2: img = get("https://api.66mz8.com/api/rand.tbimg.php") elif website == 3: - img = get("https://api.isoyu.com/mm_images.php") + img = get("https://api.nmb.show/xiaojiejie2.php") elif website == 4: img = get("https://uploadbeta.com/api/pictures/random/?key=%E5%A5%B3") elif website == 5: - img = get("https://uploadbeta.com/api/pictures/random/?key=%E5%A6%B9%E5%AD%90") + img = get("https://uploadbeta.com/api/pictures/random/?key=%E5%86%85%E8%A1%A3") elif website == 6: img = get("https://uploadbeta.com/api/pictures/random/?key=%E6%8E%A8%E5%A5%B3%E9%83%8E") elif website == 7: - img = get("https://uploadbeta.com/api/pictures/random/?key=%E7%BE%8E%E5%A5%B3") + img = get("https://tvv.tw/xjj/meinv/img-ct.php") elif website == 8: img = get("https://api.diskgirl.com/image/api.php?t=xinggan&v=" + str(random.uniform(0, 100))) elif website == 9: img = get("https://api.lyiqk.cn/sexylady") elif website == 10: - img = get("https://api.pingping6.com/tools/acg3/index.php") + img = get("https://tvv.tw/xjj/meinv/img.php") elif website == 11: img = get("https://api.uomg.com/api/rand.img3") elif website == 12: - img = get("https://api.diskgirl.com/image/api.php?t=&v=0.9451485087333713") + img = get("https://api.nmb.show/xiaojiejie1.php") elif website == 13: img = get("https://uploadbeta.com/api/pictures/random/?key=%E6%80%A7%E6%84%9F") if img.status_code == 200: From 5ecfa90475309ca25e174e311998c0154e2c62c7 Mon Sep 17 00:00:00 2001 From: AAA <35992542+TNTcraftHIM@users.noreply.github.com> Date: Mon, 30 Nov 2020 14:47:34 +0800 Subject: [PATCH 06/91] =?UTF-8?q?aff=E6=8F=92=E4=BB=B6=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=9C=BA=E5=9E=8B=E7=BC=96=E7=A0=81=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E9=97=AE=E9=A2=98=20(#84)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: TNTcraftHIM --- aff.py | 4 ++-- list.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/aff.py b/aff.py index dc72fc0..055cade 100644 --- a/aff.py +++ b/aff.py @@ -10,7 +10,7 @@ from pagermaid.listener import listener async def aff(context): if not context.parameter: #发送aff信息 try: - with open("plugins/AffExtra/aff.txt", "r") as f: + with open("plugins/AffExtra/aff.txt", "r", encoding="UTF-8") as f: msg = f.read() except: msg = "" @@ -31,7 +31,7 @@ async def aff(context): msg = reply.message if not exists("plugins/AffExtra"): mkdir("plugins/AffExtra") - with open("plugins/AffExtra/aff.txt", "w") as f: + with open("plugins/AffExtra/aff.txt", "w", encoding="UTF-8") as f: f.write(msg) await context.edit("好耶 ! Aff信息保存成功。") sleep(3) diff --git a/list.json b/list.json index 16ddb27..cd9a2d8 100644 --- a/list.json +++ b/list.json @@ -312,7 +312,7 @@ }, { "name": "aff", - "version": "1.1", + "version": "1.2", "section": "chat", "maintainer": "TNTcraftHIM", "size": "2.0 kb", From 4334747710cbe28a024e759b55c5404acfa5e6ea Mon Sep 17 00:00:00 2001 From: Xtao_dada Date: Sat, 16 Jan 2021 21:13:21 +0800 Subject: [PATCH 07/91] Update vip.py --- vip.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/vip.py b/vip.py index 51c76ef..0137a8e 100644 --- a/vip.py +++ b/vip.py @@ -1,3 +1,5 @@ +from requests import get +from os import remove from pagermaid import bot from pagermaid.listener import listener from pagermaid.utils import obtain_message @@ -18,3 +20,40 @@ async def weather(context): await bot.send_read_acknowledge(conversation.chat_id) weather_text = chat_response.text await context.edit(weather_text) + + +@listener(is_plugin=True, outgoing=True, command="pixiv", + description="查询插画信息 (或者回复一条消息)", + parameters="[<图片链接>] <图片序号>") +async def pixiv(context): + await context.edit("获取中 . . .") + try: + message = await obtain_message(context) + except ValueError: + await context.edit("出错了呜呜呜 ~ 无效的参数。") + return + async with bot.conversation('PagerMaid_Modify_bot') as conversation: + await conversation.send_message('/pixiv_api ' + message) + chat_response = await conversation.get_response() + await bot.send_read_acknowledge(conversation.chat_id) + pixiv_text = chat_response.text + pixiv_list = pixiv_text.split('|||||') + if len(pixiv_list) == 2: + pixiv_albums = pixiv_list[1].split('|||') + pixiv_album = [] + await context.edit("下载图片中 . . .") + for i in range(0, len(pixiv_albums) - 1): + r = get(pixiv_albums[i]) + with open("pixiv." + str(i) + ".jpg", "wb") as code: + code.write(r.content) + pixiv_album.extend(["pixiv." + str(i) + ".jpg"]) + await context.client.send_file(context.chat_id, pixiv_album, + caption=pixiv_list[0]) + await context.delete() + for i in pixiv_album: + try: + remove(i) + except: + pass + else: + await context.edit(pixiv_text) From 4ec5cd7f7fdf9f73702d198f6a6650f75962633c Mon Sep 17 00:00:00 2001 From: Xtao_dada Date: Sat, 16 Jan 2021 21:16:12 +0800 Subject: [PATCH 08/91] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20pixiv=20=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E4=BD=BF=E7=94=A8=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= =?UTF-8?q?(#92)=20fixed=20#91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update xtao-some.py * Update list.json --- list.json | 8 ++-- xtao-some.py | 120 --------------------------------------------------- 2 files changed, 4 insertions(+), 124 deletions(-) diff --git a/list.json b/list.json index 43ea7e8..f2d7f65 100644 --- a/list.json +++ b/list.json @@ -62,13 +62,13 @@ }, { "name": "xtao-some", - "version": "1.11", + "version": "1.12", "section": "daily", "maintainer": "xtaodada", "size": "18.8 kb", "supported": true, "des-short": "一大堆便民功能。", - "des": "超多功能 例如 -ip -pixiv -guess 等。" + "des": "超多功能 例如 -ip -ipping -guess 等。" }, { "name": "yb-dl", @@ -332,13 +332,13 @@ }, { "name": "vip", - "version": "0.1", + "version": "0.2", "section": "chat", "maintainer": "xtaodada", "size": "4.0 kb", "supported": true, "des-short": "vip 捐赠用户功能", - "des": "命令:天气:weather 。" + "des": "命令:天气:weather Pixiv:pixiv。" }, { "name": "calculator", diff --git a/xtao-some.py b/xtao-some.py index 60660c6..5843a1b 100644 --- a/xtao-some.py +++ b/xtao-some.py @@ -228,126 +228,6 @@ async def ipping(context): await context.edit('没有找到要查询的 ip/域名 ...') -@listener(is_plugin=True, outgoing=True, command="pixiv", - description="查询插画信息 (或者回复一条消息)", - parameters="[<图片链接>] <图片序号>") -async def pixiv(context): - reply = await context.get_reply_message() - await context.edit('正在查询中...') - try: - if reply: - try: - if context.arguments.strip() == '': - pixiv_page = 1 - else: - try: - pixiv_page = int(context.arguments.strip()) - except: - await context.edit('呜呜呜出错了...可能参数不是数字') - return True - except: - pass - for num in range(0, len(reply.entities)): - url = reply.message[reply.entities[num].offset:reply.entities[num].offset + reply.entities[num].length] - url = urlparse(url) - try: - url = str(re.findall(r"\d+\.?\d*", url.path)[0]) - pixiv_json = json.loads(requests.get( - "https://api.imjad.cn/pixiv/v2/?type=illust&id=" + url).content.decode( - "utf-8")) - except: - await context.edit('呜呜呜出错了...可能是链接不上 API 服务器') - return True - try: - pixiv_tag = pixiv_json['error']['user_message'] - await context.edit('没有找到要查询的 pixiv 作品...') - return True - except: - if pixiv_page > pixiv_json['illust']['page_count']: - await context.edit('呜呜呜出错了...可能是参数指定的页数大于插画页数') - return True - else: - pass - pixiv_tag = [] - pixiv_num = str(pixiv_json['illust']['page_count']) - pixiv_list = '[' + pixiv_json['illust']['title'] + '](https://www.pixiv.net/artworks/' + str( - pixiv_json['illust']['id']) + ')' + ' (' + str(pixiv_page) + '/' + pixiv_num + ')' - for nums in range(0, len(pixiv_json['illust']['tags'])): - pixiv_tag.extend(['#' + pixiv_json['illust']['tags'][nums]['name']]) - try: - await context.edit('正在下载图片中 ...') - try: - r = requests.get(pixiv_json['illust']['meta_single_page']['original_image_url'].replace('i.pximg.net','i.pixiv.cat')) - except: - r = requests.get(pixiv_json['illust']['meta_pages'][pixiv_page - 1]['image_urls']['original'].replace('i.pximg.net','i.pixiv.cat')) - with open("pixiv.jpg", "wb") as code: - code.write(r.content) - await context.edit('正在上传图片中 ...') - await context.client.send_file(context.chat_id, 'pixiv.jpg', - caption=pixiv_list + '\nTags: ' + ' , '.join(pixiv_tag), - reply_to=reply.id) - await context.delete() - remove('pixiv.jpg') - except: - pass - return True - else: - try: - url = urlparse(context.arguments.split()[0]) - if len(context.arguments.split()) == 1: - pixiv_page = 1 - else: - try: - pixiv_page = int(context.arguments.split()[1]) - except: - await context.edit('呜呜呜出错了...可能参数不是数字') - return True - except: - pass - try: - url = str(re.findall(r"\d+\.?\d*", url.path)[0]) - pixiv_json = json.loads(requests.get( - "https://api.imjad.cn/pixiv/v2/?type=illust&id=" + url).content.decode( - "utf-8")) - except: - await context.edit('呜呜呜出错了...可能是链接不上 API 服务器') - try: - pixiv_tag = pixiv_json['error']['user_message'] - await context.edit('没有找到要查询的 pixiv 作品...') - return True - except: - if pixiv_page > pixiv_json['illust']['page_count']: - await context.edit('呜呜呜出错了...可能是参数指定的页数大于插画页数') - return True - else: - pass - pixiv_tag = [] - pixiv_num = str(pixiv_json['illust']['page_count']) - pixiv_list = '[' + pixiv_json['illust']['title'] + '](https://www.pixiv.net/artworks/' + str( - pixiv_json['illust']['id']) + ')' + ' (' + str(pixiv_page) + '/' + pixiv_num + ')' - for nums in range(0, len(pixiv_json['illust']['tags'])): - pixiv_tag.extend(['#' + pixiv_json['illust']['tags'][nums]['name']]) - try: - await context.edit('正在下载图片中 ...') - try: - r = requests.get(pixiv_json['illust']['meta_single_page']['original_image_url'].replace('i.pximg.net','i.pixiv.cat')) - except: - r = requests.get(pixiv_json['illust']['meta_pages'][pixiv_page - 1]['image_urls']['original'].replace('i.pximg.net','i.pixiv.cat')) - with open("pixiv.jpg", "wb") as code: - code.write(r.content) - await context.edit('正在上传图片中 ...') - await context.client.send_file(context.chat_id, 'pixiv.jpg', - caption=pixiv_list + '\nTags: ' + ' , '.join(pixiv_tag)) - await context.delete() - remove('pixiv.jpg') - except: - pass - return True - await context.edit('没有找到要查询的 pixiv 作品 ...') - except: - await context.edit('没有找到要查询的 pixiv 作品 ...') - - @listener(is_plugin=True, outgoing=True, command="t", description="通过腾讯AI开放平台将目标消息翻译成指定的语言。", parameters="<文本>") From cc36f04c1575d7f39052973a9332d810127e26f8 Mon Sep 17 00:00:00 2001 From: Xtao_dada Date: Sat, 16 Jan 2021 21:31:51 +0800 Subject: [PATCH 09/91] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20pixiv=20=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E7=BC=BA=E5=B0=91=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vip.py b/vip.py index 0137a8e..c93867e 100644 --- a/vip.py +++ b/vip.py @@ -42,7 +42,7 @@ async def pixiv(context): pixiv_albums = pixiv_list[1].split('|||') pixiv_album = [] await context.edit("下载图片中 . . .") - for i in range(0, len(pixiv_albums) - 1): + for i in range(0, len(pixiv_albums)): r = get(pixiv_albums[i]) with open("pixiv." + str(i) + ".jpg", "wb") as code: code.write(r.content) From 87173dac8cf5bf2c32387e25a43f31a839a7b8a1 Mon Sep 17 00:00:00 2001 From: c3b2a <62082214+c3b2a@users.noreply.github.com> Date: Sat, 16 Jan 2021 22:13:20 +0800 Subject: [PATCH 10/91] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=85=B3=E9=94=AE?= =?UTF-8?q?=E8=AF=8D=E5=9B=9E=E5=A4=8D=E6=8F=92=E4=BB=B6=20keyword=20=20(#?= =?UTF-8?q?93)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update list.json * Create keyword.py --- keyword.py | 279 +++++++++++++++++++++++++++++++++++++++++++++++++++++ list.json | 10 ++ 2 files changed, 289 insertions(+) create mode 100644 keyword.py diff --git a/keyword.py b/keyword.py new file mode 100644 index 0000000..c1c240a --- /dev/null +++ b/keyword.py @@ -0,0 +1,279 @@ +import re, time, uuid +from base64 import b64encode, b64decode +from pagermaid import bot, redis, log, redis_status +from pagermaid.listener import listener + +msg_rate = 1 +last_time = time.time() + +def is_num(x: str): + try: + x = int(x) + return isinstance(x, int) + except ValueError: + return False + +def encode(s: str): + return str(b64encode(s.encode('utf-8')), 'utf-8') + +def decode(s: str): + return str(b64decode(s.encode('utf-8')), 'utf-8') + +def random_str(): + return str(uuid.uuid4()).replace('-', '') + +def parse_rules(rules: str): + n_rules = {} + rules_parse = rules.split(";") + for p in rules_parse: + d = p.split(":") + if len(d) == 2: + key = decode(d[0]) + value = decode(d[1]) + n_rules[key] = value + return n_rules + +def save_rules(rules: dict, placeholder: str): + n_rules = "" + for k, v in rules.items(): + if placeholder: + k = k.replace(placeholder, "'") + v = v.replace(placeholder, "'") + n_rules += encode(k) + ":" + encode(v) + ";" + return n_rules + +def validate(user_id: str, mode: int, user_list: list): + if mode == 0: + return user_id not in user_list + elif mode == 1: + return user_id in user_list + else: + return False + +def get_redis(db_key: str): + byte_data = redis.get(db_key) + byte_data = byte_data if byte_data else b"" + byte_data = str(byte_data, "ascii") + return parse_rules(byte_data) + +@listener(is_plugin=True, outgoing=True, command="keyword", + description="关键词自动回复。", + parameters="``new '<规则>' '<回复信息>'` 或者 `del '<规则>'` 或者 `list` 或者 `clear ") +async def reply(context): + if not redis_status(): + await context.edit("出错了呜呜呜 ~ Redis 离线,无法运行。") + return + chat_id = context.chat_id + if chat_id > 0: + await context.edit("请在群组中使用") + return + plain_dict = get_redis(f"keyword.{chat_id}.plain") + regex_dict = get_redis(f"keyword.{chat_id}.regex") + params = context.parameter + params = " ".join(params) + placeholder = random_str() + params = params.replace(r"\'", placeholder) + tmp_parse = params.split("'") + parse = [] + for i in range(len(tmp_parse)): + if len(tmp_parse[i].split()) != 0: + parse.append(tmp_parse[i]) + if len(parse) == 0 or (len(parse[0].split()) == 1 and parse[0].split()[0] in ("new", "del", "clear")) or len(parse[0].split()) > 2: + await context.edit("[Code: -1] 格式错误,格式为 `-keyword` 加上 `new '<规则>' '<回复信息>'` 或者 `del '<规则>'` 或者 `list` 或者 `clear `") + return + else: parse[0] = parse[0].split() + if parse[0][0] == "new" and len(parse) == 3: + if parse[0][1] == "plain": + plain_dict[parse[1]] = parse[2] + redis.set(f"keyword.{chat_id}.plain", save_rules(plain_dict, placeholder)) + elif parse[0][1] == "regex": + regex_dict[parse[1]] = parse[2] + redis.set(f"keyword.{chat_id}.regex", save_rules(regex_dict, placeholder)) + else: + await context.edit("格式错误,格式为 `-keyword` 加上 `new '<规则>' '<回复信息>'` 或者 `del '<规则>'` 或者 `list` 或者 `clear `") + return + await context.edit("设置成功") + elif parse[0][0] == "del" and len(parse) == 2: + if parse[0][1] == "plain": + if parse[1] in plain_dict: + plain_dict.pop(parse[1]) + redis.set(f"keyword.{chat_id}.plain", save_rules(plain_dict, placeholder)) + else: + await context.edit("规则不存在") + return + elif parse[0][1] == "regex": + if parse[1] in regex_dict: + regex_dict.pop(parse[1]) + redis.set(f"keyword.{chat_id}.regex", save_rules(regex_dict, placeholder)) + else: + await context.edit("规则不存在") + return + else: + await context.edit("格式错误,格式为 -keyword 加上 new '<规则>' '<回复信息>' 或者 del '<规则>' 或者 list 或者 clear ") + return + await context.edit("删除成功") + elif parse[0][0] == "list" and len(parse) == 1: + plain_msg = "Plain: \n" + for k, v in plain_dict.items(): + plain_msg += f"`{k}` -> `{v}`\n" + regex_msg = "Regex: \n" + for k, v in regex_dict.items(): + regex_msg += f"`{k}` -> `{v}`\n" + await context.edit(plain_msg + "\n" + regex_msg) + elif parse[0][0] == "clear" and len(parse) == 1: + if parse[0][1] == "plain": + redis.set(f"keyword.{chat_id}.plain", "") + elif parse[0][1] == "regex": + redis.set(f"keyword.{chat_id}.regex", "") + else: + await context.edit("参数错误") + return + await context.edit("清除成功") + else: + await context.edit("[Code -2] 格式错误,格式为 `-keyword` 加上 `new '<规则>' '<回复信息>'` 或者 `del '<规则>'` 或者 `list` 或者 `clear `") + return + +@listener(outgoing=True, command="replyset", + description="自动回复设置。", + parameters="help") +async def reply_set(context): + if not redis_status(): + await context.edit("出错了呜呜呜 ~ Redis 离线,无法运行。") + return + chat_id = context.chat_id + if chat_id > 0: + await context.edit("请在群组中使用") + return + params = context.parameter + is_global = len(params) >= 1 and params[0] == "global" + redis_data = "keyword.settings" if is_global else f"keyword.{chat_id}.settings" + if is_global: + del params[0] + settings_dict = get_redis(redis_data) + cmd_list = ["help", "mode", "list", "show", "clear"] + cmd_dict = {"help": (1, ), "mode": (2, ), "list": (2, 3), "show": (1, ), "clear": (1, )} + if len(params) < 1: + await context.edit("参数错误") + return + if params[0] in cmd_list and len(params) in cmd_dict[params[0]]: + if params[0] == "help": + await context.edit(''' +`-replyset show` 或 +`-replyset clear` 或 +`-replyset mode <0/1/clear>` ( 0 表示黑名单,1 表示白名单 ) 或 +`-replyset list [user_id]`。 +在 `-replyset` 后面加上 `global` 即为全局设置''') + return + elif params[0] == "show": + defaults = {"mode": "0", "list": "无"} + msg = "Settings: \n" + for k, v in defaults.items(): + msg += f"`{k}` -> `{settings_dict[k] if k in settings_dict else v}`\n" + await context.edit(msg) + return + elif params[0] == "mode": + if params[1] in ("0", "1"): + settings_dict["mode"] = params[1] + redis.set(redis_data, save_rules(settings_dict, None)) + if params[1] == "0": await context.edit("模式已更改为黑名单") + elif params[1] == "1": await context.edit("模式已更改为白名单") + return + elif params[1] == "clear": + if "mode" in settings_dict: del settings_dict["mode"] + redis.set(redis_data, save_rules(settings_dict, None)) + await context.edit("清除成功") + return + else: + await context.edit("参数错误") + return + elif params[0] == "list": + if params[1] == "show" and len(params) == 2: + user_list = settings_dict["list"] if "list" in settings_dict else None + if user_list: + msg = "List: \n" + for p in user_list.split(","): + msg += f"`{p}`\n" + await context.edit(msg) + return + else: + await context.edit("列表为空") + return + elif params[1] == "add" and len(params) == 3: + if is_num(params[2]): + tmp = settings_dict["list"] if "list" in settings_dict else None + if not tmp: settings_dict["list"] = params[2] + else: settings_dict["list"] += f",{params[2]}" + redis.set(redis_data, save_rules(settings_dict, None)) + await context.edit("添加成功") + return + else: + await context.edit("user_id 需为整数") + return + elif params[1] == "del" and len(params) == 3: + if is_num(params[2]): + tmp = settings_dict["list"] if "list" in settings_dict else None + if tmp: + user_list = settings_dict["list"].split(",") + if params[2] in user_list: + user_list.remove(params[2]) + settings_dict["list"] = ",".join(user_list) + redis.set(redis_data, save_rules(settings_dict, None)) + await context.edit("删除成功") + return + else: + await context.edit("user_id 不在列表") + return + else: + await context.edit("列表为空") + return + else: + await context.edit("user_id 需为整数") + return + elif params[1] == "clear" and len(params) == 2: + if "list" in settings_dict: del settings_dict["list"] + redis.set(redis_data, save_rules(settings_dict, None)) + await context.edit("清除成功") + return + else: + await context.edit("参数错误") + return + elif params[0] == "clear": + redis.delete(redis_data) + await context.edit("清除成功") + return + else: + await context.edit("参数错误") + return + + +@listener(incoming=True, ignore_edited=True) +async def auto_reply(context): + global msg_rate, last_time + chat_id = context.chat_id + sender_id = context.sender_id + if chat_id < 0: + plain_dict = get_redis(f"keyword.{chat_id}.plain") + regex_dict = get_redis(f"keyword.{chat_id}.regex") + g_settings = get_redis("keyword.settings") + n_settings = get_redis(f"keyword.{chat_id}.settings") + g_mode = g_settings["mode"] if "mode" in g_settings else None + n_mode = n_settings["mode"] if "mode" in n_settings else None + mode = "0" + g_list = g_settings["list"] if "list" in g_settings else None + n_list = n_settings["list"] if "list" in n_settings else None + user_list = [] + if g_mode and n_mode: mode = n_mode + elif g_mode or n_mode: mode = g_mode if g_mode else n_mode + if g_list and n_list: user_list = n_list + elif g_list or n_list: user_list = g_list if g_list else n_list + for k, v in plain_dict.items(): + if k in context.text and time.time() - last_time > msg_rate: + if validate(str(sender_id), int(mode), user_list): + last_time = time.time() + await bot.send_message(chat_id, v) + for k, v in regex_dict.items(): + pattern = re.compile(k) + if pattern.search(context.text) and time.time() - last_time > msg_rate: + if validate(str(sender_id), int(mode), user_list): + last_time = time.time() + await bot.send_message(chat_id, v) diff --git a/list.json b/list.json index f2d7f65..bbbd7f1 100644 --- a/list.json +++ b/list.json @@ -359,6 +359,16 @@ "supported": true, "des-short": "一键跑路(删所有消息并禁言)", "des": "paolu。" + }, + { + "name": "keyword", + "version": "1.00", + "section": "chat", + "maintainer": "c3b2a", + "size": "11.9 kb", + "supported": true, + "des-short": "群组关键词自动回复插件", + "des": "keyword, replyset。" } ] } From e4d280e28fe7c6b6f3ddadfbad990301a170450d Mon Sep 17 00:00:00 2001 From: c3b2a <62082214+c3b2a@users.noreply.github.com> Date: Sun, 17 Jan 2021 09:42:11 +0800 Subject: [PATCH 11/91] =?UTF-8?q?keyword=20=E6=B7=BB=E5=8A=A0=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E8=87=AA=E5=8A=A8=E5=88=A0=E9=99=A4=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=20(#94)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 添加消息自动删除功能 * Update list.json --- keyword.py | 47 +++++++++++++++++++++++++++++++++++++++++------ list.json | 4 ++-- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/keyword.py b/keyword.py index c1c240a..e1f27e0 100644 --- a/keyword.py +++ b/keyword.py @@ -1,4 +1,5 @@ -import re, time, uuid +import re, time, asyncio +from uuid import uuid4 from base64 import b64encode, b64decode from pagermaid import bot, redis, log, redis_status from pagermaid.listener import listener @@ -20,7 +21,7 @@ def decode(s: str): return str(b64decode(s.encode('utf-8')), 'utf-8') def random_str(): - return str(uuid.uuid4()).replace('-', '') + return str(uuid4()).replace('-', '') def parse_rules(rules: str): n_rules = {} @@ -56,16 +57,22 @@ def get_redis(db_key: str): byte_data = str(byte_data, "ascii") return parse_rules(byte_data) +async def del_msg(context, t_lim): + await asyncio.sleep(t_lim) + await context.delete() + @listener(is_plugin=True, outgoing=True, command="keyword", - description="关键词自动回复。", + description="关键词自动回复", parameters="``new '<规则>' '<回复信息>'` 或者 `del '<规则>'` 或者 `list` 或者 `clear ") async def reply(context): if not redis_status(): - await context.edit("出错了呜呜呜 ~ Redis 离线,无法运行。") + await context.edit("出错了呜呜呜 ~ Redis 离线,无法运行") + await del_msg(context, 5) return chat_id = context.chat_id if chat_id > 0: await context.edit("请在群组中使用") + await del_msg(context, 5) return plain_dict = get_redis(f"keyword.{chat_id}.plain") regex_dict = get_redis(f"keyword.{chat_id}.regex") @@ -80,6 +87,7 @@ async def reply(context): parse.append(tmp_parse[i]) if len(parse) == 0 or (len(parse[0].split()) == 1 and parse[0].split()[0] in ("new", "del", "clear")) or len(parse[0].split()) > 2: await context.edit("[Code: -1] 格式错误,格式为 `-keyword` 加上 `new '<规则>' '<回复信息>'` 或者 `del '<规则>'` 或者 `list` 或者 `clear `") + await del_msg(context, 10) return else: parse[0] = parse[0].split() if parse[0][0] == "new" and len(parse) == 3: @@ -91,8 +99,10 @@ async def reply(context): redis.set(f"keyword.{chat_id}.regex", save_rules(regex_dict, placeholder)) else: await context.edit("格式错误,格式为 `-keyword` 加上 `new '<规则>' '<回复信息>'` 或者 `del '<规则>'` 或者 `list` 或者 `clear `") + await del_msg(context, 10) return await context.edit("设置成功") + await del_msg(context, 5) elif parse[0][0] == "del" and len(parse) == 2: if parse[0][1] == "plain": if parse[1] in plain_dict: @@ -100,6 +110,7 @@ async def reply(context): redis.set(f"keyword.{chat_id}.plain", save_rules(plain_dict, placeholder)) else: await context.edit("规则不存在") + await del_msg(context, 5) return elif parse[0][1] == "regex": if parse[1] in regex_dict: @@ -107,11 +118,14 @@ async def reply(context): redis.set(f"keyword.{chat_id}.regex", save_rules(regex_dict, placeholder)) else: await context.edit("规则不存在") + await del_msg(context, 5) return else: await context.edit("格式错误,格式为 -keyword 加上 new '<规则>' '<回复信息>' 或者 del '<规则>' 或者 list 或者 clear ") + await del_msg(context, 10) return await context.edit("删除成功") + await del_msg(context, 5) elif parse[0][0] == "list" and len(parse) == 1: plain_msg = "Plain: \n" for k, v in plain_dict.items(): @@ -127,22 +141,27 @@ async def reply(context): redis.set(f"keyword.{chat_id}.regex", "") else: await context.edit("参数错误") + await del_msg(context, 5) return await context.edit("清除成功") + await del_msg(context, 5) else: await context.edit("[Code -2] 格式错误,格式为 `-keyword` 加上 `new '<规则>' '<回复信息>'` 或者 `del '<规则>'` 或者 `list` 或者 `clear `") + await del_msg(context, 10) return @listener(outgoing=True, command="replyset", - description="自动回复设置。", + description="自动回复设置", parameters="help") async def reply_set(context): if not redis_status(): - await context.edit("出错了呜呜呜 ~ Redis 离线,无法运行。") + await context.edit("出错了呜呜呜 ~ Redis 离线,无法运行") + await del_msg(context, 5) return chat_id = context.chat_id if chat_id > 0: await context.edit("请在群组中使用") + await del_msg(context, 5) return params = context.parameter is_global = len(params) >= 1 and params[0] == "global" @@ -154,6 +173,7 @@ async def reply_set(context): cmd_dict = {"help": (1, ), "mode": (2, ), "list": (2, 3), "show": (1, ), "clear": (1, )} if len(params) < 1: await context.edit("参数错误") + await del_msg(context, 5) return if params[0] in cmd_list and len(params) in cmd_dict[params[0]]: if params[0] == "help": @@ -163,6 +183,7 @@ async def reply_set(context): `-replyset mode <0/1/clear>` ( 0 表示黑名单,1 表示白名单 ) 或 `-replyset list [user_id]`。 在 `-replyset` 后面加上 `global` 即为全局设置''') + await del_msg(context, 15) return elif params[0] == "show": defaults = {"mode": "0", "list": "无"} @@ -177,14 +198,17 @@ async def reply_set(context): redis.set(redis_data, save_rules(settings_dict, None)) if params[1] == "0": await context.edit("模式已更改为黑名单") elif params[1] == "1": await context.edit("模式已更改为白名单") + await del_msg(context, 5) return elif params[1] == "clear": if "mode" in settings_dict: del settings_dict["mode"] redis.set(redis_data, save_rules(settings_dict, None)) await context.edit("清除成功") + await del_msg(context, 5) return else: await context.edit("参数错误") + await del_msg(context, 5) return elif params[0] == "list": if params[1] == "show" and len(params) == 2: @@ -197,6 +221,7 @@ async def reply_set(context): return else: await context.edit("列表为空") + await del_msg(context, 5) return elif params[1] == "add" and len(params) == 3: if is_num(params[2]): @@ -205,9 +230,11 @@ async def reply_set(context): else: settings_dict["list"] += f",{params[2]}" redis.set(redis_data, save_rules(settings_dict, None)) await context.edit("添加成功") + await del_msg(context, 5) return else: await context.edit("user_id 需为整数") + await del_msg(context, 5) return elif params[1] == "del" and len(params) == 3: if is_num(params[2]): @@ -219,30 +246,38 @@ async def reply_set(context): settings_dict["list"] = ",".join(user_list) redis.set(redis_data, save_rules(settings_dict, None)) await context.edit("删除成功") + await del_msg(context, 5) return else: await context.edit("user_id 不在列表") + await del_msg(context, 5) return else: await context.edit("列表为空") + await del_msg(context, 5) return else: await context.edit("user_id 需为整数") + await del_msg(context, 5) return elif params[1] == "clear" and len(params) == 2: if "list" in settings_dict: del settings_dict["list"] redis.set(redis_data, save_rules(settings_dict, None)) await context.edit("清除成功") + await del_msg(context, 5) return else: await context.edit("参数错误") + await del_msg(context, 5) return elif params[0] == "clear": redis.delete(redis_data) await context.edit("清除成功") + await del_msg(context, 5) return else: await context.edit("参数错误") + await del_msg(context, 5) return diff --git a/list.json b/list.json index bbbd7f1..e8e0098 100644 --- a/list.json +++ b/list.json @@ -362,10 +362,10 @@ }, { "name": "keyword", - "version": "1.00", + "version": "1.1", "section": "chat", "maintainer": "c3b2a", - "size": "11.9 kb", + "size": "12.9 kb", "supported": true, "des-short": "群组关键词自动回复插件", "des": "keyword, replyset。" From 9c67341626992217c8ab4007a9f4caac1c018ed9 Mon Sep 17 00:00:00 2001 From: c3b2a <62082214+c3b2a@users.noreply.github.com> Date: Sun, 17 Jan 2021 23:10:44 +0800 Subject: [PATCH 12/91] =?UTF-8?q?keyword=20=E5=8A=9F=E8=83=BD=E6=80=A7?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=20(#95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update keyword.py * Update list.json --- keyword.py | 46 +++++++++++++++++++++++++++++++++++++++++----- list.json | 4 ++-- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/keyword.py b/keyword.py index e1f27e0..15fdc18 100644 --- a/keyword.py +++ b/keyword.py @@ -1,4 +1,5 @@ -import re, time, asyncio +import re, time, asyncio, requests +from os import path, mkdir, remove from uuid import uuid4 from base64 import b64encode, b64decode from pagermaid import bot, redis, log, redis_status @@ -57,10 +58,44 @@ def get_redis(db_key: str): byte_data = str(byte_data, "ascii") return parse_rules(byte_data) +def parse_multi(rule: str): + sep_ph = random_str() + col_ph = random_str() + rule = rule.replace(r"\||", sep_ph) + rule = rule.replace(r"\::", col_ph) + rule = rule.split("||") + n_rule = [] + for r in rule: + p = r.split("::") + p = [i.replace(sep_ph, "||") for i in p] + p = [i.replace(col_ph, "::") for i in p] + data = ['plain', ''] + if len(p) == 2: data = p + else: data[1] = p[0] + n_rule.append(data) + return n_rule + async def del_msg(context, t_lim): await asyncio.sleep(t_lim) await context.delete() +async def send_reply(chat_id, reply_msg, context): + for re_type, re_msg in reply_msg: + if re_type == "plain": + await bot.send_message(chat_id, re_msg) + elif re_type == "file" and len(re_msg.split()) >= 2: + if not path.exists("/tmp"): mkdir("/tmp") + re_data = re_msg.split() + file_name = "/tmp/" + re_data[0] + file_get = requests.get(" ".join(re_data[1: ])) + with open(file_name, "wb") as f: + f.write(file_get.content) + await bot.send_file(chat_id, file_name) + remove(file_name) + elif re_type == "op": + if re_msg == "delete": + await context.delete() + @listener(is_plugin=True, outgoing=True, command="keyword", description="关键词自动回复", parameters="``new '<规则>' '<回复信息>'` 或者 `del '<规则>'` 或者 `list` 或者 `clear ") @@ -301,14 +336,15 @@ async def auto_reply(context): elif g_mode or n_mode: mode = g_mode if g_mode else n_mode if g_list and n_list: user_list = n_list elif g_list or n_list: user_list = g_list if g_list else n_list + send_text = context.text for k, v in plain_dict.items(): - if k in context.text and time.time() - last_time > msg_rate: + if k in send_text and time.time() - last_time > msg_rate: if validate(str(sender_id), int(mode), user_list): last_time = time.time() - await bot.send_message(chat_id, v) + await send_reply(chat_id, parse_multi(v), context) for k, v in regex_dict.items(): pattern = re.compile(k) - if pattern.search(context.text) and time.time() - last_time > msg_rate: + if pattern.search(send_text) and time.time() - last_time > msg_rate: if validate(str(sender_id), int(mode), user_list): last_time = time.time() - await bot.send_message(chat_id, v) + await send_reply(chat_id, parse_multi(v), context) diff --git a/list.json b/list.json index e8e0098..6868d66 100644 --- a/list.json +++ b/list.json @@ -362,10 +362,10 @@ }, { "name": "keyword", - "version": "1.1", + "version": "1.2", "section": "chat", "maintainer": "c3b2a", - "size": "12.9 kb", + "size": "14.2 kb", "supported": true, "des-short": "群组关键词自动回复插件", "des": "keyword, replyset。" From 4b351664b9855c82011121e62c43646359060a41 Mon Sep 17 00:00:00 2001 From: c3b2a <62082214+c3b2a@users.noreply.github.com> Date: Mon, 18 Jan 2021 20:24:19 +0800 Subject: [PATCH 13/91] Update keyword.py --- keyword.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/keyword.py b/keyword.py index 15fdc18..64ba9c0 100644 --- a/keyword.py +++ b/keyword.py @@ -75,12 +75,30 @@ def parse_multi(rule: str): n_rule.append(data) return n_rule +def get_capture(search_data, group_name): + try: + capture_data = search_data.group(group_name) + return capture_data + except: + return None + async def del_msg(context, t_lim): await asyncio.sleep(t_lim) await context.delete() async def send_reply(chat_id, reply_msg, context): + chat = context.chat + sender = context.sender + replace_data = { + "user_id": sender.id, + "first_name": sender.first_name, + "last_name": sender.last_name if sender.last_name else "", + "chat_id": chat.id, + "chat_name": chat.title + } for re_type, re_msg in reply_msg: + for k, v in replace_data.items(): + re_msg = re_msg.replace(f"${k}", str(v)) if re_type == "plain": await bot.send_message(chat_id, re_msg) elif re_type == "file" and len(re_msg.split()) >= 2: @@ -95,6 +113,10 @@ async def send_reply(chat_id, reply_msg, context): elif re_type == "op": if re_msg == "delete": await context.delete() + elif re_msg.split()[0] == "sleep" and len(re_msg.split()) == 2: + sleep_time = re_msg.split()[1] + if is_num(sleep_time): + await asyncio.sleep(int(sleep_time)) @listener(is_plugin=True, outgoing=True, command="keyword", description="关键词自动回复", @@ -347,4 +369,15 @@ async def auto_reply(context): if pattern.search(send_text) and time.time() - last_time > msg_rate: if validate(str(sender_id), int(mode), user_list): last_time = time.time() + catch_pattern = r"\$\{regex_(?P((?!\}).)+)\}" + while re.search(catch_pattern, v): + search_data = re.search(k, send_text) + print(search_data) + group_name = re.search(catch_pattern, v).group("str") + print(group_name) + capture_data = get_capture(search_data, group_name) + print(capture_data) + if not capture_data: capture_data = "" + v = v.replace("${regex_%s}" % group_name, capture_data) + print(v) await send_reply(chat_id, parse_multi(v), context) From d4262a0ca3321f63e6461d6df2f86871a3ca29eb Mon Sep 17 00:00:00 2001 From: c3b2a <62082214+c3b2a@users.noreply.github.com> Date: Mon, 18 Jan 2021 20:25:06 +0800 Subject: [PATCH 14/91] Update list.json --- list.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/list.json b/list.json index 6868d66..dbdf406 100644 --- a/list.json +++ b/list.json @@ -362,13 +362,13 @@ }, { "name": "keyword", - "version": "1.2", + "version": "1.3", "section": "chat", "maintainer": "c3b2a", - "size": "14.2 kb", + "size": "15.6 kb", "supported": true, "des-short": "群组关键词自动回复插件", - "des": "keyword, replyset。" + "des": "命令: keyword, replyset。" } ] } From 70980a953dd97f83676d8a06c3c4659479dbbc72 Mon Sep 17 00:00:00 2001 From: c3b2a <62082214+c3b2a@users.noreply.github.com> Date: Mon, 18 Jan 2021 20:34:25 +0800 Subject: [PATCH 15/91] =?UTF-8?q?keyword=20=E5=A2=9E=E5=8A=A0=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E5=8F=98=E9=87=8F=E5=92=8C=E6=AD=A3=E5=88=99=E6=8D=95?= =?UTF-8?q?=E8=8E=B7=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- keyword.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keyword.py b/keyword.py index 64ba9c0..5882087 100644 --- a/keyword.py +++ b/keyword.py @@ -82,7 +82,7 @@ def get_capture(search_data, group_name): except: return None -async def del_msg(context, t_lim): +async def del_msg(context, t_lim: int): await asyncio.sleep(t_lim) await context.delete() From c9a970dbd54a852c7951e5fb8432f9e9fddcb265 Mon Sep 17 00:00:00 2001 From: c3b2a <62082214+c3b2a@users.noreply.github.com> Date: Mon, 18 Jan 2021 22:42:53 +0800 Subject: [PATCH 16/91] =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=92=8C=E5=88=A0=E9=99=A4=E5=BF=98=E5=88=A0=E7=9A=84debug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- keyword.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/keyword.py b/keyword.py index 5882087..2c930ed 100644 --- a/keyword.py +++ b/keyword.py @@ -82,7 +82,7 @@ def get_capture(search_data, group_name): except: return None -async def del_msg(context, t_lim: int): +async def del_msg(context, t_lim): await asyncio.sleep(t_lim) await context.delete() @@ -269,7 +269,7 @@ async def reply_set(context): return elif params[0] == "list": if params[1] == "show" and len(params) == 2: - user_list = settings_dict["list"] if "list" in settings_dict else None + user_list = settings_dict.get("list", None) if user_list: msg = "List: \n" for p in user_list.split(","): @@ -282,7 +282,7 @@ async def reply_set(context): return elif params[1] == "add" and len(params) == 3: if is_num(params[2]): - tmp = settings_dict["list"] if "list" in settings_dict else None + tmp = settings_dict.get("list", None) if not tmp: settings_dict["list"] = params[2] else: settings_dict["list"] += f",{params[2]}" redis.set(redis_data, save_rules(settings_dict, None)) @@ -295,7 +295,7 @@ async def reply_set(context): return elif params[1] == "del" and len(params) == 3: if is_num(params[2]): - tmp = settings_dict["list"] if "list" in settings_dict else None + tmp = settings_dict.get("list", None) if tmp: user_list = settings_dict["list"].split(",") if params[2] in user_list: @@ -348,11 +348,11 @@ async def auto_reply(context): regex_dict = get_redis(f"keyword.{chat_id}.regex") g_settings = get_redis("keyword.settings") n_settings = get_redis(f"keyword.{chat_id}.settings") - g_mode = g_settings["mode"] if "mode" in g_settings else None - n_mode = n_settings["mode"] if "mode" in n_settings else None + g_mode = g_settings.get("mode", None) + n_mode = n_settings.get("mode", None) mode = "0" - g_list = g_settings["list"] if "list" in g_settings else None - n_list = n_settings["list"] if "list" in n_settings else None + g_list = g_settings.get("list", None) + n_list = g_settings.get("list", None) user_list = [] if g_mode and n_mode: mode = n_mode elif g_mode or n_mode: mode = g_mode if g_mode else n_mode @@ -372,12 +372,8 @@ async def auto_reply(context): catch_pattern = r"\$\{regex_(?P((?!\}).)+)\}" while re.search(catch_pattern, v): search_data = re.search(k, send_text) - print(search_data) group_name = re.search(catch_pattern, v).group("str") - print(group_name) capture_data = get_capture(search_data, group_name) - print(capture_data) if not capture_data: capture_data = "" v = v.replace("${regex_%s}" % group_name, capture_data) - print(v) await send_reply(chat_id, parse_multi(v), context) From 0677e12c5c46d4c86459e117fea709dba1086cd9 Mon Sep 17 00:00:00 2001 From: c3b2a <62082214+c3b2a@users.noreply.github.com> Date: Mon, 18 Jan 2021 22:44:34 +0800 Subject: [PATCH 17/91] =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=92=8C=E5=88=A0=E9=99=A4=E5=BF=98=E5=88=A0=E7=9A=84debug?= 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 dbdf406..c727172 100644 --- a/list.json +++ b/list.json @@ -362,7 +362,7 @@ }, { "name": "keyword", - "version": "1.3", + "version": "1.4", "section": "chat", "maintainer": "c3b2a", "size": "15.6 kb", From 08e6537d4a1cf6ec0f72e8546ee4f7831fa7a48a Mon Sep 17 00:00:00 2001 From: c3b2a <62082214+c3b2a@users.noreply.github.com> Date: Tue, 19 Jan 2021 17:42:55 +0800 Subject: [PATCH 18/91] =?UTF-8?q?bug=20=E4=BF=AE=E5=A4=8D=20(#97)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update keyword.py * Update list.json --- keyword.py | 7 +++++-- list.json | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/keyword.py b/keyword.py index 2c930ed..ef073a7 100644 --- a/keyword.py +++ b/keyword.py @@ -352,7 +352,7 @@ async def auto_reply(context): n_mode = n_settings.get("mode", None) mode = "0" g_list = g_settings.get("list", None) - n_list = g_settings.get("list", None) + n_list = n_settings.get("list", None) user_list = [] if g_mode and n_mode: mode = n_mode elif g_mode or n_mode: mode = g_mode if g_mode else n_mode @@ -370,10 +370,13 @@ async def auto_reply(context): if validate(str(sender_id), int(mode), user_list): last_time = time.time() catch_pattern = r"\$\{regex_(?P((?!\}).)+)\}" - while re.search(catch_pattern, v): + count = 0 + while re.search(catch_pattern, v) and count < 20: search_data = re.search(k, send_text) group_name = re.search(catch_pattern, v).group("str") capture_data = get_capture(search_data, group_name) if not capture_data: capture_data = "" + if re.search(catch_pattern, capture_data): capture_data = "" v = v.replace("${regex_%s}" % group_name, capture_data) + count += 1 await send_reply(chat_id, parse_multi(v), context) diff --git a/list.json b/list.json index c727172..0fc1098 100644 --- a/list.json +++ b/list.json @@ -362,10 +362,10 @@ }, { "name": "keyword", - "version": "1.4", + "version": "1.5", "section": "chat", "maintainer": "c3b2a", - "size": "15.6 kb", + "size": "15.4 kb", "supported": true, "des-short": "群组关键词自动回复插件", "des": "命令: keyword, replyset。" From cce2af8f323877822887924b9b76355f61ba78ec Mon Sep 17 00:00:00 2001 From: c3b2a <62082214+c3b2a@users.noreply.github.com> Date: Wed, 20 Jan 2021 16:35:15 +0800 Subject: [PATCH 19/91] =?UTF-8?q?=E9=98=B2=E6=AD=A2=20vps=20=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E5=AE=89=E8=A3=85=20redis-server=20=E9=80=A0=E6=88=90?= =?UTF-8?q?=E7=9A=84=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- keyword.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/keyword.py b/keyword.py index ef073a7..6ac2dd4 100644 --- a/keyword.py +++ b/keyword.py @@ -340,6 +340,8 @@ async def reply_set(context): @listener(incoming=True, ignore_edited=True) async def auto_reply(context): + if not redis_status(): + return global msg_rate, last_time chat_id = context.chat_id sender_id = context.sender_id From abb076c659cd69c24d38672340fd3a20be2c4b2f Mon Sep 17 00:00:00 2001 From: c3b2a <62082214+c3b2a@users.noreply.github.com> Date: Wed, 20 Jan 2021 16:36:53 +0800 Subject: [PATCH 20/91] =?UTF-8?q?keyword=20=E9=98=B2=E6=AD=A2=E6=B2=A1?= =?UTF-8?q?=E5=AE=89=E8=A3=85=20redis-server=20=E9=80=A0=E6=88=90=E7=9A=84?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= 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 0fc1098..5a4eaa8 100644 --- a/list.json +++ b/list.json @@ -362,7 +362,7 @@ }, { "name": "keyword", - "version": "1.5", + "version": "1.5.1", "section": "chat", "maintainer": "c3b2a", "size": "15.4 kb", From 45f6b0d8c8d9087c31b304c6b8542e7da250c83b Mon Sep 17 00:00:00 2001 From: c3b2a <62082214+c3b2a@users.noreply.github.com> Date: Wed, 20 Jan 2021 16:37:35 +0800 Subject: [PATCH 21/91] Update list.json --- list.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/list.json b/list.json index 5a4eaa8..e6960c7 100644 --- a/list.json +++ b/list.json @@ -362,7 +362,7 @@ }, { "name": "keyword", - "version": "1.5.1", + "version": "1.6", "section": "chat", "maintainer": "c3b2a", "size": "15.4 kb", From 657c5e0f379576f7163d9f3dd4ea4271ca53dc9a Mon Sep 17 00:00:00 2001 From: c3b2a <62082214+c3b2a@users.noreply.github.com> Date: Wed, 20 Jan 2021 20:12:29 +0800 Subject: [PATCH 22/91] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=9B=9E=E5=A4=8D?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=8A=9F=E8=83=BD=20(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update keyword.py * Update list.json --- keyword.py | 2 ++ list.json | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/keyword.py b/keyword.py index 6ac2dd4..07decd4 100644 --- a/keyword.py +++ b/keyword.py @@ -101,6 +101,8 @@ async def send_reply(chat_id, reply_msg, context): re_msg = re_msg.replace(f"${k}", str(v)) if re_type == "plain": await bot.send_message(chat_id, re_msg) + elif re_type == "reply": + await bot.send_message(chat_id, re_msg, reply_to = context.id) elif re_type == "file" and len(re_msg.split()) >= 2: if not path.exists("/tmp"): mkdir("/tmp") re_data = re_msg.split() diff --git a/list.json b/list.json index e6960c7..55de896 100644 --- a/list.json +++ b/list.json @@ -362,10 +362,10 @@ }, { "name": "keyword", - "version": "1.6", + "version": "1.7", "section": "chat", "maintainer": "c3b2a", - "size": "15.4 kb", + "size": "15.5 kb", "supported": true, "des-short": "群组关键词自动回复插件", "des": "命令: keyword, replyset。" From 4fd0ebef0a3180395ed775c38c5bea03cb203c51 Mon Sep 17 00:00:00 2001 From: c3b2a <62082214+c3b2a@users.noreply.github.com> Date: Wed, 20 Jan 2021 20:29:07 +0800 Subject: [PATCH 23/91] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=20(#99)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update keyword.py * Update list.json --- keyword.py | 2 +- list.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/keyword.py b/keyword.py index 07decd4..203994d 100644 --- a/keyword.py +++ b/keyword.py @@ -245,7 +245,7 @@ async def reply_set(context): await del_msg(context, 15) return elif params[0] == "show": - defaults = {"mode": "0", "list": "无"} + defaults = {"mode": "未设置", "list": "未设置"} msg = "Settings: \n" for k, v in defaults.items(): msg += f"`{k}` -> `{settings_dict[k] if k in settings_dict else v}`\n" diff --git a/list.json b/list.json index 55de896..02a4638 100644 --- a/list.json +++ b/list.json @@ -362,7 +362,7 @@ }, { "name": "keyword", - "version": "1.7", + "version": "1.8", "section": "chat", "maintainer": "c3b2a", "size": "15.5 kb", From 9fb2606fd92e1605c770c018a461b2f3fe01eda9 Mon Sep 17 00:00:00 2001 From: c3b2a <62082214+c3b2a@users.noreply.github.com> Date: Fri, 22 Jan 2021 14:34:38 +0800 Subject: [PATCH 24/91] =?UTF-8?q?=E6=AF=8F=E5=A4=A9=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E5=8F=91=E9=80=81=E4=BF=A1=E6=81=AF=EF=BC=88=E4=BE=9D=E9=9D=A0?= =?UTF-8?q?=20bot=20=E5=AE=9E=E7=8E=B0=EF=BC=89=20(#100)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Create msgst.py * Update list.json --- list.json | 10 +++++++ msgst.py | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 msgst.py diff --git a/list.json b/list.json index 02a4638..cc36cc7 100644 --- a/list.json +++ b/list.json @@ -369,6 +369,16 @@ "supported": true, "des-short": "群组关键词自动回复插件", "des": "命令: keyword, replyset。" + }, + { + "name": "msgst", + "version": "1.0", + "section": "chat", + "maintainer": "c3b2a", + "size": "3.0 kb", + "supported": true, + "des-short": "消息每天定时发送", + "des": "命令: msgst, msgset。" } ] } diff --git a/msgst.py b/msgst.py new file mode 100644 index 0000000..3526c0f --- /dev/null +++ b/msgst.py @@ -0,0 +1,81 @@ +import asyncio +from pagermaid import bot, redis, redis_status +from pagermaid.listener import listener + +def is_num(x: str): + try: + x = int(x) + return isinstance(x, int) + except ValueError: + return False + +def get_bot(): + data = [1527463252, "msg_schedule_bot"] + if redis_status(): + n_id = redis.get("msgst.bot_id") + n_un = redis.get("msgst.bot_un") + if n_id and is_num(str(n_id, "ascii")): data[0] = int(str(n_id, "ascii")) + if n_un: data[1] = str(n_un, "ascii") + return data + +async def del_msg(context, t_lim): + await asyncio.sleep(t_lim) + await context.delete() + +@listener(is_plugin=True, outgoing=True, command="msgst", + description="消息每天定时发送", + parameters="new