Skip to content

Commit

Permalink
feat: init server status plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
StarHeartHunt committed Aug 9, 2024
1 parent 808a896 commit fcf78d0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/plugins/fgo_server_status/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from nonebot.plugin import PluginMetadata

from . import common as common

__plugin_meta__ = PluginMetadata(
"FGO 服务器状态查询", "定时推送及查询 FGO 服务器状态", ""
)
40 changes: 40 additions & 0 deletions src/plugins/fgo_server_status/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import httpx
from nonebot import logger
from nonebot_plugin_alconna import Args, Match, Alconna, on_alconna

from . import __plugin_meta__

server_status = on_alconna(
Alconna("server_status", Args["type?", str]),
aliases={"服务器状态"},
priority=10,
use_cmd_start=True,
)


async def fetch_status(type: str):
match type:
case "国服":
...
case "日服":
...


@server_status.handle()
async def handle_default(type: Match[str]) -> None:
if type.available:
try:
result = await fetch_status(type.result)
except httpx.HTTPError as e:
logger.opt(colors=True, exception=e).error(
"failed to fetch guess from nbnhhsh api"
)
await server_status.finish(f"查询出错,请稍后重试:\n{e}")

if not result:
await server_status.finish("查询结果为空")

await server_status.finish(result)

else:
await server_status.finish(__plugin_meta__.usage)

0 comments on commit fcf78d0

Please sign in to comment.