nonebot-plugin-werewolf 1.0.7__tar.gz → 1.1.0__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 (22) hide show
  1. nonebot_plugin_werewolf-1.0.7/README.md → nonebot_plugin_werewolf-1.1.0/PKG-INFO +28 -3
  2. nonebot_plugin_werewolf-1.0.7/PKG-INFO → nonebot_plugin_werewolf-1.1.0/README.md +14 -16
  3. {nonebot_plugin_werewolf-1.0.7 → nonebot_plugin_werewolf-1.1.0}/nonebot_plugin_werewolf/__init__.py +1 -1
  4. nonebot_plugin_werewolf-1.1.0/nonebot_plugin_werewolf/config.py +86 -0
  5. {nonebot_plugin_werewolf-1.0.7 → nonebot_plugin_werewolf-1.1.0}/nonebot_plugin_werewolf/constant.py +13 -40
  6. nonebot_plugin_werewolf-1.1.0/nonebot_plugin_werewolf/exception.py +19 -0
  7. {nonebot_plugin_werewolf-1.0.7 → nonebot_plugin_werewolf-1.1.0}/nonebot_plugin_werewolf/game.py +102 -69
  8. {nonebot_plugin_werewolf-1.0.7 → nonebot_plugin_werewolf-1.1.0}/nonebot_plugin_werewolf/matchers.py +3 -8
  9. {nonebot_plugin_werewolf-1.0.7 → nonebot_plugin_werewolf-1.1.0}/nonebot_plugin_werewolf/ob11_ext.py +1 -1
  10. {nonebot_plugin_werewolf-1.0.7 → nonebot_plugin_werewolf-1.1.0}/nonebot_plugin_werewolf/player.py +72 -35
  11. {nonebot_plugin_werewolf-1.0.7 → nonebot_plugin_werewolf-1.1.0}/nonebot_plugin_werewolf/player_set.py +9 -3
  12. {nonebot_plugin_werewolf-1.0.7 → nonebot_plugin_werewolf-1.1.0}/nonebot_plugin_werewolf/utils.py +20 -16
  13. nonebot_plugin_werewolf-1.1.0/nonebot_plugin_werewolf.egg-info/PKG-INFO +271 -0
  14. nonebot_plugin_werewolf-1.1.0/nonebot_plugin_werewolf.egg-info/SOURCES.txt +18 -0
  15. nonebot_plugin_werewolf-1.1.0/nonebot_plugin_werewolf.egg-info/dependency_links.txt +1 -0
  16. nonebot_plugin_werewolf-1.1.0/nonebot_plugin_werewolf.egg-info/requires.txt +4 -0
  17. nonebot_plugin_werewolf-1.1.0/nonebot_plugin_werewolf.egg-info/top_level.txt +1 -0
  18. nonebot_plugin_werewolf-1.1.0/pyproject.toml +105 -0
  19. nonebot_plugin_werewolf-1.1.0/setup.cfg +4 -0
  20. nonebot_plugin_werewolf-1.0.7/nonebot_plugin_werewolf/config.py +0 -18
  21. nonebot_plugin_werewolf-1.0.7/pyproject.toml +0 -111
  22. {nonebot_plugin_werewolf-1.0.7 → nonebot_plugin_werewolf-1.1.0}/LICENSE +0 -0
@@ -1,3 +1,17 @@
1
+ Metadata-Version: 2.1
2
+ Name: nonebot-plugin-werewolf
3
+ Version: 1.1.0
4
+ Summary: 适用于 Nonebot2 的狼人杀插件
5
+ Author-email: wyf7685 <wyf7685@163.com>
6
+ License: MIT
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: nonebot2>=2.3.3
11
+ Requires-Dist: nonebot-plugin-alconna>=0.52.1
12
+ Requires-Dist: nonebot-plugin-userinfo>=0.2.6
13
+ Requires-Dist: nonebot-plugin-waiter>=0.7.1
14
+
1
15
  <div align="center">
2
16
  <a href="https://v2.nonebot.dev/store">
3
17
  <img src="https://github.com/wyf7685/wyf7685/blob/main/assets/NoneBotPlugin.svg" width="300" alt="logo">
