2018-12-27 20:23:45 +08:00
|
|
|
|
from nonebot import (
|
2018-07-01 17:51:01 +08:00
|
|
|
|
on_command, CommandSession,
|
|
|
|
|
on_natural_language, NLPSession, NLPResult
|
|
|
|
|
)
|
|
|
|
|
|
2019-01-21 10:39:06 +08:00
|
|
|
|
__plugin_name__ = '智能聊天'
|
|
|
|
|
__plugin_usage__ = r"""
|
|
|
|
|
智能聊天功能使用帮助
|
|
|
|
|
|
|
|
|
|
直接跟我聊天即可~
|
|
|
|
|
""".strip()
|
|
|
|
|
|
2018-07-01 17:51:01 +08:00
|
|
|
|
|
|
|
|
|
@on_command('tuling', aliases=('聊天', '对话'))
|
|
|
|
|
async def tuling(session: CommandSession):
|
|
|
|
|
message = session.get('message', prompt='我已经准备好啦,来跟我聊天吧~')
|
|
|
|
|
|
|
|
|
|
finish = message in ('结束', '拜拜', '再见')
|
|
|
|
|
if finish:
|
2018-12-22 12:45:15 +08:00
|
|
|
|
session.finish('拜拜啦,你忙吧,下次想聊天随时找我哦~')
|
2018-07-01 17:51:01 +08:00
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# call tuling api
|
|
|
|
|
reply = f'你说了:{message}'
|
|
|
|
|
|
|
|
|
|
one_time = session.get_optional('one_time', False)
|
|
|
|
|
if one_time:
|
2018-12-22 12:45:15 +08:00
|
|
|
|
session.finish(reply)
|
2018-07-01 17:51:01 +08:00
|
|
|
|
else:
|
2018-12-22 12:45:15 +08:00
|
|
|
|
session.pause(reply)
|
2018-07-01 17:51:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@tuling.args_parser
|
|
|
|
|
async def _(session: CommandSession):
|
|
|
|
|
if session.current_key == 'message':
|
|
|
|
|
session.args[session.current_key] = session.current_arg_text.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@on_natural_language
|
|
|
|
|
async def _(session: NLPSession):
|
2018-07-03 10:32:16 +08:00
|
|
|
|
return NLPResult(60.0, 'tuling', {
|
|
|
|
|
'message': session.msg,
|
|
|
|
|
'one_time': True
|
|
|
|
|
})
|