mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-02-20 17:46:51 +08:00
🐛 fix: strip after at bot
This commit is contained in:
parent
6d37417d21
commit
bd7aaa94c6
@ -84,6 +84,9 @@ def _check_at_me(bot: "Bot", event: "Event"):
|
|||||||
if first_msg_seg == at_me_seg:
|
if first_msg_seg == at_me_seg:
|
||||||
event.to_me = True
|
event.to_me = True
|
||||||
del event.message[0]
|
del event.message[0]
|
||||||
|
if event.message[0].type == "text":
|
||||||
|
event.message[0].data["text"] = event.message[0].data[
|
||||||
|
"text"].lstrip()
|
||||||
|
|
||||||
if not event.to_me:
|
if not event.to_me:
|
||||||
# check the last segment
|
# check the last segment
|
||||||
|
@ -151,6 +151,8 @@ def on_command(cmd: Union[str, Tuple[str, ...]],
|
|||||||
|
|
||||||
async def _strip_cmd(bot, event, state: dict):
|
async def _strip_cmd(bot, event, state: dict):
|
||||||
message = event.message
|
message = event.message
|
||||||
|
print(message[0].data)
|
||||||
|
print(state["_prefix"])
|
||||||
event.message = message.__class__(
|
event.message = message.__class__(
|
||||||
str(message)[len(state["_prefix"]["raw_command"]):].strip())
|
str(message)[len(state["_prefix"]["raw_command"]):].strip())
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ nonebot.init()
|
|||||||
app = nonebot.get_asgi()
|
app = nonebot.get_asgi()
|
||||||
|
|
||||||
# load builtin plugin
|
# load builtin plugin
|
||||||
nonebot.load_plugin("nonebot.plugins.base")
|
nonebot.load_builtin_plugins()
|
||||||
|
|
||||||
# load local plugins
|
# load local plugins
|
||||||
nonebot.load_plugins("test_plugins")
|
nonebot.load_plugins("test_plugins")
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from nonebot.rule import to_me
|
||||||
from nonebot.typing import Event
|
from nonebot.typing import Event
|
||||||
from nonebot.plugin import on_message
|
from nonebot.plugin import on_message
|
||||||
from nonebot.adapters.cqhttp import Bot
|
from nonebot.adapters.cqhttp import Bot
|
||||||
|
|
||||||
test_message = on_message(state={"default": 1})
|
test_message = on_message(to_me(), state={"default": 1})
|
||||||
|
|
||||||
|
|
||||||
@test_message.handle()
|
@test_message.handle()
|
||||||
|
15
tests/test_plugins/test_permission.py
Normal file
15
tests/test_plugins/test_permission.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from nonebot.rule import to_me
|
||||||
|
from nonebot.typing import Event
|
||||||
|
from nonebot.plugin import on_startswith
|
||||||
|
from nonebot.adapters.cqhttp import Bot
|
||||||
|
from nonebot.permission import GROUP_ADMIN
|
||||||
|
|
||||||
|
test_command = on_startswith("hello", to_me(), permission=GROUP_ADMIN)
|
||||||
|
|
||||||
|
|
||||||
|
@test_command.handle()
|
||||||
|
async def test_handler(bot: Bot, event: Event, state: dict):
|
||||||
|
await test_command.finish("hello")
|
Loading…
x
Reference in New Issue
Block a user