@@ -14,12 +28,15 @@ _✨ 简单的狼人杀插件 ✨_
14
28
  [![pypi](https://img.shields.io/pypi/v/nonebot-plugin-werewolf?logo=python&logoColor=edb641)](https://pypi.python.org/pypi/nonebot-plugin-werewolf)
15
29
  [![python](https://img.shields.io/badge/python-3.10+-blue?logo=python&logoColor=edb641)](https://www.python.org/)
16
30
 
17
- [![pdm-managed](https://img.shields.io/endpoint?url=https%3A%2F%2Fcdn.jsdelivr.net%2Fgh%2Fpdm-project%2F.github%2Fbadge.json)](https://pdm-project.org)
31
+ [![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
18
32
  [![isort](https://img.shields.io/badge/%20imports-isort-%231674b1)](https://pycqa.github.io/isort/)
19
33
  [![black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
20
34
  [![pyright](https://img.shields.io/badge/types-pyright-797952.svg?logo=python&logoColor=edb641)](https://github.com/Microsoft/pyright)
21
35
  [![ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
22
36
 
37
+ [![NoneBot Registry](https://img.shields.io/endpoint?url=https%3A%2F%2Fnbbdg.lgc2333.top%2Fplugin%2Fnonebot-plugin-werewolf)](https://registry.nonebot.dev/plugin/nonebot-plugin-werewolf:nonebot_plugin_werewolf)
38
+ [![Supported Adapters](https://img.shields.io/endpoint?url=https%3A%2F%2Fnbbdg.lgc2333.top%2Fplugin-adapters%2Fnonebot-plugin-werewolf)](https://registry.nonebot.dev/plugin/nonebot-plugin-werewolf:nonebot_plugin_werewolf)
39
+
23
40
  </div>
24
41
 
25
42
  ## 📖 介绍
@@ -73,7 +90,7 @@ _✨ 简单的狼人杀插件 ✨_
73
90
 
74
91
  ## ⚙️ 配置
75
92
 
76
- 在 nonebot2 项目的`.env`文件中添加下表中的必填配置
93
+ 在 nonebot2 项目的 `.env` 文件中添加如下配置
77
94
 
78
95
  | 配置项 | 必填 | 默认值 | 说明 |
79
96
  | :-----------------------------: | :--: | :----: | :-----------------------------------------------------------: |
@@ -81,6 +98,7 @@ _✨ 简单的狼人杀插件 ✨_
81
98
  | `werewolf__role_preset` | 否 | - | 覆写插件内置的职业预设 |
82
99
  | `werewolf__werewolf_priority` | 否 | - | 自定义狼人职业优先级 |
83
100
  | `werewolf__priesthood_proirity` | 否 | - | 自定义神职职业优先级 |
101
+ | `werewolf__joker_probability` | 否 | `0.0` | 小丑职业替换平民的概率, 范围`[0,1]` |
84
102
 
85
103
  `werewolf__role_preset`, `werewolf__werewolf_priority`, `werewolf__priesthood_proirity` 的配置格式请参考 [`游戏内容`](#游戏内容) 部分
86
104
 
@@ -179,7 +197,7 @@ werewolf__werewolf_priority=[1, 2, 1, 1]
179
197
 
180
198
  上述配置中,`[1, 2, 1, 1]` 表示狼人的职业优先级为 `狼人`, `狼王`, `狼人`, `狼人`
181
199
 
182
- #### 配置项 `werewolf__werewolf_priority`
200
+ #### 配置项 `werewolf__priesthood_proirity`
183
201
 
184
202
  ```env
185
203
  werewolf__priesthood_proirity=[11, 12, 13, 14, 15]
@@ -213,6 +231,13 @@ werewolf__priesthood_proirity=[11, 12, 13, 14, 15]
213
231
 
214
232
  <!-- CHANGELOG -->
215
233
 
234
+ - 2024.09.09 v1.1.0
235
+
236
+ - 新增职业 `小丑`
237
+ - 修复守卫无法保护自己的 bug
238
+ - 添加部分特殊职业的说明
239
+ - 添加游戏过程中的日志输出
240
+
216
241
  - 2024.09.04 v1.0.7
217
242
 
218
243
  - 优先使用群名片作为玩家名
@@ -1,16 +1,3 @@
1
- Metadata-Version: 2.1
2
- Name: nonebot-plugin-werewolf
3
- Version: 1.0.7
4
- Summary: Default template for PDM package
5
- Author-Email: wyf7685 <wyf7685@163.com>
6
- License: MIT
7
- Requires-Python: >=3.10
8
- Requires-Dist: nonebot2>=2.3.3
9
- Requires-Dist: nonebot-plugin-alconna>=0.52.1
10
- Requires-Dist: nonebot-plugin-userinfo>=0.2.6
11
- Requires-Dist: nonebot-plugin-waiter>=0.7.1
12
- Description-Content-Type: text/markdown
13
-
14
1
  <div align="center">
15
2
  <a href="https://v2.nonebot.dev/store">
16
3
  <img src="https://github.com/wyf7685/wyf7685/blob/main/assets/NoneBotPlugin.svg" width="300" alt="logo">
@@ -27,12 +14,15 @@ _✨ 简单的狼人杀插件 ✨_
27
14
  [![pypi](https://img.shields.io/pypi/v/nonebot-plugin-werewolf?logo=python&logoColor=edb641)](https://pypi.python.org/pypi/nonebot-plugin-werewolf)
28
15
  [![python](https://img.shields.io/badge/python-3.10+-blue?logo=python&logoColor=edb641)](https://www.python.org/)
29
16
 
30
- [![pdm-managed](https://img.shields.io/endpoint?url=https%3A%2F%2Fcdn.jsdelivr.net%2Fgh%2Fpdm-project%2F.github%2Fbadge.json)](https://pdm-project.org)
17
+ [![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
31
18
  [![isort](https://img.shields.io/badge/%20imports-isort-%231674b1)](https://pycqa.github.io/isort/)
32
19
  [![black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
33
20
  [![pyright](https://img.shields.io/badge/types-pyright-797952.svg?logo=python&logoColor=edb641)](https://github.com/Microsoft/pyright)
34
21
  [![ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
35
22
 
23
+ [![NoneBot Registry](https://img.shields.io/endpoint?url=https%3A%2F%2Fnbbdg.lgc2333.top%2Fplugin%2Fnonebot-plugin-werewolf)](https://registry.nonebot.dev/plugin/nonebot-plugin-werewolf:nonebot_plugin_werewolf)
24
+ [![Supported Adapters](https://img.shields.io/endpoint?url=https%3A%2F%2Fnbbdg.lgc2333.top%2Fplugin-adapters%2Fnonebot-plugin-werewolf)](https://registry.nonebot.dev/plugin/nonebot-plugin-werewolf:nonebot_plugin_werewolf)
25
+
36
26
  </div>
37
27
 
38
28
  ## 📖 介绍
@@ -86,7 +76,7 @@ _✨ 简单的狼人杀插件 ✨_
86
76
 
87
77
  ## ⚙️ 配置
88
78
 
89
- 在 nonebot2 项目的`.env`文件中添加下表中的必填配置
79
+ 在 nonebot2 项目的 `.env` 文件中添加如下配置
90
80
 
91
81
  | 配置项 | 必填 | 默认值 | 说明 |
92
82
  | :-----------------------------: | :--: | :----: | :-----------------------------------------------------------: |
@@ -94,6 +84,7 @@ _✨ 简单的狼人杀插件 ✨_
94
84
  | `werewolf__role_preset` | 否 | - | 覆写插件内置的职业预设 |
95
85
  | `werewolf__werewolf_priority` | 否 | - | 自定义狼人职业优先级 |
96
86
  | `werewolf__priesthood_proirity` | 否 | - | 自定义神职职业优先级 |
87
+ | `werewolf__joker_probability` | 否 | `0.0` | 小丑职业替换平民的概率, 范围`[0,1]` |
97
88
 
98
89
  `werewolf__role_preset`, `werewolf__werewolf_priority`, `werewolf__priesthood_proirity` 的配置格式请参考 [`游戏内容`](#游戏内容) 部分
99
90
 
@@ -192,7 +183,7 @@ werewolf__werewolf_priority=[1, 2, 1, 1]
192
183
 
193
184
  上述配置中,`[1, 2, 1, 1]` 表示狼人的职业优先级为 `狼人`, `狼王`, `狼人`, `狼人`
194
185
 
195
- #### 配置项 `werewolf__werewolf_priority`
186
+ #### 配置项 `werewolf__priesthood_proirity`
196
187
 
197
188
  ```env
198
189
  werewolf__priesthood_proirity=[11, 12, 13, 14, 15]
@@ -226,6 +217,13 @@ werewolf__priesthood_proirity=[11, 12, 13, 14, 15]
226
217
 
227
218
  <!-- CHANGELOG -->
228
219
 
220
+ - 2024.09.09 v1.1.0
221
+
222
+ - 新增职业 `小丑`
223
+ - 修复守卫无法保护自己的 bug
224
+ - 添加部分特殊职业的说明
225
+ - 添加游戏过程中的日志输出
226
+
229
227
  - 2024.09.04 v1.0.7
230
228
 
231
229
  - 优先使用群名片作为玩家名
@@ -8,7 +8,7 @@ require("nonebot_plugin_waiter")
8
8
  from . import matchers as matchers
9
9
  from .config import Config
10
10
 
11
- __version__ = "1.0.7"
11
+ __version__ = "1.1.0"
12
12
  __plugin_meta__ = PluginMetadata(
13
13
  name="狼人杀",
14
14
  description="适用于 Nonebot2 的狼人杀插件",
@@ -0,0 +1,86 @@
1
+ from typing import Literal, overload
2
+
3
+ from nonebot import get_plugin_config, logger
4
+ from nonebot.compat import PYDANTIC_V2
5
+ from pydantic import BaseModel, Field
6
+ from typing_extensions import Self
7
+
8
+ from .constant import (
9
+ Role,
10
+ default_priesthood_proirity,
11
+ default_role_preset,
12
+ default_werewolf_priority,
13
+ )
14
+
15
+ if PYDANTIC_V2:
16
+ from pydantic import model_validator as model_validator
17
+ else:
18
+ from pydantic import root_validator
19
+
20
+ @overload
21
+ def model_validator(*, mode: Literal["before"]): ... # noqa: ANN201
22
+
23
+ @overload
24
+ def model_validator(*, mode: Literal["after"]): ... # noqa: ANN201
25
+
26
+ def model_validator(*, mode: Literal["before", "after"]):
27
+ return root_validator(
28
+ pre=mode == "before", # pyright: ignore[reportArgumentType]
29
+ allow_reuse=True,
30
+ )
31
+
32
+
33
+ class PluginConfig(BaseModel):
34
+ enable_poke: bool = Field(default=True)
35
+ role_preset: list[tuple[int, int, int, int]] | dict[int, tuple[int, int, int]] = (
36
+ Field(default_factory=default_role_preset.copy)
37
+ )
38
+ werewolf_priority: list[Role] = Field(
39
+ default_factory=default_werewolf_priority.copy
40
+ )
41
+ priesthood_proirity: list[Role] = Field(
42
+ default_factory=default_priesthood_proirity.copy
43
+ )
44
+ joker_probability: float = Field(default=0.0, ge=0.0, le=1.0)
45
+
46
+ @model_validator(mode="after")
47
+ def _validate(self) -> Self:
48
+ if isinstance(self.role_preset, list):
49
+ for preset in self.role_preset:
50
+ if preset[0] != sum(preset[1:]):
51
+ raise RuntimeError(
52
+ "配置项 `role_preset` 错误: "
53
+ f"预设总人数为 {preset[0]}, 实际总人数为 {sum(preset[1:])} "
54
+ f"({', '.join(map(str, preset[1:]))})"
55
+ )
56
+ self.role_preset = default_role_preset | {
57
+ i[0]: i[1:] for i in self.role_preset
58
+ }
59
+ logger.debug(f"覆写配置 role_preset: {self.role_preset}")
60
+
61
+ min_length = max(i[0] for i in self.role_preset.values())
62
+ if len(self.werewolf_priority) < min_length:
63
+ raise RuntimeError(
64
+ f"配置项 `werewolf_priority` 错误: 应至少为 {min_length} 项"
65
+ )
66
+
67
+ min_length = max(i[1] for i in self.role_preset.values())
68
+ if len(self.priesthood_proirity) < min_length:
69
+ raise RuntimeError(
70
+ f"配置项 `priesthood_proirity` 错误: 应至少为 {min_length} 项"
71
+ )
72
+
73
+ return self
74
+
75
+ def get_role_preset(self) -> dict[int, tuple[int, int, int]]:
76
+ if isinstance(self.role_preset, list):
77
+ self.role_preset = {i[0]: i[1:] for i in self.role_preset}
78
+ return self.role_preset
79
+
80
+
81
+ class Config(BaseModel):
82
+ werewolf: PluginConfig = PluginConfig()
83
+
84
+
85
+ config = get_plugin_config(Config).werewolf
86
+ logger.debug(f"加载插件配置: {config}")
@@ -20,6 +20,9 @@ class Role(Enum):
20
20
  Guard = 14
21
21
  Idiot = 15
22
22
 
23
+ # 其他
24
+ Joker = 51
25
+
23
26
  # 平民
24
27
  Civilian = 0
25
28
 
@@ -27,19 +30,21 @@ class Role(Enum):
27
30
  class RoleGroup(Enum):
28
31
  Werewolf = auto()
29
32
  GoodGuy = auto()
33
+ Others = auto()
30
34
 
31
35
 
32
36
  class KillReason(Enum):
33
- Kill = auto()
37
+ Werewolf = auto()
34
38
  Poison = auto()
35
39
  Shoot = auto()
36
40
  Vote = auto()
37
41
 
38
42
 
39
43
  class GameStatus(Enum):
40
- Good = auto()
41
- Bad = auto()
44
+ GoodGuy = auto()
45
+ Werewolf = auto()
42
46
  Unset = auto()
47
+ Joker = auto()
43
48
 
44
49
 
45
50
  @dataclass
@@ -59,12 +64,14 @@ role_name_conv: dict[Role | RoleGroup, str] = {
59
64
  Role.Hunter: "猎人",
60
65
  Role.Guard: "守卫",
61
66
  Role.Idiot: "白痴",
67
+ Role.Joker: "小丑",
62
68
  Role.Civilian: "平民",
63
69
  RoleGroup.Werewolf: "狼人",
64
70
  RoleGroup.GoodGuy: "好人",
71
+ RoleGroup.Others: "其他",
65
72
  }
66
73
 
67
- role_preset: dict[int, tuple[int, int, int]] = {
74
+ default_role_preset: dict[int, tuple[int, int, int]] = {
68
75
  # 总人数: (狼, 神, 民)
69
76
  6: (1, 2, 3),
70
77
  7: (2, 2, 3),
@@ -75,50 +82,16 @@ role_preset: dict[int, tuple[int, int, int]] = {
75
82
  12: (4, 5, 3),
76
83
  }
77
84
 
78
- werewolf_priority: list[Role] = [
85
+ default_werewolf_priority: list[Role] = [
79
86
  Role.Werewolf,
80
87
  Role.Werewolf,
81
88
  Role.WolfKing,
82
89
  Role.Werewolf,
83
90
  ]
84
- priesthood_proirity: list[Role] = [
91
+ default_priesthood_proirity: list[Role] = [
85
92
  Role.Witch,
86
93
  Role.Prophet,
87
94
  Role.Hunter,
88
95
  Role.Guard,
89
96
  Role.Idiot,
90
97
  ]
91
-
92
-
93
- def __apply_config():
94
- from .config import config
95
-
96
- global role_preset, werewolf_priority, priesthood_proirity
97
-
98
- if config.role_preset is not None:
99
- for preset in config.role_preset:
100
- if preset[0] != preset[1:]:
101
- raise RuntimeError(
102
- "配置项 `role_preset` 错误: "
103
- f"预设总人数为 {preset[0]}, 实际总人数为 {sum(preset[1:])}"
104
- )
105
- role_preset |= {i[0]: i[1:] for i in config.role_preset}
106
-
107
- if (priority := config.werewolf_priority) is not None:
108
- min_length = max(i[0] for i in role_preset.values())
109
- if len(priority) < min_length:
110
- raise RuntimeError(
111
- f"配置项 `werewolf_priority` 错误: 应至少为 {min_length} 项"
112
- )
113
- werewolf_priority = priority
114
-
115
- if (priority := config.priesthood_proirity) is not None:
116
- min_length = max(i[1] for i in role_preset.values())
117
- if len(priority) < min_length:
118
- raise RuntimeError(
119
- f"配置项 `priesthood_proirity` 错误: 应至少为 {min_length} 项"
120
- )
121
- priesthood_proirity = priority
122
-
123
-
124
- __apply_config()
@@ -0,0 +1,19 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING
4
+
5
+ if TYPE_CHECKING:
6
+ from .constant import GameStatus
7
+
8
+
9
+ class Error(Exception):
10
+ """插件错误类型基类"""
11
+
12
+
13
+ class GameFinishedError(Error):
14
+ """游戏结束时抛出,无视游戏进程进入结算"""
15
+
16
+ status: GameStatus
17
+
18
+ def __init__(self, status: GameStatus) -> None:
19
+ self.status = status