nonebot-plugin-onebot-luckperms 0.1.1__tar.gz → 0.1.2__tar.gz

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.
Files changed (43) hide show
  1. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/PKG-INFO +1 -1
  2. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/__init__.py +24 -23
  3. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/adapter/permission.py +4 -4
  4. nonebot_plugin_onebot_luckperms-0.1.2/nonebot_plugin_onebot_luckperms/config.py +14 -0
  5. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/core/cache.py +2 -2
  6. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms.egg-info/PKG-INFO +1 -1
  7. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/pyproject.toml +1 -1
  8. nonebot_plugin_onebot_luckperms-0.1.1/nonebot_plugin_onebot_luckperms/config.py +0 -12
  9. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/LICENSE +0 -0
  10. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/README.md +0 -0
  11. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/adapter/__init__.py +0 -0
  12. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/adapter/context.py +0 -0
  13. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/adapter/identity.py +0 -0
  14. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/commands/__init__.py +0 -0
  15. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/commands/admin.py +0 -0
  16. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/core/__init__.py +0 -0
  17. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/core/context_provider.py +0 -0
  18. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/core/engine.py +0 -0
  19. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/core/exceptions.py +0 -0
  20. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/core/models.py +0 -0
  21. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/core/registry.py +0 -0
  22. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/message.py +0 -0
  23. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/py.typed +0 -0
  24. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/storage/__init__.py +0 -0
  25. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/storage/memory.py +0 -0
  26. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/storage/protocol.py +0 -0
  27. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/storage/redis.py +0 -0
  28. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/storage/sqlite.py +0 -0
  29. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/webeditor/__init__.py +0 -0
  30. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/webeditor/bytebin.py +0 -0
  31. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/webeditor/manager.py +0 -0
  32. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/webeditor/session.py +0 -0
  33. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms/webeditor/websocket.py +0 -0
  34. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms.egg-info/SOURCES.txt +0 -0
  35. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms.egg-info/dependency_links.txt +0 -0
  36. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms.egg-info/requires.txt +0 -0
  37. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/nonebot_plugin_onebot_luckperms.egg-info/top_level.txt +0 -0
  38. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/setup.cfg +0 -0
  39. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/tests/test_borderline.py +0 -0
  40. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/tests/test_context.py +0 -0
  41. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/tests/test_models.py +0 -0
  42. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/tests/test_storage.py +0 -0
  43. {nonebot_plugin_onebot_luckperms-0.1.1 → nonebot_plugin_onebot_luckperms-0.1.2}/tests/test_webeditor.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nonebot-plugin-onebot-luckperms
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: LuckPerms-style permission system for NoneBot2 + OneBot
5
5
  License-Expression: MIT
6
6
  Project-URL: Homepage, https://github.com/XChen446/nonebot-plugin-onebot-luckperms
@@ -1,16 +1,30 @@
1
+ from nonebot import get_driver, get_plugin_config, require
1
2
  from nonebot.log import logger
2
3
  from nonebot.plugin import PluginMetadata
3
4
 
5
+ # 依赖插件需在加载时声明:localstore 自身在导入时读取配置,
6
+ # 此时 driver 已由 nonebot.init 初始化完毕,可以安全调用 get_plugin_config。
7
+ require("nonebot_plugin_localstore")
8
+ import nonebot_plugin_localstore as store
9
+
10
+ from .config import OBLPConfig
4
11
  from .core.registry import register_node
5
12
  from .core.models import ContextSet, PermissionNode
6
13
  from .core.context_provider import register_context_provider, ContextProvider
7
14
  from .storage import get_store
8
15
  from .adapter import set_resolver, require, require_any, require_all, get_context
9
16
  from .adapter.context import LPContext
10
- from .config import OBLPConfig
11
17
 
12
18
  __version__ = "0.1.0"
13
19
 
