yinglish 能把中文翻译成淫语的翻译机 (#179)

Co-authored-by: Xtao_dada <xtao@xtaolink.cn>
This commit is contained in:
gchengyu 2021-08-21 00:30:57 +08:00 committed by GitHub
parent 0cc5f31381
commit cfac5c26c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 85 additions and 0 deletions

View File

@ -67,6 +67,7 @@
- `paolu` : 一键跑路(删所有消息并禁言)。
- `keyword` : 群组关键词自动回复插件。
- `msgst` : 每天定时发送消息。
- `yinglish` : 能把中文翻译成淫语的翻译机.
- profile (资料类)
- `autochangename` : 自动更新 last_name 为时间等。
- `throwit` : 生成一张 扔头像 图片。

View File

@ -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"
}
]
}

74
yinglish.py Normal file
View File

@ -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="<message>|要转换的内容")
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")