From cfac5c26c2394064bb042f45336f75c852307732 Mon Sep 17 00:00:00 2001 From: gchengyu <86chengyujin@gmail.com> Date: Sat, 21 Aug 2021 00:30:57 +0800 Subject: [PATCH] =?UTF-8?q?yinglish=20=E8=83=BD=E6=8A=8A=E4=B8=AD=E6=96=87?= =?UTF-8?q?=E7=BF=BB=E8=AF=91=E6=88=90=E6=B7=AB=E8=AF=AD=E7=9A=84=E7=BF=BB?= =?UTF-8?q?=E8=AF=91=E6=9C=BA=20(#179)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Xtao_dada --- README.md | 1 + list.json | 10 ++++++++ yinglish.py | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 yinglish.py diff --git a/README.md b/README.md index b343b4d..58c1857 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ - `paolu` : 一键跑路(删所有消息并禁言)。 - `keyword` : 群组关键词自动回复插件。 - `msgst` : 每天定时发送消息。 + - `yinglish` : 能把中文翻译成淫语的翻译机. - profile (资料类) - `autochangename` : 自动更新 last_name 为时间等。 - `throwit` : 生成一张 扔头像 图片。 diff --git a/list.json b/list.json index 4177be3..c273deb 100644 --- a/list.json +++ b/list.json @@ -759,6 +759,16 @@ "supported": true, "des-short": "在贴纸被回复时自动删除贴纸防止被偷取", "des": "在贴纸被回复时自动删除贴纸防止被偷取。\n网速争霸 不保证成功率" + }, + { + "name": "yinglish", + "version": "1.00", + "section": "chat", + "maintainer": "YU", + "size": "1.7 kb", + "supported": true, + "des-short": "能把中文翻译成淫语的翻译机", + "des": "能把中文自动翻译成淫语的翻译机\n 需要 pypi 前置 jieba \n 灵感来自于https://github.com/RimoChan/yinglish \n指令:-yinglish" } ] } diff --git a/yinglish.py b/yinglish.py new file mode 100644 index 0000000..02bf1e8 --- /dev/null +++ b/yinglish.py @@ -0,0 +1,74 @@ +import random +from asyncio import sleep +from sys import executable +from pagermaid import log +from pagermaid.listener import listener +from pagermaid.utils import alias_command, execute + +imported = True +try: + import jieba + import jieba.posseg as pseg + jieba.setLogLevel(20) +except ImportError: + imported = False + + +def chaos (x, y, chaosrate): + if random.random() > chaosrate: + return x + if x in {'[', ']'}: + return '' + if x in {','}: + return '…' + if x in { '!', '!',}: + return '‼‼‼' + if x in { '。'}: + return '❗' + if len(x) > 1 and random.random() < 0.1: + return f'{x[0]}…{x}' + if len(x) > 1 and random.random() < 0.4: + return f'{x[0]}♥{x}' + if y == 'n' and random.random() < 0.1: + x = '⭕' * len(x) + return f'…{x}' + if x in { '\……n', '\♥n'}: + return '\n' + if x in { '…………'}: + return '……' + else: + if y == 'n' and random.random() < 0.2: + x = '⭕' * len(x) + return f'……{x}' + + +def chs2yin(s, chaosrate =0.8): + return ''.join(chaos (x, y, chaosrate) for x, y in pseg.cut(s)) + + +@listener(is_plugin=True, outgoing=True, command=alias_command("yinglish"), + description="能把中文和英文翻译成淫语的翻译机!", + parameters="|要转换的内容") +async def yinglish(context): + if not imported: + try: + await context.edit("支持库 `jieba` 未安装...\n正在尝试自动安装...") + await execute(f'{executable} -m pip install jieba') + await sleep(10) + result = await execute(f'{executable} -m pip show jieba') + if len(result) > 0: + await context.edit('支持库 `jieba` 安装成功...\n正在尝试自动重启...') + await context.client.disconnect() + else: + await context.edit(f"自动安装失败..请尝试手动安装 `{executable} -m pip install jieba` 随后,请重启 PagerMaid-Modify 。") + return + except: + return + if context.text and not context.via_bot and not context.forward and not context.parameter: + await context.edit(f"你没说话我转换个啥") + elif context.text and context.parameter and not context.via_bot and not context.forward: + outputtext=chs2yin(context.arguments) + await context.edit(f"{outputtext}") + await log(f"转换啦!从{context.parameter}变成了{str(outputtext)}!!!") + else : + await context.edit("error")