Beispiel #1
0
async def _(session: CommandSession):
    if session.current_key:
        if session.current_arg_text.strip() in {'算了', '不删了', '取消'}:
            session.finish('好的')
            return

    if not session.current_key and session.current_arg.strip():
        # initial interaction, and there is an argument, we take it as the id
        session.current_key = 'id'

    if session.current_key == 'id':
        try:
            id_ = int(session.current_arg.strip())
            session.args['id'] = id_
        except ValueError:
            session.pause('ID 不正确,应只包含数字,请重新输入')
Beispiel #2
0
async def _(session: CommandSession):
    text = session.current_arg_text.strip()

    if session.is_first_run and text:
        # first run, and there is an argument, we take it as the id
        session.current_key = 'id'

    if session.current_key == 'id':
        id_ = None
        try:
            # try parse the text message as an id
            id_ = int(text)
        except ValueError:
            # it's not directly a number
            if not session.is_first_run:
                # we are in and interactive session, do nlp

                # user may want to ask for all notes, check it
                match_score = await nlp.sentence_similarity(
                    session.current_arg_text.strip(), '现在有哪些呢?')
                if match_score > 0.70:
                    # we think it matches
                    await session.send_expr(expr.QUERYING_ALL)
                    # sleep to make conversation natural :)
                    await asyncio.sleep(1)
                    await call_command(session.bot,
                                       session.ctx, ('note', 'list'),
                                       check_perm=False,
                                       disable_interaction=True)

                    # pause the session and wait for further interaction
                    await session.pause()
                    return

                # user may also put the id in a natural sentence, check it
                m = re.search(r'\d+', text)
                if m:
                    possible_id = int(m.group(0))
                    match_score = await nlp.sentence_similarity(
                        session.current_arg_text.strip(), f'删掉笔记{possible_id}')
                    if match_score > 0.70:
                        # we think it matches
                        id_ = possible_id
        if id_ is not None:
            session.args['id'] = id_
        else:
            session.pause(render(expr.DEL_CANNOT_RECOGNIZE_ID))
Beispiel #3
0
async def _(session: CommandSession):
    striped_text_arg = session.current_arg_text.strip()
    if not striped_text_arg:
        # ignore empty argument
        return

    if not session.current_key:
        session.current_key = 'location'

    if session.current_key == 'location':
        location = await nlp.parse_location(striped_text_arg)
        if any((location.province, location.city, location.district)):
            session.args['location'] = location
    elif session.current_key == 'location_more':
        patched_loc = await nlp.parse_location(striped_text_arg)
        location: nlp.Location = session.args.get('location')
        assert location
        location.province = location.province or patched_loc.province
        location.city = location.city or patched_loc.city
        location.district = location.district or patched_loc.district
        session.args['location'] = location
    else:
        session.args[session.current_key] = striped_text_arg