mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-16 19:11:00 +00:00
🏗️ change code structure
This commit is contained in:
@ -3,14 +3,14 @@ from functools import reduce
|
||||
from nonebot.rule import to_me
|
||||
from nonebot.plugin import on_command
|
||||
from nonebot.permission import SUPERUSER
|
||||
from nonebot.adapters.cqhttp import (Bot, Message, MessageEvent, MessageSegment,
|
||||
from nonebot.adapters.cqhttp import (Message, MessageEvent, MessageSegment,
|
||||
unescape)
|
||||
|
||||
say = on_command("say", to_me(), permission=SUPERUSER)
|
||||
|
||||
|
||||
@say.handle()
|
||||
async def say_unescape(bot: Bot, event: MessageEvent):
|
||||
async def say_unescape(event: MessageEvent):
|
||||
|
||||
def _unescape(message: Message, segment: MessageSegment):
|
||||
if segment.is_text():
|
||||
@ -18,12 +18,12 @@ async def say_unescape(bot: Bot, event: MessageEvent):
|
||||
return message.append(segment)
|
||||
|
||||
message = reduce(_unescape, event.get_message(), Message()) # type: ignore
|
||||
await bot.send(message=message, event=event)
|
||||
await say.send(message=message)
|
||||
|
||||
|
||||
echo = on_command("echo", to_me())
|
||||
|
||||
|
||||
@echo.handle()
|
||||
async def echo_escape(bot: Bot, event: MessageEvent):
|
||||
await bot.send(message=event.get_message(), event=event)
|
||||
async def echo_escape(event: MessageEvent):
|
||||
await say.send(message=event.get_message())
|
||||
|
@ -1,7 +1,7 @@
|
||||
from typing import Dict, Optional
|
||||
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.processor import Matcher
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.adapters import Bot, Event
|
||||
from nonebot.message import (IgnoredException, run_preprocessor,
|
||||
run_postprocessor)
|
||||
@ -10,7 +10,7 @@ _running_matcher: Dict[str, int] = {}
|
||||
|
||||
|
||||
@run_preprocessor
|
||||
async def preprocess(matcher: Matcher, bot: Bot, event: Event, state: T_State):
|
||||
async def preprocess(event: Event):
|
||||
try:
|
||||
session_id = event.get_session_id()
|
||||
except Exception:
|
||||
@ -24,8 +24,7 @@ async def preprocess(matcher: Matcher, bot: Bot, event: Event, state: T_State):
|
||||
|
||||
|
||||
@run_postprocessor
|
||||
async def postprocess(matcher: Matcher, exception: Optional[Exception],
|
||||
bot: Bot, event: Event, state: T_State):
|
||||
async def postprocess(event: Event):
|
||||
try:
|
||||
session_id = event.get_session_id()
|
||||
except Exception:
|
||||
|
Reference in New Issue
Block a user