xtao-some 修复 wiki 无法使用的问题

This commit is contained in:
xtaodada 2021-08-04 13:50:38 +08:00
parent 268dae9fd8
commit 9b57f94dab
No known key found for this signature in database
GPG Key ID: EE4DC37B55E24736
2 changed files with 5 additions and 16 deletions

View File

@ -62,13 +62,13 @@
},
{
"name": "xtao-some",
"version": "1.203",
"version": "1.21",
"section": "daily",
"maintainer": "xtaodada",
"size": "18.8 kb",
"size": "12.9 kb",
"supported": true,
"des-short": "一大堆便民功能。",
"des": "超多功能 例如 -ip -ipping -guess -getdel -get_bots 等。"
"des": "超多功能 例如 -ip -ipping -guess -getdel -get_bots -wiki 等。"
},
{
"name": "yb-dl",

View File

@ -42,7 +42,6 @@ async def guess(context):
description="查询维基百科词条",
parameters="<词组>")
async def wiki(context):
lang = config['application_language'].replace('zh-cn', 'zh')
await context.edit("获取中 . . .")
try:
message = await obtain_message(context)
@ -61,18 +60,8 @@ async def wiki(context):
wiki_content = wiki_json['query']['search'][0]['snippet'].replace('<span class=\"searchmatch\">', '**').replace(
'</span>', '**')
wiki_time = wiki_json['query']['search'][0]['timestamp'].replace('T', ' ').replace('Z', ' ')
try:
await context.edit("正在生成翻译中 . . .")
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}
wiki_content = json.loads(requests.get("https://xtaolink.cn/git/m/t.php?lang=" + lang + '&text=' +
clear_emojis(wiki_content), headers=headers)
.content.decode("utf-8"))['data']['target_text']
message = '词条: [' + wiki_title + '](https://zh.wikipedia.org/zh-cn/' + wiki_title + ')\n\n' + \
wiki_content + '...\n\n此词条最后修订于 ' + wiki_time
except ValueError:
await context.edit("出错了呜呜呜 ~ 找不到目标语言,请更正配置文件中的错误。")
return
message = '词条: [' + wiki_title + '](https://zh.wikipedia.org/zh-cn/' + wiki_title + ')\n\n' + \
wiki_content + '...\n\n此词条最后修订于 ' + wiki_time
await context.edit(message)
else:
await context.edit("没有匹配到相关词条")