nonebot-plugin-werewolf 1.1.3__py3-none-any.whl → 1.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.
- nonebot_plugin_werewolf/__init__.py +3 -1
- nonebot_plugin_werewolf/config.py +18 -55
- nonebot_plugin_werewolf/constant.py +20 -58
- nonebot_plugin_werewolf/exception.py +1 -1
- nonebot_plugin_werewolf/game.py +286 -245
- nonebot_plugin_werewolf/matchers/__init__.py +2 -0
- nonebot_plugin_werewolf/matchers/depends.py +50 -0
- nonebot_plugin_werewolf/matchers/edit_preset.py +263 -0
- nonebot_plugin_werewolf/matchers/message_in_game.py +18 -3
- nonebot_plugin_werewolf/matchers/poke/__init__.py +8 -0
- nonebot_plugin_werewolf/matchers/poke/chronocat_poke.py +117 -0
- nonebot_plugin_werewolf/matchers/{ob11_ext.py → poke/ob11_poke.py} +21 -19
- nonebot_plugin_werewolf/matchers/start_game.py +266 -28
- nonebot_plugin_werewolf/matchers/superuser_ops.py +24 -0
- nonebot_plugin_werewolf/models.py +73 -0
- nonebot_plugin_werewolf/player_set.py +33 -34
- nonebot_plugin_werewolf/players/can_shoot.py +15 -20
- nonebot_plugin_werewolf/players/civilian.py +3 -3
- nonebot_plugin_werewolf/players/guard.py +16 -22
- nonebot_plugin_werewolf/players/hunter.py +3 -3
- nonebot_plugin_werewolf/players/idiot.py +4 -4
- nonebot_plugin_werewolf/players/joker.py +8 -4
- nonebot_plugin_werewolf/players/player.py +133 -70
- nonebot_plugin_werewolf/players/prophet.py +8 -15
- nonebot_plugin_werewolf/players/werewolf.py +54 -30
- nonebot_plugin_werewolf/players/witch.py +33 -38
- nonebot_plugin_werewolf/players/wolfking.py +3 -3
- nonebot_plugin_werewolf/utils.py +109 -179
- {nonebot_plugin_werewolf-1.1.3.dist-info → nonebot_plugin_werewolf-1.1.6.dist-info}/METADATA +78 -66
- nonebot_plugin_werewolf-1.1.6.dist-info/RECORD +34 -0
- {nonebot_plugin_werewolf-1.1.3.dist-info → nonebot_plugin_werewolf-1.1.6.dist-info}/WHEEL +1 -1
- nonebot_plugin_werewolf/_timeout.py +0 -110
- nonebot_plugin_werewolf-1.1.3.dist-info/RECORD +0 -29
- {nonebot_plugin_werewolf-1.1.3.dist-info → nonebot_plugin_werewolf-1.1.6.dist-info}/LICENSE +0 -0
- {nonebot_plugin_werewolf-1.1.3.dist-info → nonebot_plugin_werewolf-1.1.6.dist-info}/top_level.txt +0 -0
@@ -1,110 +0,0 @@
|
|
1
|
-
import asyncio
|
2
|
-
import enum
|
3
|
-
import sys
|
4
|
-
from types import TracebackType
|
5
|
-
from typing import final
|
6
|
-
|
7
|
-
if sys.version_info >= (3, 11):
|
8
|
-
from asyncio.timeouts import timeout as timeout
|
9
|
-
|
10
|
-
else:
|
11
|
-
# ruff: noqa: S101
|
12
|
-
|
13
|
-
class _State(enum.Enum):
|
14
|
-
CREATED = "created"
|
15
|
-
ENTERED = "active"
|
16
|
-
EXPIRING = "expiring"
|
17
|
-
EXPIRED = "expired"
|
18
|
-
EXITED = "finished"
|
19
|
-
|
20
|
-
@final
|
21
|
-
class Timeout:
|
22
|
-
def __init__(self, when: float | None) -> None:
|
23
|
-
self._state = _State.CREATED
|
24
|
-
self._timeout_handler: asyncio.Handle | None = None
|
25
|
-
self._task: asyncio.Task | None = None
|
26
|
-
if when is not None:
|
27
|
-
when = asyncio.get_running_loop().time() + when
|
28
|
-
self._when = when
|
29
|
-
|
30
|
-
def when(self) -> float | None:
|
31
|
-
return self._when
|
32
|
-
|
33
|
-
def reschedule(self, when: float | None) -> None:
|
34
|
-
if self._state is not _State.ENTERED:
|
35
|
-
if self._state is _State.CREATED:
|
36
|
-
raise RuntimeError("Timeout has not been entered")
|
37
|
-
raise RuntimeError(
|
38
|
-
f"Cannot change state of {self._state.value} Timeout",
|
39
|
-
)
|
40
|
-
|
41
|
-
self._when = when
|
42
|
-
|
43
|
-
if self._timeout_handler is not None:
|
44
|
-
self._timeout_handler.cancel()
|
45
|
-
|
46
|
-
if when is None:
|
47
|
-
self._timeout_handler = None
|
48
|
-
else:
|
49
|
-
loop = asyncio.get_running_loop()
|
50
|
-
if when <= loop.time():
|
51
|
-
self._timeout_handler = loop.call_soon(self._on_timeout)
|
52
|
-
else:
|
53
|
-
self._timeout_handler = loop.call_at(when, self._on_timeout)
|
54
|
-
|
55
|
-
def expired(self) -> bool:
|
56
|
-
return self._state in (_State.EXPIRING, _State.EXPIRED)
|
57
|
-
|
58
|
-
def __repr__(self) -> str:
|
59
|
-
info = [""]
|
60
|
-
if self._state is _State.ENTERED:
|
61
|
-
when = round(self._when, 3) if self._when is not None else None
|
62
|
-
info.append(f"when={when}")
|
63
|
-
info_str = " ".join(info)
|
64
|
-
return f"<Timeout [{self._state.value}]{info_str}>"
|
65
|
-
|
66
|
-
async def __aenter__(self) -> "Timeout":
|
67
|
-
if self._state is not _State.CREATED:
|
68
|
-
raise RuntimeError("Timeout has already been entered")
|
69
|
-
task = asyncio.current_task()
|
70
|
-
if task is None:
|
71
|
-
raise RuntimeError("Timeout should be used inside a task")
|
72
|
-
self._state = _State.ENTERED
|
73
|
-
self._task = task
|
74
|
-
self.reschedule(self._when)
|
75
|
-
return self
|
76
|
-
|
77
|
-
async def __aexit__(
|
78
|
-
self,
|
79
|
-
exc_type: type[BaseException] | None,
|
80
|
-
exc_val: BaseException | None,
|
81
|
-
exc_tb: TracebackType | None,
|
82
|
-
) -> bool | None:
|
83
|
-
assert self._state in (_State.ENTERED, _State.EXPIRING)
|
84
|
-
|
85
|
-
if self._timeout_handler is not None:
|
86
|
-
self._timeout_handler.cancel()
|
87
|
-
self._timeout_handler = None
|
88
|
-
|
89
|
-
if self._state is _State.EXPIRING:
|
90
|
-
self._state = _State.EXPIRED
|
91
|
-
|
92
|
-
if exc_type is asyncio.CancelledError:
|
93
|
-
raise TimeoutError from exc_val
|
94
|
-
elif self._state is _State.ENTERED:
|
95
|
-
self._state = _State.EXITED
|
96
|
-
|
97
|
-
return None
|
98
|
-
|
99
|
-
def _on_timeout(self) -> None:
|
100
|
-
assert self._state is _State.ENTERED
|
101
|
-
assert self._task is not None
|
102
|
-
self._task.cancel()
|
103
|
-
self._state = _State.EXPIRING
|
104
|
-
self._timeout_handler = None
|
105
|
-
|
106
|
-
def timeout(delay: float | None) -> Timeout:
|
107
|
-
return Timeout(delay)
|
108
|
-
|
109
|
-
|
110
|
-
__all__ = ["timeout"]
|
@@ -1,29 +0,0 @@
|
|
1
|
-
nonebot_plugin_werewolf/__init__.py,sha256=Im_u8hP6N6qA2SwnNSGu1MsewLoyHUa3v0Paj1yC3T0,862
|
2
|
-
nonebot_plugin_werewolf/_timeout.py,sha256=MVkA5oMoxOTV8Luc0BH2QPP8wwz4Tr9CJjeYgiPu_O4,3649
|
3
|
-
nonebot_plugin_werewolf/config.py,sha256=FKQDkb57ujcBYJZX-sLgxWmTVqSeR7T1ywphp7GOCcE,2803
|
4
|
-
nonebot_plugin_werewolf/constant.py,sha256=-S-KjlrSc_wJwsXCkQOMFVqyu4RwR4GLXIRZEp_0mlI,2300
|
5
|
-
nonebot_plugin_werewolf/exception.py,sha256=YSwxeogIB0YJqH9MP1bgxojiu-I_xQE44XnSk5bC1AQ,400
|
6
|
-
nonebot_plugin_werewolf/game.py,sha256=LWxn2OCnkTAF8NdLt1BQzyAtyUfk477xisCf5mbfK_E,17376
|
7
|
-
nonebot_plugin_werewolf/player_set.py,sha256=BlK7wHv_9YrCINMAPWL36TLkRjAiI_GXSHlZySVemoo,2777
|
8
|
-
nonebot_plugin_werewolf/utils.py,sha256=50bJGhJU7b9kQEqmc2V8-5wYkukilDtchZBSBKcwwq4,7633
|
9
|
-
nonebot_plugin_werewolf/matchers/__init__.py,sha256=_MwAZsXlpBLXyzHWqNLTQdMWw9z_O01L5Yo02dzGC9I,88
|
10
|
-
nonebot_plugin_werewolf/matchers/message_in_game.py,sha256=hpQCaNaxCikma8DJTJLCttP5B1vBWlqMDEukSqfPlRk,452
|
11
|
-
nonebot_plugin_werewolf/matchers/ob11_ext.py,sha256=TGhI4yWfb5N3K9hXkI8k8Rs6cMVXDwp05cXtu3a-_jU,2597
|
12
|
-
nonebot_plugin_werewolf/matchers/start_game.py,sha256=DZPQ88hiobuJejIbKsIc8ZcoKDw7wcjawWfTC3wjIto,1884
|
13
|
-
nonebot_plugin_werewolf/players/__init__.py,sha256=djAI5XxR2I-XvnH-lVqX_YCHB_AiT-6jdmwFE1ffN_0,379
|
14
|
-
nonebot_plugin_werewolf/players/can_shoot.py,sha256=6u_luXfNOWO0svTpb78h74HcG65kh1GZyFPJFYNuOG0,2068
|
15
|
-
nonebot_plugin_werewolf/players/civilian.py,sha256=6iKEWRRWDGq1qgVZZZ9pX7kBVpMN-yfxeLq9hIp17hU,165
|
16
|
-
nonebot_plugin_werewolf/players/guard.py,sha256=pDH66q-KoU5oRD-tn542x3siXv9BM824-KRxsVb0Gvk,1408
|
17
|
-
nonebot_plugin_werewolf/players/hunter.py,sha256=nqYGCVppd4mdCPhFHZbjbbNvZfyCNT0bZ3raQFXmELA,203
|
18
|
-
nonebot_plugin_werewolf/players/idiot.py,sha256=7-BTsYUSOcs5rPOJx1hsHPOWcmGcv2rSO8IfUGPdqEE,1456
|
19
|
-
nonebot_plugin_werewolf/players/joker.py,sha256=uUK6EuoOWd8_35yvBTkM14XCplOFwFCRsbhR7bjeiD8,699
|
20
|
-
nonebot_plugin_werewolf/players/player.py,sha256=ejEjbsrIKpUJql3-qLMFsZY_jGFtQ3OTjcN1lFZ4yKo,4697
|
21
|
-
nonebot_plugin_werewolf/players/prophet.py,sha256=nh8eB9T9LMBiqNgnqE-ygAFiYvTZS8bGUKYsNBPm8F0,1078
|
22
|
-
nonebot_plugin_werewolf/players/werewolf.py,sha256=kyZjwijEGG0EkP80VOlu8HFzReg33v8a-o670fZN_xI,2560
|
23
|
-
nonebot_plugin_werewolf/players/witch.py,sha256=P1odgjFc9kAIUxmlz9aV69aYzl76OVcsQQGhigmRTgc,2571
|
24
|
-
nonebot_plugin_werewolf/players/wolfking.py,sha256=hgxOugrIOF6wC5wKcjflPuQ2K4d99eWpF9E69ishbsg,440
|
25
|
-
nonebot_plugin_werewolf-1.1.3.dist-info/LICENSE,sha256=B_WbEqjGr6GYVNfEJPY31T1Opik7OtgOkhRs4Ig3e2M,1064
|
26
|
-
nonebot_plugin_werewolf-1.1.3.dist-info/METADATA,sha256=uLZxheMxeLRL70cOrpZtr1Nqy2gP1sAIFNiiNtkEwi4,10707
|
27
|
-
nonebot_plugin_werewolf-1.1.3.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
28
|
-
nonebot_plugin_werewolf-1.1.3.dist-info/top_level.txt,sha256=wLTfg8sTKbH9lLT9LtU118C9cTspEBJareLsrYM52YA,24
|
29
|
-
nonebot_plugin_werewolf-1.1.3.dist-info/RECORD,,
|
File without changes
|
{nonebot_plugin_werewolf-1.1.3.dist-info → nonebot_plugin_werewolf-1.1.6.dist-info}/top_level.txt
RENAMED
File without changes
|