mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
feat✨: ALAPI
This commit is contained in:
parent
960b665ba4
commit
913811b90d
14
zhenxun/plugins/alapi/__init__.py
Normal file
14
zhenxun/plugins/alapi/__init__.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import nonebot
|
||||||
|
|
||||||
|
from zhenxun.configs.config import Config
|
||||||
|
|
||||||
|
Config.add_plugin_config(
|
||||||
|
"alapi",
|
||||||
|
"ALAPI_TOKEN",
|
||||||
|
None,
|
||||||
|
help="在https://admin.alapi.cn/user/login登录后获取token",
|
||||||
|
)
|
||||||
|
|
||||||
|
nonebot.load_plugins(str(Path(__file__).parent.resolve()))
|
||||||
29
zhenxun/plugins/alapi/_data_source.py
Normal file
29
zhenxun/plugins/alapi/_data_source.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
from zhenxun.configs.config import Config
|
||||||
|
from zhenxun.utils.http_utils import AsyncHttpx
|
||||||
|
|
||||||
|
|
||||||
|
async def get_data(url: str, params: dict | None = None) -> tuple[dict | str, int]:
|
||||||
|
"""获取ALAPI数据
|
||||||
|
|
||||||
|
参数:
|
||||||
|
url: 请求链接
|
||||||
|
params: 参数
|
||||||
|
|
||||||
|
返回:
|
||||||
|
tuple[dict | str, int]: 返回信息
|
||||||
|
"""
|
||||||
|
if not params:
|
||||||
|
params = {}
|
||||||
|
params["token"] = Config.get_config("alapi", "ALAPI_TOKEN")
|
||||||
|
try:
|
||||||
|
data = (await AsyncHttpx.get(url, params=params, timeout=5)).json()
|
||||||
|
if data["code"] == 200:
|
||||||
|
if not data["data"]:
|
||||||
|
return "没有搜索到...", 997
|
||||||
|
return data, 200
|
||||||
|
else:
|
||||||
|
if data["code"] == 101:
|
||||||
|
return "缺失ALAPI TOKEN,请在配置文件中填写!", 999
|
||||||
|
return f'发生了错误...code:{data["code"]}', 999
|
||||||
|
except TimeoutError:
|
||||||
|
return "超时了....", 998
|
||||||
60
zhenxun/plugins/alapi/comments_163.py
Normal file
60
zhenxun/plugins/alapi/comments_163.py
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
from nonebot import on_regex
|
||||||
|
from nonebot.plugin import PluginMetadata
|
||||||
|
from nonebot_plugin_alconna import Alconna, Arparma, on_alconna
|
||||||
|
from nonebot_plugin_saa import Text
|
||||||
|
from nonebot_plugin_session import EventSession
|
||||||
|
|
||||||
|
from zhenxun.configs.utils import PluginExtraData
|
||||||
|
from zhenxun.services.log import logger
|
||||||
|
|
||||||
|
from ._data_source import get_data
|
||||||
|
|
||||||
|
comments_163 = on_regex(
|
||||||
|
"^(网易云热评|网易云评论|到点了|12点了)$", priority=5, block=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
comments_163_url = "https://v2.alapi.cn/api/comment"
|
||||||
|
|
||||||
|
__plugin_meta__ = PluginMetadata(
|
||||||
|
name="网易云热评",
|
||||||
|
description="生了个人,我很抱歉",
|
||||||
|
usage="""
|
||||||
|
到点了,还是防不了下塔
|
||||||
|
指令:
|
||||||
|
网易云热评/到点了/12点了
|
||||||
|
""".strip(),
|
||||||
|
extra=PluginExtraData(
|
||||||
|
author="HibiKier",
|
||||||
|
version="0.1",
|
||||||
|
).dict(),
|
||||||
|
)
|
||||||
|
|
||||||
|
_matcher = on_alconna(
|
||||||
|
Alconna("网易云热评"),
|
||||||
|
priority=5,
|
||||||
|
block=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
_matcher.shortcut(
|
||||||
|
"(到点了|12点了)",
|
||||||
|
command="网易云热评",
|
||||||
|
arguments=[],
|
||||||
|
prefix=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@comments_163.handle()
|
||||||
|
async def _(session: EventSession, arparma: Arparma):
|
||||||
|
data, code = await get_data(comments_163_url)
|
||||||
|
if code != 200 and isinstance(data, str):
|
||||||
|
await Text(data).finish(reply=True)
|
||||||
|
data = data["data"] # type: ignore
|
||||||
|
comment = data["comment_content"] # type: ignore
|
||||||
|
song_name = data["title"] # type: ignore
|
||||||
|
await Text(f"{comment}\n\t——《{song_name}》").send(reply=True)
|
||||||
|
logger.info(
|
||||||
|
f" 发送网易云热评: {comment} \n\t\t————{song_name}",
|
||||||
|
arparma.header_result,
|
||||||
|
session=session,
|
||||||
|
)
|
||||||
45
zhenxun/plugins/alapi/cover.py
Normal file
45
zhenxun/plugins/alapi/cover.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
from nonebot.plugin import PluginMetadata
|
||||||
|
from nonebot_plugin_alconna import Alconna, Args, Arparma, on_alconna
|
||||||
|
from nonebot_plugin_saa import Image, MessageFactory, Text
|
||||||
|
from nonebot_plugin_session import EventSession
|
||||||
|
|
||||||
|
from zhenxun.configs.utils import PluginExtraData
|
||||||
|
from zhenxun.services.log import logger
|
||||||
|
|
||||||
|
from ._data_source import get_data
|
||||||
|
|
||||||
|
cover_url = "https://v2.alapi.cn/api/bilibili/cover"
|
||||||
|
|
||||||
|
__plugin_meta__ = PluginMetadata(
|
||||||
|
name="b封面",
|
||||||
|
description="快捷的b站视频封面获取方式",
|
||||||
|
usage="""
|
||||||
|
b封面 [链接/av/bv/cv/直播id]
|
||||||
|
示例:b封面 av86863038
|
||||||
|
""".strip(),
|
||||||
|
extra=PluginExtraData(
|
||||||
|
author="HibiKier",
|
||||||
|
version="0.1",
|
||||||
|
).dict(),
|
||||||
|
)
|
||||||
|
|
||||||
|
_matcher = on_alconna(
|
||||||
|
Alconna("b封面", Args["url", str]),
|
||||||
|
priority=5,
|
||||||
|
block=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@_matcher.handle()
|
||||||
|
async def _(session: EventSession, arparma: Arparma, url: str):
|
||||||
|
params = {"c": url}
|
||||||
|
data, code = await get_data(cover_url, params)
|
||||||
|
if code != 200 and isinstance(data, str):
|
||||||
|
await Text(data).finish(reply=True)
|
||||||
|
data = data["data"] # type: ignore
|
||||||
|
title = data["title"] # type: ignore
|
||||||
|
img = data["cover"] # type: ignore
|
||||||
|
await MessageFactory([Text(f"title:{title}\n"), Image(img)]).send(reply=True)
|
||||||
|
logger.info(
|
||||||
|
f" 获取b站封面: {title} url:{img}", arparma.header_result, session=session
|
||||||
|
)
|
||||||
48
zhenxun/plugins/alapi/jitang.py
Normal file
48
zhenxun/plugins/alapi/jitang.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
from nonebot.plugin import PluginMetadata
|
||||||
|
from nonebot_plugin_alconna import Alconna, Arparma, on_alconna
|
||||||
|
from nonebot_plugin_saa import Text
|
||||||
|
from nonebot_plugin_session import EventSession
|
||||||
|
|
||||||
|
from zhenxun.configs.utils import PluginExtraData
|
||||||
|
from zhenxun.services.log import logger
|
||||||
|
|
||||||
|
from ._data_source import get_data
|
||||||
|
|
||||||
|
url = "https://v2.alapi.cn/api/soul"
|
||||||
|
|
||||||
|
__plugin_meta__ = PluginMetadata(
|
||||||
|
name="鸡汤",
|
||||||
|
description="喏,亲手为你煮的鸡汤",
|
||||||
|
usage="""
|
||||||
|
不喝点什么感觉有点不舒服
|
||||||
|
指令:
|
||||||
|
鸡汤
|
||||||
|
""".strip(),
|
||||||
|
extra=PluginExtraData(
|
||||||
|
author="HibiKier",
|
||||||
|
version="0.1",
|
||||||
|
).dict(),
|
||||||
|
)
|
||||||
|
|
||||||
|
_matcher = on_alconna(
|
||||||
|
Alconna("鸡汤"),
|
||||||
|
priority=5,
|
||||||
|
block=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@_matcher.handle()
|
||||||
|
async def _(session: EventSession, arparma: Arparma):
|
||||||
|
try:
|
||||||
|
data, code = await get_data(url)
|
||||||
|
if code != 200 and isinstance(data, str):
|
||||||
|
await Text(data).finish(reply=True)
|
||||||
|
await Text(data["data"]["content"]).send(reply=True) # type: ignore
|
||||||
|
logger.info(
|
||||||
|
f" 发送鸡汤:" + data["data"]["content"], # type:ignore
|
||||||
|
arparma.header_result,
|
||||||
|
session=session,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
await Text("鸡汤煮坏掉了...").send()
|
||||||
|
logger.error(f"鸡汤煮坏掉了", e=e)
|
||||||
55
zhenxun/plugins/alapi/poetry.py
Normal file
55
zhenxun/plugins/alapi/poetry.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
from nonebot.plugin import PluginMetadata
|
||||||
|
from nonebot_plugin_alconna import Alconna, Arparma, on_alconna
|
||||||
|
from nonebot_plugin_saa import Text
|
||||||
|
from nonebot_plugin_session import EventSession
|
||||||
|
|
||||||
|
from zhenxun.configs.utils import PluginExtraData
|
||||||
|
from zhenxun.services.log import logger
|
||||||
|
|
||||||
|
from ._data_source import get_data
|
||||||
|
|
||||||
|
__plugin_meta__ = PluginMetadata(
|
||||||
|
name="古诗",
|
||||||
|
description="为什么突然文艺起来了!",
|
||||||
|
usage="""
|
||||||
|
平白无故念首诗
|
||||||
|
示例:念诗/来首诗/念首诗
|
||||||
|
""".strip(),
|
||||||
|
extra=PluginExtraData(
|
||||||
|
author="HibiKier",
|
||||||
|
version="0.1",
|
||||||
|
).dict(),
|
||||||
|
)
|
||||||
|
|
||||||
|
_matcher = on_alconna(
|
||||||
|
Alconna("念诗"),
|
||||||
|
priority=5,
|
||||||
|
block=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
_matcher.shortcut(
|
||||||
|
"(来首诗|念首诗)",
|
||||||
|
command="念诗",
|
||||||
|
arguments=[],
|
||||||
|
prefix=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
poetry_url = "https://v2.alapi.cn/api/shici"
|
||||||
|
|
||||||
|
|
||||||
|
@_matcher.handle()
|
||||||
|
async def _(session: EventSession, arparma: Arparma):
|
||||||
|
data, code = await get_data(poetry_url)
|
||||||
|
if code != 200 and isinstance(data, str):
|
||||||
|
await Text(data).finish(reply=True)
|
||||||
|
data = data["data"] # type: ignore
|
||||||
|
content = data["content"] # type: ignore
|
||||||
|
title = data["origin"] # type: ignore
|
||||||
|
author = data["author"] # type: ignore
|
||||||
|
await Text(f"{content}\n\t——{author}《{title}》").send(reply=True)
|
||||||
|
logger.info(
|
||||||
|
f" 发送古诗: f'{content}\n\t--{author}《{title}》'",
|
||||||
|
arparma.header_result,
|
||||||
|
session=session,
|
||||||
|
)
|
||||||
Loading…
Reference in New Issue
Block a user