async def contactViewTrees(app: App, e: ContactMessageRecvEvent): record = userdb(userid=e.sender.id) empty = True if len(record) > 0: reply = "你的树林里有以下树木👇\n" bag = record[0]['bag'] ids = list(bag.keys()) ids.sort(reverse=True) for treeId in ids: cnt = bag[treeId] if cnt > 0: empty = False item = getItemDetail(treeId) reply += f" 【{getQualityDescription(item['quality'])}】{item['name']}×{cnt}\n" reply = reply[:-1] if empty: app.replyContactMessage(e.sender, "哎呀,你的树林空空如也呢,快去种树吧~") else: app.replyContactMessage(e.sender, reply)
async def sessionHandler(app: App, e: ContactMessageRecvEvent): sender = e.sender contactId = e.sender.id message = str(e.msg).strip() session = sessions.getSession(contactId) step = session.step() if step == 1: options = session.get('options') optionCnt = session.get('optionCnt') if str.isdigit(message): id = int(message) if 1 <= id <= optionCnt: app.replyContactMessage(sender, ("你确定嘛?\n" "输入“确定”放弃种树,输入其他内容取消操作")) session.set('groupId', options[id]) session.next() else: app.replyContactMessage(sender, "范围要正确哦~") elif message == "取消": app.replyContactMessage(sender, "取消啦~") sessions.closeSession(contactId) app.unredirect(str(contactId)) else: app.replyContactMessage(sender, "输入的内容不正确~") elif step == 2: if message == "确定": app.replyContactMessage(sender, "臭水群怪,给你解除禁言了喔~") groupId = session.get('groupId') plantComplete(app, groupId, contactId, type='cancel') sessions.closeSession(contactId) app.unredirect(str(contactId)) crontab.remove(f'{groupId}.{contactId}') else: app.replyContactMessage(sender, "未输入确定,操作取消啦~继续专注喔~") sessions.closeSession(contactId) app.unredirect(str(contactId))
async def unplantCommand(app: App, e: ContactMessageRecvEvent): async def sessionHandler(app: App, e: ContactMessageRecvEvent): sender = e.sender contactId = e.sender.id message = str(e.msg).strip() session = sessions.getSession(contactId) step = session.step() if step == 1: options = session.get('options') optionCnt = session.get('optionCnt') if str.isdigit(message): id = int(message) if 1 <= id <= optionCnt: app.replyContactMessage(sender, ("你确定嘛?\n" "输入“确定”放弃种树,输入其他内容取消操作")) session.set('groupId', options[id]) session.next() else: app.replyContactMessage(sender, "范围要正确哦~") elif message == "取消": app.replyContactMessage(sender, "取消啦~") sessions.closeSession(contactId) app.unredirect(str(contactId)) else: app.replyContactMessage(sender, "输入的内容不正确~") elif step == 2: if message == "确定": app.replyContactMessage(sender, "臭水群怪,给你解除禁言了喔~") groupId = session.get('groupId') plantComplete(app, groupId, contactId, type='cancel') sessions.closeSession(contactId) app.unredirect(str(contactId)) crontab.remove(f'{groupId}.{contactId}') else: app.replyContactMessage(sender, "未输入确定,操作取消啦~继续专注喔~") sessions.closeSession(contactId) app.unredirect(str(contactId)) sender = e.sender contactId = e.sender.id session = sessions.createSession(contactId) records = db(memberId=contactId) if len(records) == 0: app.replyContactMessage(sender, "你没有在种的树哦~") return options: Dict[int, int] = {} reply = '' optCnt = 0 for r in records: optCnt += 1 options[optCnt] = r['groupId'] reply += f'{optCnt}. {r["groupName"]}\n' session.set('options', options) session.set('optionCnt', optCnt) session.next() app.replyContactMessage( sender, Message.phrase(("你有以下几个正在种树的群\n" + reply + "请输入序号(仅数字)\n" "输入“取消”继续种树"))) guid = str(contactId) app.redirectContact(guid, contactId, sessionHandler)