20
+ # 插件配置在加载时读取(而非等待 on_startup)
21
+ plugin_config = get_plugin_config(OBLPConfig)
22
+
23
+ # 数据文件路径在加载时由 localstore 确定
24
+ # (仅创建目录,不创建文件;实际写入在初始化阶段进行)
25
+ PLUGIN_DB_FILE = str(store.get_plugin_data_file("permissions.db"))
26
+ PLUGIN_MESSAGE_FILE = str(store.get_plugin_data_file("messages.yml"))
27
+
14
28
  __plugin_meta__ = PluginMetadata(
15
29
  name="nonebot-plugin-onebot-luckperms",
16
30
  description="LuckPerms-style permission system for NoneBot2 + OneBot",
@@ -81,35 +95,26 @@ async def _init():
81
95
  if _store_initialized:
82
96
  return
83
97
 
84
- from nonebot import require, get_plugin_config
85
- from .config import OBLPConfig
86
98
  from .storage import init_store
87
99
  from .adapter.identity import set_resolver as _set_resolver, OneBotV11Resolver
88
100
  from .commands import register_admin_commands
89
101
  from .message import load_messages, _export_defaults
90
102
 
91
- require("nonebot_plugin_localstore")
92
- import nonebot_plugin_localstore as store
93
-
94
- raw_cfg = get_plugin_config(OBLPConfig)
95
-
96
- store_type = raw_cfg.store_type
103
+ store_type = plugin_config.oblp_store_type
97
104
  kwargs = {}
98
105
  if store_type == "sqlite":
99
- db_file = store.get_plugin_data_file("permissions.db")
100
- kwargs["db_path"] = str(db_file)
106
+ kwargs["db_path"] = PLUGIN_DB_FILE
101
107
  elif store_type == "redis":
102
- kwargs["redis_url"] = raw_cfg.redis_url
108
+ kwargs["redis_url"] = plugin_config.oblp_redis_url
103
109
 
104
- store = init_store(store_type, **kwargs)
105
- await store.load_all()
110
+ backend = init_store(store_type, **kwargs)
111
+ await backend.load_all()
106
112
  _set_resolver(OneBotV11Resolver())
107
113
  register_admin_commands()
108
114
 
109
- message_file = str(store.get_plugin_data_file("messages.yml"))
110
- await load_messages(message_file)
115
+ await load_messages(PLUGIN_MESSAGE_FILE)
111
116
  try:
112
- await _export_defaults(message_file)
117
+ await _export_defaults(PLUGIN_MESSAGE_FILE)
113
118
  except Exception:
114
119
  pass
115
120
 
@@ -117,9 +122,5 @@ async def _init():
117
122
  logger.info(f"OBLP initialized (store: {store_type})")
118
123
 
119
124
 
120
- try:
121
- from nonebot import get_driver
122
- driver = get_driver()
123
- driver.on_startup(_init)
124
- except (ValueError, RuntimeError, ImportError):
125
- logger.debug("NoneBot not initialized, OBLP will init on first use")
125
+ driver = get_driver()
126
+ driver.on_startup(_init)
@@ -24,10 +24,10 @@ def _apply_default_nodes(user: User, identity: Identity) -> list:
24
24
  cfg = get_plugin_config(OBLPConfig)
25
25
  nodes = []
26
26
  role_map = {
27
- "owner": cfg.default_group_owner,
28
- "admin": cfg.default_group_admin,
29
- "member": cfg.default_group_member,
30
- "superuser": cfg.superuser_inherit,
27
+ "owner": cfg.oblp_default_group_owner,
28
+ "admin": cfg.oblp_default_group_admin,
29
+ "member": cfg.oblp_default_group_member,
30
+ "superuser": cfg.oblp_superuser_inherit,
31
31
  }
32
32
  patterns = role_map.get(identity.role, [])
33
33
  for pattern in patterns:
@@ -0,0 +1,14 @@
1
+ from typing import List, Literal
2
+ from pydantic import BaseModel, Field
3
+
4
+
5
+ class OBLPConfig(BaseModel):
6
+ oblp_store_type: Literal["memory", "sqlite", "redis"] = "sqlite"
7
+ oblp_redis_url: str = "redis://localhost:6379/0"
8
+ oblp_default_group_owner: List[str] = Field(
9
+ default_factory=lambda: ["luckperms.help"]
10
+ )
11
+ oblp_default_group_admin: List[str] = Field(default_factory=list)
12
+ oblp_default_group_member: List[str] = Field(default_factory=list)
13
+ oblp_superuser_inherit: List[str] = Field(default_factory=lambda: ["luckperms.*"])
14
+ oblp_cache_ttl: int = 300
@@ -13,7 +13,7 @@ class PermissionCache:
13
13
  def get(cls, key: str) -> Optional[dict]:
14
14
  from nonebot import get_plugin_config
15
15
 
16
- ttl = get_plugin_config(OBLPConfig).cache_ttl
16
+ ttl = get_plugin_config(OBLPConfig).oblp_cache_ttl
17
17
  if ttl <= 0:
18
18
  return None
19
19
  entry = cls._cache.get(key)
@@ -29,7 +29,7 @@ class PermissionCache:
29
29
  def set(cls, key: str, value: dict):
30
30
  from nonebot import get_plugin_config
31
31
 
32
- ttl = get_plugin_config(OBLPConfig).cache_ttl
32
+ ttl = get_plugin_config(OBLPConfig).oblp_cache_ttl
33
33
  if ttl <= 0:
34
34
  return
35
35
  cls._cache[key] = (time.time(), value)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nonebot-plugin-onebot-luckperms
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: LuckPerms-style permission system for NoneBot2 + OneBot
5
5
  License-Expression: MIT
6
6
  Project-URL: Homepage, https://github.com/XChen446/nonebot-plugin-onebot-luckperms
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "nonebot-plugin-onebot-luckperms"
3
- version = "0.1.1"
3
+ version = "0.1.2"
4
4
  description = "LuckPerms-style permission system for NoneBot2 + OneBot"
5
5
  requires-python = ">=3.10"
6
6
  license = "MIT"
@@ -1,12 +0,0 @@
1
- from typing import List, Literal
2
- from pydantic import BaseModel, Field
3
-
4
-
5
- class OBLPConfig(BaseModel):
6
- store_type: Literal["memory", "sqlite", "redis"] = "sqlite"
7
- redis_url: str = "redis://localhost:6379/0"
8
- default_group_owner: List[str] = Field(default_factory=lambda: ["luckperms.help"])
9
- default_group_admin: List[str] = Field(default_factory=list)
10
- default_group_member: List[str] = Field(default_factory=list)
11
- superuser_inherit: List[str] = Field(default_factory=lambda: ["luckperms.*"])
12
- cache_ttl: int = 300