From 25b0bafa5a33613f507d8afb0d4c8cf87eef4816 Mon Sep 17 00:00:00 2001 From: StarStar-Lab <35412541+StarStar-Lab@users.noreply.github.com> Date: Sun, 25 Apr 2021 14:55:41 +0800 Subject: [PATCH] =?UTF-8?q?xtao-some=20=E7=BF=BB=E8=AF=91=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89=E8=AF=AD=E8=A8=80=20(#155)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list.json | 2 +- xtao-some.py | 29 +++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/list.json b/list.json index 1eaeea5..ab512e1 100644 --- a/list.json +++ b/list.json @@ -62,7 +62,7 @@ }, { "name": "xtao-some", - "version": "1.154", + "version": "1.16", "section": "daily", "maintainer": "xtaodada", "size": "18.8 kb", diff --git a/xtao-some.py b/xtao-some.py index a189d32..756769e 100644 --- a/xtao-some.py +++ b/xtao-some.py @@ -216,8 +216,9 @@ async def ipping(context): @listener(is_plugin=True, outgoing=True, command="t", - description="通过腾讯AI开放平台将目标消息翻译成指定的语言。", - parameters="<文本>") + description="通过腾讯AI开放平台将目标消息翻译成指定的语言。" + "目前支持的语言有 zh, en, jp, kr, fr, es, it, de, tr, ru, pt, vi, id, ms, th。", + parameters="<回复消息/文本> <指定语言>") async def tx_t(context): """ PagerMaid universal translator. """ reply = await context.get_reply_message() @@ -225,14 +226,30 @@ async def tx_t(context): lang = 'zh' 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} - if message: - pass - elif reply: + api_lang = ['zh', 'en', 'jp', 'kr', 'fr', 'es', 'it', 'de', 'tr', 'ru', 'pt', 'vi', 'id', 'ms', 'th'] + if reply: message = reply.text + if context.parameter: + if re.search(r'[a-z]{2}', context.parameter[0]): + if context.parameter[0] in api_lang: + lang = context.parameter[0] + else: + await context.edit("指定语言未支持,使用默认语言") + else: + await context.edit("未指定语言,使用默认语言") + elif context.parameter: + message = context.parameter[0] + try: + if re.search(r'[a-z]{2}', context.parameter[1]): + if context.parameter[1] in api_lang: + lang = context.parameter[1] + else: + await context.edit("指定语言未支持,使用默认语言") + except IndexError: + await context.edit("未指定语言,使用默认语言") else: await context.edit("出错了呜呜呜 ~ 无效的参数。") return - try: await context.edit("正在生成翻译中 . . .") tx_json = json.loads(requests.get(