mirror of
https://github.com/TeamPGM/PagerMaid_Plugins_Pyro.git
synced 2024-11-22 09:41:54 +00:00
xtao-some 新增 wiki 功能 (#4)
Co-authored-by: omg-xtao <100690902+omg-xtao@users.noreply.github.com>
This commit is contained in:
parent
3cf21d366e
commit
c332bb9bb2
@ -2,7 +2,7 @@
|
||||
"list": [
|
||||
{
|
||||
"name": "xtao-some",
|
||||
"version": "1.01",
|
||||
"version": "1.02",
|
||||
"section": "daily",
|
||||
"maintainer": "xtaodada",
|
||||
"size": "12.9 kb",
|
||||
|
@ -1,14 +1,13 @@
|
||||
import json
|
||||
|
||||
from pyrogram import Client
|
||||
|
||||
from pagermaid.listener import listener
|
||||
from pagermaid.utils import alias_command, Message, client
|
||||
from pagermaid.utils import Message, client
|
||||
|
||||
|
||||
@listener(is_plugin=True, outgoing=True, command=alias_command("guess"),
|
||||
@listener(is_plugin=True, command="guess",
|
||||
description="能不能好好说话? - 拼音首字母缩写释义工具(需要回复一句话)")
|
||||
async def guess(c: Client, message: Message):
|
||||
async def guess(_: Client, message: Message):
|
||||
text = message.arguments
|
||||
if not text:
|
||||
return await message.edit("请先输入一个缩写。")
|
||||
@ -32,3 +31,32 @@ async def guess(c: Client, message: Message):
|
||||
await message.edit("\n\n".join(guess_res))
|
||||
else:
|
||||
await message.edit("没有匹配到拼音首字母缩写")
|
||||
|
||||
|
||||
@listener(is_plugin=True, command="wiki",
|
||||
description="查询维基百科词条",
|
||||
parameters="<词组>")
|
||||
async def wiki(_: Client, message: Message):
|
||||
message = await message.edit("获取中 . . .")
|
||||
text = message.arguments
|
||||
if not text:
|
||||
return await message.edit("请先输入一个关键词。")
|
||||
try:
|
||||
req = await client.get("https://zh.wikipedia.org/w/api.php?action=query&list=search&format=json&formatversion=2&srsearch=" + message)
|
||||
wiki_json = json.loads(req.content.decode("utf-8"))
|
||||
except:
|
||||
return await message.edit("出错了呜呜呜 ~ 无法访问到维基百科。")
|
||||
try:
|
||||
if not len(wiki_json['query']['search']) == 0:
|
||||
wiki_title = wiki_json['query']['search'][0]['title']
|
||||
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', ' ')
|
||||
text = '词条: [' + wiki_title + '](https://zh.wikipedia.org/zh-cn/' + wiki_title + ')\n\n' + \
|
||||
wiki_content + '...\n\n此词条最后修订于 ' + wiki_time
|
||||
else:
|
||||
text = "没有匹配到相关词条"
|
||||
except KeyError:
|
||||
text = wiki_json['error']['info']
|
||||
await message.edit(text)
|
||||
|
Loading…
Reference in New Issue
Block a user