mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-06-14 08:08:16 +00:00
commit
f036057b2b
@ -69,7 +69,7 @@ async def handle2(bot: Bot, event: Event, state: T_State):
|
|||||||
```python
|
```python
|
||||||
@matcher.got("key1")
|
@matcher.got("key1")
|
||||||
@matcher.got("key2")
|
@matcher.got("key2")
|
||||||
async def handle(bot: Bot, event: Event, state: State):
|
async def handle(bot: Bot, event: Event, state: T_State):
|
||||||
pass
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -169,12 +169,12 @@ matcher = on_command("test")
|
|||||||
|
|
||||||
# 修改默认参数处理
|
# 修改默认参数处理
|
||||||
@matcher.args_parser
|
@matcher.args_parser
|
||||||
async def parse(bot: Bot, event: Event, state: State):
|
async def parse(bot: Bot, event: Event, state: T_State):
|
||||||
print(state["_current_key"], ":", str(event.get_message()))
|
print(state["_current_key"], ":", str(event.get_message()))
|
||||||
state[state["_current_key"]] = str(event.get_message())
|
state[state["_current_key"]] = str(event.get_message())
|
||||||
|
|
||||||
@matcher.handle()
|
@matcher.handle()
|
||||||
async def first_receive(bot: Bot, event: Event, state: State):
|
async def first_receive(bot: Bot, event: Event, state: T_State):
|
||||||
# 获取用户原始命令,如:/test
|
# 获取用户原始命令,如:/test
|
||||||
print(state["_prefix"]["raw_command"])
|
print(state["_prefix"]["raw_command"])
|
||||||
# 处理用户输入参数,如:/test arg1 arg2
|
# 处理用户输入参数,如:/test arg1 arg2
|
||||||
@ -186,7 +186,7 @@ async def first_receive(bot: Bot, event: Event, state: State):
|
|||||||
|
|
||||||
|
|
||||||
@matcher.got("arg1", prompt="参数?")
|
@matcher.got("arg1", prompt="参数?")
|
||||||
async def arg_handle(bot: Bot, event: Event, state: State):
|
async def arg_handle(bot: Bot, event: Event, state: T_State):
|
||||||
# 在这里对参数进行验证
|
# 在这里对参数进行验证
|
||||||
if state["arg1"] not in ["allow", "list"]:
|
if state["arg1"] not in ["allow", "list"]:
|
||||||
await matcher.reject("参数不正确!请重新输入")
|
await matcher.reject("参数不正确!请重新输入")
|
@ -21,7 +21,7 @@ async def handle_first_receive(bot: Bot, event: Event, state: T_State):
|
|||||||
|
|
||||||
|
|
||||||
@weather.got("city", prompt="你想查询哪个城市的天气呢?")
|
@weather.got("city", prompt="你想查询哪个城市的天气呢?")
|
||||||
async def handle_city(bot: Bot, event: Event, state: State):
|
async def handle_city(bot: Bot, event: Event, state: T_State):
|
||||||
city = state["city"]
|
city = state["city"]
|
||||||
if city not in ["上海", "北京"]:
|
if city not in ["上海", "北京"]:
|
||||||
await weather.reject("你想查询的城市暂不支持,请重新输入!")
|
await weather.reject("你想查询的城市暂不支持,请重新输入!")
|
||||||
@ -115,16 +115,17 @@ rule 的出现使得 nonebot 对事件的响应可以非常自由,nonebot 内
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
from nonebot.rule import Rule
|
from nonebot.rule import Rule
|
||||||
|
from nonebot.typing import T_State
|
||||||
|
|
||||||
async def async_checker(bot: Bot, event: Event, state: State) -> bool:
|
async def async_checker(bot: Bot, event: Event, state: T_State) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def sync_checker(bot: Bot, event: Event, state: State) -> bool:
|
def sync_checker(bot: Bot, event: Event, state: T_State) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def check(arg1, args2):
|
def check(arg1, args2):
|
||||||
|
|
||||||
async def _checker(bot: Bot, event: Event, state: State) -> bool:
|
async def _checker(bot: Bot, event: Event, state: T_State) -> bool:
|
||||||
return bool(arg1 + arg2)
|
return bool(arg1 + arg2)
|
||||||
|
|
||||||
return Rule(_check)
|
return Rule(_check)
|
@ -1,4 +1,4 @@
|
|||||||
[
|
[
|
||||||
"2.0.0a8",
|
"2.0.0a8.post1",
|
||||||
"2.0.0a7"
|
"2.0.0a7"
|
||||||
]
|
]
|
@ -69,7 +69,7 @@ async def handle2(bot: Bot, event: Event, state: T_State):
|
|||||||
```python
|
```python
|
||||||
@matcher.got("key1")
|
@matcher.got("key1")
|
||||||
@matcher.got("key2")
|
@matcher.got("key2")
|
||||||
async def handle(bot: Bot, event: Event, state: State):
|
async def handle(bot: Bot, event: Event, state: T_State):
|
||||||
pass
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -169,12 +169,12 @@ matcher = on_command("test")
|
|||||||
|
|
||||||
# 修改默认参数处理
|
# 修改默认参数处理
|
||||||
@matcher.args_parser
|
@matcher.args_parser
|
||||||
async def parse(bot: Bot, event: Event, state: State):
|
async def parse(bot: Bot, event: Event, state: T_State):
|
||||||
print(state["_current_key"], ":", str(event.get_message()))
|
print(state["_current_key"], ":", str(event.get_message()))
|
||||||
state[state["_current_key"]] = str(event.get_message())
|
state[state["_current_key"]] = str(event.get_message())
|
||||||
|
|
||||||
@matcher.handle()
|
@matcher.handle()
|
||||||
async def first_receive(bot: Bot, event: Event, state: State):
|
async def first_receive(bot: Bot, event: Event, state: T_State):
|
||||||
# 获取用户原始命令,如:/test
|
# 获取用户原始命令,如:/test
|
||||||
print(state["_prefix"]["raw_command"])
|
print(state["_prefix"]["raw_command"])
|
||||||
# 处理用户输入参数,如:/test arg1 arg2
|
# 处理用户输入参数,如:/test arg1 arg2
|
||||||
@ -186,7 +186,7 @@ async def first_receive(bot: Bot, event: Event, state: State):
|
|||||||
|
|
||||||
|
|
||||||
@matcher.got("arg1", prompt="参数?")
|
@matcher.got("arg1", prompt="参数?")
|
||||||
async def arg_handle(bot: Bot, event: Event, state: State):
|
async def arg_handle(bot: Bot, event: Event, state: T_State):
|
||||||
# 在这里对参数进行验证
|
# 在这里对参数进行验证
|
||||||
if state["arg1"] not in ["allow", "list"]:
|
if state["arg1"] not in ["allow", "list"]:
|
||||||
await matcher.reject("参数不正确!请重新输入")
|
await matcher.reject("参数不正确!请重新输入")
|
||||||
|
@ -21,7 +21,7 @@ async def handle_first_receive(bot: Bot, event: Event, state: T_State):
|
|||||||
|
|
||||||
|
|
||||||
@weather.got("city", prompt="你想查询哪个城市的天气呢?")
|
@weather.got("city", prompt="你想查询哪个城市的天气呢?")
|
||||||
async def handle_city(bot: Bot, event: Event, state: State):
|
async def handle_city(bot: Bot, event: Event, state: T_State):
|
||||||
city = state["city"]
|
city = state["city"]
|
||||||
if city not in ["上海", "北京"]:
|
if city not in ["上海", "北京"]:
|
||||||
await weather.reject("你想查询的城市暂不支持,请重新输入!")
|
await weather.reject("你想查询的城市暂不支持,请重新输入!")
|
||||||
@ -115,16 +115,17 @@ rule 的出现使得 nonebot 对事件的响应可以非常自由,nonebot 内
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
from nonebot.rule import Rule
|
from nonebot.rule import Rule
|
||||||
|
from nonebot.typing import T_State
|
||||||
|
|
||||||
async def async_checker(bot: Bot, event: Event, state: State) -> bool:
|
async def async_checker(bot: Bot, event: Event, state: T_State) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def sync_checker(bot: Bot, event: Event, state: State) -> bool:
|
def sync_checker(bot: Bot, event: Event, state: T_State) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def check(arg1, args2):
|
def check(arg1, args2):
|
||||||
|
|
||||||
async def _checker(bot: Bot, event: Event, state: State) -> bool:
|
async def _checker(bot: Bot, event: Event, state: T_State) -> bool:
|
||||||
return bool(arg1 + arg2)
|
return bool(arg1 + arg2)
|
||||||
|
|
||||||
return Rule(_check)
|
return Rule(_check)
|
||||||
|
@ -184,7 +184,7 @@ class GroupMessageEvent(MessageEvent):
|
|||||||
__event__ = "message.group"
|
__event__ = "message.group"
|
||||||
message_type: Literal["group"]
|
message_type: Literal["group"]
|
||||||
group_id: int
|
group_id: int
|
||||||
anonymous: Anonymous
|
anonymous: Optional[Anonymous] = None
|
||||||
|
|
||||||
@overrides(Event)
|
@overrides(Event)
|
||||||
def get_event_description(self) -> str:
|
def get_event_description(self) -> str:
|
||||||
@ -319,6 +319,7 @@ class PokeNotifyEvent(NotifyEvent):
|
|||||||
__event__ = "notice.notify.poke"
|
__event__ = "notice.notify.poke"
|
||||||
sub_type: Literal["poke"]
|
sub_type: Literal["poke"]
|
||||||
target_id: int
|
target_id: int
|
||||||
|
group_id: Optional[int] = None
|
||||||
|
|
||||||
@overrides(Event)
|
@overrides(Event)
|
||||||
def is_tome(self) -> bool:
|
def is_tome(self) -> bool:
|
||||||
|
@ -28,7 +28,8 @@ class ActionFailed(BaseActionFailed, CQHTTPAdapterException):
|
|||||||
self.info = kwargs
|
self.info = kwargs
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<ActionFailed " + ", ".join(f"{k=}" for k in self.info) + ">"
|
return f"<ActionFailed " + ", ".join(
|
||||||
|
f"{k}={v}" for k, v in self.info.items()) + ">"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.__repr__()
|
return self.__repr__()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "nonebot2"
|
name = "nonebot2"
|
||||||
version = "2.0.0-alpha.8"
|
version = "2.0.0-alpha.8.post1"
|
||||||
description = "An asynchronous python bot framework."
|
description = "An asynchronous python bot framework."
|
||||||
authors = ["yanyongyu <yanyongyu_1@126.com>"]
|
authors = ["yanyongyu <yanyongyu_1@126.com>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user