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("出错了呜呜呜 ~ 找不到目标语言,请更正配置文件中的错误。")