mirror of
https://github.com/TeamPGM/PagerMaid_Plugins_Pyro.git
synced 2024-11-22 11:06:37 +00:00
This commit is contained in:
parent
8df760475b
commit
a07818e20d
@ -1 +1,8 @@
|
|||||||
命令:wbrs,zhrs,dyrs。
|
命令:resou
|
||||||
|
|
||||||
|
- resou zhihu
|
||||||
|
- resou wb
|
||||||
|
- resou dy
|
||||||
|
- resou baidu
|
||||||
|
- resou b
|
||||||
|
- resou tt
|
138
resou/main.py
138
resou/main.py
@ -1,58 +1,96 @@
|
|||||||
from pyrogram import Client
|
from enum import Enum
|
||||||
from json.decoder import JSONDecodeError
|
from typing import Dict, Any
|
||||||
|
|
||||||
|
from pagermaid.enums import Message
|
||||||
|
from pagermaid.enums.command import CommandHandler
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
from pagermaid.utils import Message, client
|
from pagermaid.services import client
|
||||||
|
|
||||||
|
|
||||||
@listener(command="zhrs", description="知乎热搜。")
|
class TypeEnum(str, Enum):
|
||||||
async def zhrs(_: Client, message: Message):
|
ZHIHU = "知乎"
|
||||||
req = await client.get("https://tenapi.cn/zhihuresou/")
|
WB = "微博"
|
||||||
if req.status_code == 200:
|
DY = "抖音"
|
||||||
try:
|
BAIDU = "百度"
|
||||||
data = req.json()
|
B = "哔哩哔哩"
|
||||||
except JSONDecodeError:
|
TT = "今日头条"
|
||||||
await message.edit("出错了呜呜呜 ~ API 数据解析失败。")
|
|
||||||
return
|
|
||||||
res = "知乎实时热搜榜:\n"
|
RESOU_HELP = """热搜榜单
|
||||||
for i in range(10):
|
|
||||||
res += f'\n{i + 1}.「<a href={data["list"][i]["url"]}>{data["list"][i]["query"]}</a>」'
|
- 参数 zhihu 查询知乎热搜
|
||||||
await message.edit(res)
|
- 参数 wb 查询微博热搜
|
||||||
else:
|
- 参数 dy 查询抖音热搜
|
||||||
|
- 参数 baidu 查询百度热搜
|
||||||
|
- 参数 b 查询哔哩哔哩
|
||||||
|
- 参数 tt 查询今日头条热点
|
||||||
|
"""
|
||||||
|
RESOU_MAP = {
|
||||||
|
TypeEnum.ZHIHU: "https://tenapi.cn/v2/zhihuhot",
|
||||||
|
TypeEnum.WB: "https://tenapi.cn/v2/weibohot",
|
||||||
|
TypeEnum.DY: "https://tenapi.cn/v2/douyinhot",
|
||||||
|
TypeEnum.BAIDU: "https://tenapi.cn/v2/baiduhot",
|
||||||
|
TypeEnum.B: "https://tenapi.cn/v2/bilihot",
|
||||||
|
TypeEnum.TT: "https://tenapi.cn/v2/toutiaohot"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def get_data(name_type: TypeEnum) -> Dict[str, Any]:
|
||||||
|
url = RESOU_MAP.get(name_type)
|
||||||
|
try:
|
||||||
|
data = (await client.get(url)).json()["data"]
|
||||||
|
except Exception as e:
|
||||||
|
return {"error": str(e)}
|
||||||
|
res = ""
|
||||||
|
for i, d in enumerate(data):
|
||||||
|
if i == 10:
|
||||||
|
break
|
||||||
|
res += f"\n{i + 1}. 「<a href={d['url']}>{d['name']}</a>」"
|
||||||
|
return {"error": None, "data": data, "text": res}
|
||||||
|
|
||||||
|
|
||||||
|
@listener(command="resou", description="热搜榜单查询")
|
||||||
|
async def resou_handler(message: Message):
|
||||||
|
await message.edit(RESOU_HELP)
|
||||||
|
|
||||||
|
|
||||||
|
resou_handler: "CommandHandler"
|
||||||
|
|
||||||
|
|
||||||
|
async def rs_handler(message: Message, name_type: TypeEnum):
|
||||||
|
data = await get_data(name_type)
|
||||||
|
if data.get("error"):
|
||||||
await message.edit("出错了呜呜呜 ~ 无法访问到 API 服务器 。")
|
await message.edit("出错了呜呜呜 ~ 无法访问到 API 服务器 。")
|
||||||
|
return
|
||||||
|
res = f"{name_type.value}实时热搜榜:\n{data['text']}"
|
||||||
|
await message.edit(res)
|
||||||
|
|
||||||
|
|
||||||
@listener(command="wbrs", description="微博热搜。")
|
@resou_handler.sub_command(command="zhihu", description="知乎热搜")
|
||||||
async def wbrs(_: Client, message: Message):
|
async def zhrs(message: Message):
|
||||||
req = await client.get("https://tenapi.cn/resou/")
|
await rs_handler(message, TypeEnum.ZHIHU)
|
||||||
if req.status_code == 200:
|
|
||||||
try:
|
|
||||||
data = req.json()
|
|
||||||
except JSONDecodeError:
|
|
||||||
await message.edit("出错了呜呜呜 ~ API 数据解析失败。")
|
|
||||||
return
|
|
||||||
res = "微博实时热搜榜:\n"
|
|
||||||
for i in range(10):
|
|
||||||
res += (
|
|
||||||
f'\n{i + 1}.「<a href={data["list"][i]["url"]}>{data["list"][i]["name"]}</a>」 '
|
|
||||||
f'热度:{data["list"][i]["hot"]}'
|
|
||||||
)
|
|
||||||
await message.edit(res)
|
|
||||||
else:
|
|
||||||
await message.edit("出错了呜呜呜 ~ 无法访问到 API 服务器 。")
|
|
||||||
|
|
||||||
|
|
||||||
@listener(command="dyrs", description="抖音热搜。")
|
@resou_handler.sub_command(command="wb", description="微博热搜。")
|
||||||
async def dyrs(_: Client, message: Message):
|
async def wbrs(message: Message):
|
||||||
req = await client.get("https://tenapi.cn/douyinresou/")
|
await rs_handler(message, TypeEnum.WB)
|
||||||
if req.status_code == 200:
|
|
||||||
try:
|
|
||||||
data = req.json()
|
@resou_handler.sub_command(command="dy", description="抖音热搜。")
|
||||||
except JSONDecodeError:
|
async def dyrs(message: Message):
|
||||||
await message.edit("出错了呜呜呜 ~ API 数据解析失败。")
|
await rs_handler(message, TypeEnum.DY)
|
||||||
return
|
|
||||||
res = "抖音实时热搜榜:\n"
|
|
||||||
for i in range(10):
|
@resou_handler.sub_command(command="baidu", description="百度热搜。")
|
||||||
res += f'\n{i + 1}.「{data["list"][i]["name"]}」 热度:{data["list"][i]["hot"]}'
|
async def bdrs(message: Message):
|
||||||
await message.edit(res)
|
await rs_handler(message, TypeEnum.BAIDU)
|
||||||
else:
|
|
||||||
await message.edit("出错了呜呜呜 ~ 无法访问到 API 服务器 。")
|
|
||||||
|
@resou_handler.sub_command(command="b", description="哔哩哔哩热搜。")
|
||||||
|
async def brs(message: Message):
|
||||||
|
await rs_handler(message, TypeEnum.B)
|
||||||
|
|
||||||
|
|
||||||
|
@resou_handler.sub_command(command="tt", description="今日头条热点。")
|
||||||
|
async def ttrs(message: Message):
|
||||||
|
await rs_handler(message, TypeEnum.TT)
|
||||||
|
Loading…
Reference in New Issue
Block a user