Move out "split_at_xiaokai" filter

This commit is contained in:
Richard Chien
2016-12-31 21:29:55 +08:00
parent c62fafa69e
commit ee7df2ab37
5 changed files with 40 additions and 16 deletions

View File

@ -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

View File

@ -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

View 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)