From 707c8114f3ccf2ff9563005db3b360c042769870 Mon Sep 17 00:00:00 2001 From: F2DRD <53929319+newkld@users.noreply.github.com> Date: Wed, 28 Jul 2021 21:51:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8F=92=E4=BB=B6=EF=BC=9Ayy?= =?UTF-8?q?r=20=E6=8A=8A=E6=99=AE=E9=80=9A=E7=9A=84=E8=AF=9D=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E6=88=90=E6=8A=BD=E8=B1=A1=E8=AF=9D=20(#176)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 新增插件:yyr 把普通的话转换成抽象话 Co-authored-by: Xtao_dada --- list.json | 10 ++++++++++ yyr.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 yyr.py diff --git a/list.json b/list.json index 3c6755f..43bbceb 100644 --- a/list.json +++ b/list.json @@ -659,6 +659,16 @@ "supported": true, "des-short": "删除烦人的消息", "des": "删除最近 200 条消息中包含指定关键字的消息。" + }, + { + "name": "yyr", + "version": "1.0", + "section": "chat", + "maintainer": "xtaodada、kld", + "size": "0.9 kb", + "supported": true, + "des-short": "抽象话转换", + "des": "把普通的话转换成抽象话" } ] } diff --git a/yyr.py b/yyr.py new file mode 100644 index 0000000..d2c3040 --- /dev/null +++ b/yyr.py @@ -0,0 +1,31 @@ +import json, requests +from pagermaid.listener import listener +from pagermaid.utils import alias_command + + +@listener(is_plugin=True, outgoing=True, command=alias_command("yyr"), + description="我们都是孙笑川", + parameters="<字符串>") +async def yyr(context): + text = context.arguments + if not text: + await context.edit("出错了呜呜呜 ~ 无效的参数。") + return + + try: + req_data = requests.get("https://github.com/gaowanliang/NMSL/raw/master/src/data/emoji.json").text + except Exception as e: + await context.edit("出错了呜呜呜 ~ 无法获取词库。") + return + + try: + req_data = json.loads(req_data) + except Exception as e: + await context.edit("出错了呜呜呜 ~ 解析JSON时发生了错误。") + return + + result = text + for key in sorted(req_data, key=len, reverse=True): + result = result.replace(key, req_data[key]) + + await context.edit(result)