nonebot-plugin-shiro-web-console 0.1.0__py3-none-any.whl → 0.1.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of nonebot-plugin-shiro-web-console might be problematic. Click here for more details.

@@ -13,7 +13,10 @@ from collections import deque
13
13
  from fastapi import FastAPI, WebSocket, WebSocketDisconnect, Request, Response, Depends, HTTPException
14
14
  from fastapi.staticfiles import StaticFiles
15
15
  from fastapi.responses import HTMLResponse, JSONResponse, FileResponse
16
- from nonebot import get_app, get_bot, get_driver, logger, on_message, on_command
16
+ from nonebot import get_app, get_bot, get_driver, logger, on_message, on_command, require
17
+ require("nonebot_plugin_localstore")
18
+ import nonebot_plugin_localstore
19
+ from .config import Config, config
17
20
  from nonebot.permission import SUPERUSER
18
21
  from nonebot.adapters.onebot.v11 import Bot, MessageEvent, GroupMessageEvent, PrivateMessageEvent, MessageSegment
19
22
  from nonebot.plugin import PluginMetadata
@@ -22,12 +25,13 @@ __plugin_meta__ = PluginMetadata(
22
25
  name="Shiro Web Console",
23
26
  description="通过浏览器查看日志、管理机器人并发送消息",
24
27
  usage="访问 /web_console 查看,在机器人聊天框发送“web控制台”获取登录码",
25
- type="tool",
28
+ type="application",
26
29
  homepage="https://github.com/luojisama/nonebot-plugin-shiro-web-console",
30
+ config=Config,
27
31
  supported_adapters={"~onebot.v11"},
28
32
  extra={
29
33
  "author": "luojisama",
30
- "version": "0.1.0",
34
+ "version": "0.1.6",
31
35
  "pypi_test": "nonebot-plugin-shiro-web-console",
32
36
  },
33
37
  )
@@ -55,8 +59,7 @@ class AuthManager:
55
59
  self.token_expire: Optional[datetime] = None
56
60
 
57
61
  # 密码持久化文件路径
58
- self.data_dir = Path(__file__).parent / "data"
59
- self.data_dir.mkdir(exist_ok=True)
62
+ self.data_dir = nonebot_plugin_localstore.get_plugin_data_dir()
60
63
  self.password_file = self.data_dir / "password.json"
61
64
 
62
65
  # 初始加载密码
@@ -69,7 +72,7 @@ class AuthManager:
69
72
  return data.get("password", "admin123")
70
73
  except:
71
74
  pass
72
- return getattr(get_driver().config, "web_console_password", "admin123")
75
+ return config.web_console_password
73
76
 
74
77
  def save_password(self, new_password: str):
75
78
  self.admin_password = new_password
@@ -122,7 +125,15 @@ async def check_auth(request: Request):
122
125
  raise HTTPException(status_code=401, detail="Unauthorized")
123
126
  return True
124
127
 
125
- app:FastAPI = get_app()
128
+ try:
129
+ app: Optional[FastAPI] = get_app()
130
+ except (ValueError, AssertionError):
131
+ app = None
132
+
133
+ if app is None:
134
+ app = FastAPI()
135
+ logger.warning("FastAPI app not found, created a new one. This might happen during plugin test.")
136
+
126
137
  static_path = Path(__file__).parent / "static"
127
138
  index_html = static_path / "index.html"
128
139
 
@@ -0,0 +1,8 @@
1
+ from nonebot import get_plugin_config
2
+ from pydantic import BaseModel
3
+ from typing import Optional
4
+
5
+ class Config(BaseModel):
6
+ web_console_password: str = "admin123"
7
+
8
+ config = get_plugin_config(Config)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nonebot-plugin-shiro-web-console
3
- Version: 0.1.0
3
+ Version: 0.1.6
4
4
  Summary: 一个用于 NoneBot2 的网页控制台插件,支持通过浏览器查看日志和发送消息
5
5
  Project-URL: Homepage, https://github.com/luojisama/nonebot-plugin-shiro-web-console
6
6
  Project-URL: Bug Tracker, https://github.com/luojisama/nonebot-plugin-shiro-web-console/issues
@@ -24,7 +24,9 @@ Requires-Dist: fastapi>=0.95.0
24
24
  Requires-Dist: httpx>=0.23.0
25
25
  Requires-Dist: jinja2>=3.1.0
26
26
  Requires-Dist: nonebot-adapter-onebot>=2.4.0
27
+ Requires-Dist: nonebot-plugin-localstore>=0.6.0
27
28
  Requires-Dist: nonebot2>=2.2.0
29
+ Requires-Dist: pydantic
28
30
  Requires-Dist: uvicorn>=0.20.0
29
31
  Description-Content-Type: text/markdown
30
32
 
@@ -0,0 +1,7 @@
1
+ nonebot_plugin_shiro_web_console/__init__.py,sha256=YPO-XtylSdnOF3vqEmflOhEbsnZr1xg7Ul46PziSd7o,31567
2
+ nonebot_plugin_shiro_web_console/config.py,sha256=LqHht8N5CuSMyBbEjzyJgfZtg05cvBlpGn_2MgTjt-g,202
3
+ nonebot_plugin_shiro_web_console/static/index.html,sha256=YFQ4e0WsfWYHQ01pD0Xify-CFCcnKE9mXDG6vQimU4s,78428
4
+ nonebot_plugin_shiro_web_console-0.1.6.dist-info/METADATA,sha256=W8H1BPkptruRzqt7FyPZJZlrAjC129F0xh7AiGM7vJE,2010
5
+ nonebot_plugin_shiro_web_console-0.1.6.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
6
+ nonebot_plugin_shiro_web_console-0.1.6.dist-info/licenses/LICENSE,sha256=WedEfsrQQfoZsmbJHIAPn4UY_IcpavYULMV5in_ZPbg,1066
7
+ nonebot_plugin_shiro_web_console-0.1.6.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- nonebot_plugin_shiro_web_console/__init__.py,sha256=9CBXKUq98cujB1g3N0rEw302TNoVqF67FHKX86y9Kf0,31278
2
- nonebot_plugin_shiro_web_console/static/index.html,sha256=YFQ4e0WsfWYHQ01pD0Xify-CFCcnKE9mXDG6vQimU4s,78428
3
- nonebot_plugin_shiro_web_console-0.1.0.dist-info/METADATA,sha256=KlzGn4NfcRYZ-x7DNpzYPPcAsx0dCcrgXlre1K-j4jk,1938
4
- nonebot_plugin_shiro_web_console-0.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
5
- nonebot_plugin_shiro_web_console-0.1.0.dist-info/licenses/LICENSE,sha256=WedEfsrQQfoZsmbJHIAPn4UY_IcpavYULMV5in_ZPbg,1066
6
- nonebot_plugin_shiro_web_console-0.1.0.dist-info/RECORD,,