🐛 xtao-some 修复 wiki 翻译

This commit is contained in:
Xtao_dada 2020-11-28 22:48:42 +08:00 committed by GitHub
parent 96a7e2bf5c
commit 6f91567909
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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