🐛 移除 Gotify 插件及相关配置,更新依赖项版本

This commit is contained in:
远野千束(神羽) 2025-02-18 06:42:42 +08:00
parent 30880ec13b
commit 60093b562b
7 changed files with 6 additions and 167 deletions

View File

@ -11,8 +11,8 @@
import os
import json
import copy
import toml
import yaml
import toml # type: ignore
import yaml # type: ignore
from typing import Any

View File

@ -20,8 +20,8 @@ dependencies = [
"toml>=0.10.2",
"watchdog>=4.0.1",
"pdm-backend>=2.3.3",
"magicoca>=1.0.6",
"croterline>=1.0.9",
"magicoca>=1.0.8",
]
[project.urls]
@ -37,7 +37,6 @@ build-backend = "pdm.backend"
[tool.pdm.build]
includes = ["liteyuki/", "LICENSE", "README.md"]
excludes = ["tests/", "docs/", "src/"]
fallback_version = "0.1.0"
[tool.pdm.version]
source = "scm"

3
scripts/install-deps.sh Normal file
View File

@ -0,0 +1,3 @@
python -m pip install pdm
python -m pdm install
python -m pip install -r requirements.txt

View File

@ -1,109 +0,0 @@
import asyncio
import aiohttp
from nonebot import logger, on_message, Bot
from nonebot.internal.adapter import Event
from nonebot.plugin import PluginMetadata
from nonebot import get_driver
from .adapter_ctx import Context
from .config import plugin_config, Config, NOTICE, MESSAGE
from .gotify import Message, msg_chan, fetch_msg
__plugin_meta__ = PluginMetadata(
name="Gotify",
description="使用Gotify API发送消息",
usage="后台服务插件,无需用户交互",
)
# on plugin load
driver = get_driver()
async def push_thread():
async with aiohttp.ClientSession() as session:
while True:
msg = await fetch_msg()
try:
logger.debug(f"Pushing message: {msg}")
async with session.post(
url=plugin_config.gotify_url + "/message",
params={"token": plugin_config.gotify_token},
data={
"title": msg.title,
"message": msg.message,
"priority": msg.priority,
},
) as resp:
if resp.status != 200:
logger.error(
f"Push message to server failed: {await resp.text()}"
)
else:
logger.info(f"Push message to server success: {msg}")
except Exception as e:
logger.error(f"Push message to server failed: {e}")
@driver.on_startup
async def start_push_thread():
asyncio.create_task(push_thread())
logger.info(
f"Gotify plugin loaded, server: {plugin_config.gotify_url}, token: {plugin_config.gotify_token}"
)
if MESSAGE in plugin_config.gotify_includes:
@on_message(block=False, priority=100).handle()
async def _(event: Event):
ctx = Context(
user_id=event.get_user_id(),
nickname="",
message=event.get_plaintext(),
message_type=event.get_type(),
)
ctx.handle(event)
msg_chan << Message(
title=plugin_config.gotify_title.format(**ctx.model_dump()),
message=plugin_config.gotify_message.format(**ctx.model_dump()),
)
if NOTICE in plugin_config.gotify_includes:
@driver.on_startup
async def startup():
if NOTICE in plugin_config.gotify_includes:
msg_chan << Message(
title=plugin_config.gotify_nickname,
message="Bot started",
priority=plugin_config.gotify_priority,
)
@driver.on_shutdown
async def shutdown():
if NOTICE in plugin_config.gotify_includes:
msg_chan << Message(
title=plugin_config.gotify_nickname,
message="Bot stopped",
priority=plugin_config.gotify_priority,
)
@driver.on_bot_connect
async def bot_connect(bot: Bot):
if NOTICE in plugin_config.gotify_includes:
msg_chan << Message(
title=plugin_config.gotify_nickname,
message=f"Bot connected: {bot.self_id}",
priority=plugin_config.gotify_priority,
)
@driver.on_bot_disconnect
async def bot_disconnect(bot: Bot):
if NOTICE in plugin_config.gotify_includes:
msg_chan << Message(
title=plugin_config.gotify_nickname,
message=f"Bot disconnected: {bot.self_id}",
priority=plugin_config.gotify_priority,
)

View File

@ -1,12 +0,0 @@
from pydantic import BaseModel
class Context(BaseModel):
user_id: str
nickname: str
message: str
message_type: str | None = None
def handle(self, event):
pass

View File

@ -1,22 +0,0 @@
from nonebot import get_plugin_config
from pydantic import BaseModel
NOTICE = "notice"
MESSAGE = "message"
class Config(BaseModel):
# required fields
gotify_token: str
# optional fields
gotify_url: str = "http://127.0.0.1:40266"
gotify_priority: int = 5
gotify_nickname: str = "NoneBot"
gotify_title: str = "{message_type}: {nickname}({user_id})"
gotify_message: str = "{message}"
gotify_includes: list[str, ...] = [NOTICE, MESSAGE]
plugin_config = get_plugin_config(Config)
if plugin_config.gotify_url.endswith("/"):
plugin_config.gotify_url = plugin_config.gotify_url[:-1]

View File

@ -1,20 +0,0 @@
import asyncio
from asyncio import Future
from typing import Any
from magicoca import Chan
from pydantic import BaseModel
from .config import plugin_config
msg_chan = Chan["Message"]()
class Message(BaseModel):
title: str
message: str
priority: int = plugin_config.gotify_priority
def fetch_msg() -> Future[Any]:
return asyncio.get_event_loop().run_in_executor(func=msg_chan.recv, executor=None)