-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
808a896
commit fcf78d0
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 服务器状态", "" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |