mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-28 16:51:26 +00:00
Move out "split_at_xiaokai" filter
This commit is contained in:
@ -31,22 +31,8 @@ def _load_commands():
|
||||
|
||||
def _dispatch_command(ctx_msg):
|
||||
try:
|
||||
content = ctx_msg.get('content', '')
|
||||
content = ctx_msg.get('content', '').lstrip()
|
||||
source = get_source(ctx_msg)
|
||||
if content.startswith('@'):
|
||||
my_group_nick = ctx_msg.get('receiver')
|
||||
if not my_group_nick:
|
||||
raise SkipException
|
||||
at_me = '@' + my_group_nick
|
||||
if not content.startswith(at_me):
|
||||
raise SkipException
|
||||
content = content[len(at_me):]
|
||||
else:
|
||||
# Not starts with '@'
|
||||
if ctx_msg.get('type') == 'group_message' or ctx_msg.get('type') == 'discuss_message':
|
||||
# And it's a group message, so we don't reply
|
||||
raise SkipException
|
||||
content = content.lstrip()
|
||||
start_flag = None
|
||||
for flag in _command_start_flags:
|
||||
# Match the command start flag
|
@ -6,7 +6,7 @@ def _print_help_message(ctx_msg):
|
||||
a = ['help', '怎么用', '怎么用啊', '你好', '你好啊', '帮助',
|
||||
'用法', '使用帮助', '使用指南', '使用说明', '使用方法',
|
||||
'你能做什么', '你能做些什么', '你会做什么', '你会做些什么']
|
||||
if ctx_msg.get('content', '') in a:
|
||||
if ctx_msg.get('content', '').strip() in a:
|
||||
core.help('', ctx_msg)
|
||||
return False
|
||||
return True
|
22
filters/split_at_xiaokai_50.py
Normal file
22
filters/split_at_xiaokai_50.py
Normal file
@ -0,0 +1,22 @@
|
||||
from filter import add_filter
|
||||
|
||||
|
||||
def _split_at_xiaokai(ctx_msg):
|
||||
if ctx_msg.get('type') == 'group_message' or ctx_msg.get('type') == 'discuss_message':
|
||||
content = ctx_msg.get('content', '')
|
||||
if content.startswith('@'):
|
||||
my_group_nick = ctx_msg.get('receiver')
|
||||
if not my_group_nick:
|
||||
return False
|
||||
at_me = '@' + my_group_nick
|
||||
if not content.startswith(at_me):
|
||||
return False
|
||||
content = content[len(at_me):]
|
||||
else:
|
||||
# Not starts with '@'
|
||||
return False
|
||||
ctx_msg['content'] = content.lstrip()
|
||||
return True
|
||||
|
||||
|
||||
add_filter(_split_at_xiaokai, priority=50)
|
Reference in New Issue
Block a user