mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-28 05:16:48 +08:00
Update demo
This commit is contained in:
parent
6fff0985ae
commit
fb5716c6e4
@ -1,6 +1,7 @@
|
|||||||
from aiocqhttp import Error as CQHttpError
|
from aiocqhttp import Error as CQHttpError
|
||||||
|
|
||||||
from none import on_notice, NoticeSession, on_request, RequestSession
|
from none import on_notice, NoticeSession, on_request, RequestSession
|
||||||
|
from none.helpers import render_expression as __
|
||||||
|
|
||||||
GROUP_GREETING = (
|
GROUP_GREETING = (
|
||||||
'欢迎新同学 {name}[]![CQ:face,id=63][CQ:face,id=63][CQ:face,id=63]',
|
'欢迎新同学 {name}[]![CQ:face,id=63][CQ:face,id=63][CQ:face,id=63]',
|
||||||
@ -18,7 +19,7 @@ async def _(session: NoticeSession):
|
|||||||
info = await session.bot.get_group_member_info(**session.ctx,
|
info = await session.bot.get_group_member_info(**session.ctx,
|
||||||
no_cache=True)
|
no_cache=True)
|
||||||
name = info['card'] or info['nickname'] or '新成员'
|
name = info['card'] or info['nickname'] or '新成员'
|
||||||
await session.send_expr(GROUP_GREETING, name=name, **session.ctx)
|
await session.send(__(GROUP_GREETING, name=name, **session.ctx))
|
||||||
except CQHttpError:
|
except CQHttpError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import asyncio
|
|
||||||
|
|
||||||
from none import (
|
from none import (
|
||||||
on_command, CommandSession,
|
on_command, CommandSession,
|
||||||
on_natural_language, NLPSession, NLPResult
|
on_natural_language, NLPSession, NLPResult
|
||||||
@ -12,7 +10,7 @@ async def tuling(session: CommandSession):
|
|||||||
|
|
||||||
finish = message in ('结束', '拜拜', '再见')
|
finish = message in ('结束', '拜拜', '再见')
|
||||||
if finish:
|
if finish:
|
||||||
asyncio.ensure_future(session.send('拜拜啦,你忙吧,下次想聊天随时找我哦~'))
|
session.finish('拜拜啦,你忙吧,下次想聊天随时找我哦~')
|
||||||
return
|
return
|
||||||
|
|
||||||
# call tuling api
|
# call tuling api
|
||||||
@ -20,10 +18,9 @@ async def tuling(session: CommandSession):
|
|||||||
|
|
||||||
one_time = session.get_optional('one_time', False)
|
one_time = session.get_optional('one_time', False)
|
||||||
if one_time:
|
if one_time:
|
||||||
asyncio.ensure_future(session.send(reply))
|
session.finish(reply)
|
||||||
else:
|
else:
|
||||||
del session.args['message']
|
session.pause(reply)
|
||||||
session.get('message', prompt=reply)
|
|
||||||
|
|
||||||
|
|
||||||
@tuling.args_parser
|
@tuling.args_parser
|
||||||
|
@ -2,16 +2,17 @@ from none import (
|
|||||||
CommandSession, CommandGroup,
|
CommandSession, CommandGroup,
|
||||||
on_natural_language, NLPSession, NLPResult
|
on_natural_language, NLPSession, NLPResult
|
||||||
)
|
)
|
||||||
|
from none.helpers import render_expression as __
|
||||||
|
|
||||||
from . import expressions as expr
|
from . import expressions as e
|
||||||
|
|
||||||
w = CommandGroup('weather')
|
w = CommandGroup('weather')
|
||||||
|
|
||||||
|
|
||||||
@w.command('weather', aliases=('天气', '天气预报'))
|
@w.command('weather', aliases=('天气', '天气预报'))
|
||||||
async def weather(session: CommandSession):
|
async def weather(session: CommandSession):
|
||||||
city = session.get('city', prompt_expr=expr.WHICH_CITY)
|
city = session.get('city', prompt=__(e.WHICH_CITY))
|
||||||
await session.send_expr(expr.REPORT, city=city)
|
await session.send(__(e.REPORT, city=city))
|
||||||
|
|
||||||
|
|
||||||
@weather.args_parser
|
@weather.args_parser
|
||||||
|
Loading…
Reference in New Issue
Block a user