async def _(session: CommandSession): striped_text_arg = session.current_arg_text.strip() if not striped_text_arg: # ignore empty argument return if session.is_first_run: 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.state['location'] = location else: session.pause('无法识别你输入的城市哦,请重新输入') elif session.current_key == 'location_more': patched_loc = await nlp.parse_location(striped_text_arg) location: nlp.Location = session.state.get('location') assert location # merge 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.state['location'] = location else: session.state[session.current_key] = striped_text_arg
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(e.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.state['id'] = id_ else: session.pause(expr(e.DEL_CANNOT_RECOGNIZE_ID))
async def _(session: CommandSession): user=session.ctx["sender"]["nickname"] striped_text_arg = session.current_arg_text.strip() if not striped_text_arg: # ignore empty argument return session.current_key = 'item' ##### if session.current_key == 'item': item = striped_text_arg nums = 1 with open(settings.GOODS_LIST, mode='r', encoding='utf-8') as f1, \ open(settings.SHOPPING_CARS, mode='a', encoding='utf-8') as f2: ass='null' for line in f1: iid, commodity, price = line.strip().split('|') if commodity == item: f2.write(f"{user}|{commodity}|{price}|{nums}\n") # print(f'{commodity}已加入购物车!') ass=user+'已将'+commodity+'加入购物车'+'\n' ass+='以上内容用于测试,不代表最终上线品质' ass=str(ass) await session.send(ass) break elif iid == item: f2.write(f"{user}|{commodity}|{price}|{nums}\n") # print(f'{commodity}已加入购物车!') ass=user+'已将'+commodity+'加入购物车'+'\n' ass+='以上内容用于测试,不代表最终上线品质' ass=str(ass) await session.send(ass) break if ass=='null': session.pause('无法识别你输入的商品哦,请重新输入') session.state[session.current_key] = striped_text_arg session.finish()
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