async def add_challenge(session: CommandSession): ''' 这个命令最常用,需要给沙雕群友优化一下语法 ----> 简易版本见 add_challenge_e ''' parser = ArgumentParser(session=session, usage='dmg -r -b damage [--uid] [--alt] [--ext | --last | --timeout]\n对3周目的老五造成114514点伤害:\n【 dmg 114514 -r3 -b5 】\n帮骑士A出了尾刀收了4周目带善人:\n【 dmg 1919810 -r4 -b1 --last --uid [骑士A的QQ] 】') parser.add_argument('-r', '--round', type=int) parser.add_argument('-b', '--boss', type=int) parser.add_argument('damage', type=int, default=-1) parser.add_argument('--uid', type=int, default=-1) parser.add_argument('--alt', type=int, default=0) flag_group = parser.add_mutually_exclusive_group() flag_group.add_argument('--ext', action='store_true') flag_group.add_argument('--last', action='store_true') flag_group.add_argument('--timeout', action='store_true') args = parser.parse_args(session.argv) flag = BattleMaster.NORM if args.last: flag = BattleMaster.LAST elif args.ext: flag = BattleMaster.EXT elif args.timeout: flag = BattleMaster.TIMEOUT args.damage = 0 challenge = { 'round': args.round, 'boss': args.boss, 'damage': args.damage, 'uid': args.uid, 'alt': args.alt, 'flag': flag } await process_challenge(session, challenge)
async def ls(session: CommandSession): parser = ArgumentParser(session=session) switch = parser.add_mutually_exclusive_group() switch.add_argument('-g', '--group', action='store_true') switch.add_argument('-f', '--friend', action='store_true') switch.add_argument('-b', '--bot', action='store_true') switch.add_argument('-s', '--service') args = parser.parse_args(session.argv) if args.group: await ls_group(session) elif args.friend: await ls_friend(session) elif args.bot: await ls_bot(session) elif args.service: await ls_service(session, args.service)
async def notebook(session: CommandSession): if session.is_first_run: parser = ArgumentParser(session=session, usage=NOTEUSAGE) group = parser.add_mutually_exclusive_group() group.add_argument("-a", "--add", type=str, nargs="+", help="添加记录") group.add_argument("-l", "--list", action="store_true", help="查看记录") group.add_argument("-d", "--delt", type=str, help="删除记录") group.add_argument("-c", "--cls", action="store_true", help="清空记录") group.add_argument("-ls", "--listsort", action="store_true") args = parser.parse_args(session.argv) else: stripped_arg = session.current_arg_text.strip() if not session.is_first_run and ( not stripped_arg and stripped_arg != "是" and stripped_arg != "否" ): session.pause("要输入「是」或者「否」中的一个哦。") if session.is_first_run and args.add != None: args.add = " ".join(args.add) if len(args.add) > 50: session.finish("呀,记录的长度不能超过 50 哦~") if args.add[0] == "*": session.finish("哦,当前并不支持以「*」开头的记录哦~") async with db.pool.acquire() as conn: try: values = await conn.fetch( f"""select noteind from quser where qid = {session.event.user_id};""" ) ind = values[0]["noteind"] except IndexError: await conn.execute( """insert into quser (qid,swid) values ({0},{1});""".format( session.event.user_id, swFormatter( session.event.sender["card"] if session.event["message_type"] != "private" else "-1" ), ) ) values = await conn.fetch( f"""select noteind from quser where qid = {session.event.user_id};""" ) ind = values[0]["noteind"] try: state = await conn.execute( """insert into notebook (qid,item,ind) values ({0},'{1}',{2});""".format( session.event.user_id, args.add, ind ) ) except asyncpg.exceptions.ForeignKeyViolationError as e: await conn.execute( """insert into quser (qid,swid) values ({0},{1});""".format( session.event.user_id, swFormatter( session.event.sender["card"] if session.event["message_type"] != "private" else "-1" ), ) ) state = await conn.execute( """insert into notebook (qid,item,ind) values ({0},'{1}',{2});""".format( session.event.user_id, args.add, ind ) ) except asyncpg.exceptions.UniqueViolationError as e: session.finish("你已经添加过该记录啦!") await conn.execute( f"""update quser set noteind = {ind + 1} where qid={session.event.user_id}""" ) session.finish("记录:{0} 添加完毕!".format(args.add)) elif session.is_first_run and args.list == True: async with db.pool.acquire() as conn: values = await conn.fetch( """select * from notebook where qid={0} order by ind;""".format( session.event.user_id ) ) if len(values) == 0: session.finish("并没有找到任何记录,蛮遗憾的。") log = "\n" for item in values: if item["ind"] % 10 == 0 and item["ind"] != 0: await session.send(log[2:]) log = "\n" log += "\n{0}. {1}".format(item["ind"] + 1, item["item"]) await session.send(log[2:]) session.finish("以上") elif session.is_first_run and args.listsort == True: async with db.pool.acquire() as conn: values = await conn.fetch( """select * from notebook where qid={0} order by item;""".format( session.event.user_id ) ) if len(values) == 0: session.finish("并没有找到任何记录,蛮遗憾的。") log = "\n" for item in values: if item["ind"] % 10 == 0 and item["ind"] != 0: await session.send(log[2:]) log = "\n" log += "\n{0}. {1}".format(item["ind"] + 1, item["item"]) await session.send(log[2:]) session.finish("以上") elif "del" in session.state or (session.is_first_run and args.delt != None): async with db.pool.acquire() as conn: if session.is_first_run: flg = 0 if args.delt[0] == "*": try: args.delt = int(args.delt[1:]) - 1 flg = 1 except: session.finish("「*」开头的记录表示记录序列号哦。") values = await conn.fetch( """select * from notebook where qid={0} and ind = '{1}';""".format( session.event.user_id, args.delt ) ) else: values = await conn.fetch( """select * from notebook where qid={0} and item = '{1}';""".format( session.event.user_id, args.delt ) ) if len(values) == 0: session.finish( "貌似,并没有找到该记录?你输入的记录为 {0}".format( args.delt if flg == 0 else f"序列号:{args.delt + 1}" ) ) item = values[0]["item"] session.state["del"] = item session.state["delind"] = values[0]["ind"] session.pause(f"确定要删除「{item}」吗?(请输入「是」或「否」)") if stripped_arg == "是": state = await conn.execute( """delete from notebook where qid={0} and item = '{1}'; update notebook set ind = ind - 1 where ind > {2} and qid={0}; update quser set noteind = noteind - 1 where qid = {0};""".format( session.event.user_id, session.state["del"], session.state["delind"], ) ) session.finish("确认删除「{}」了!".format(session.state["del"])) else: session.finish("删除撤销!") elif "cls" in session.state or (session.is_first_run and args.cls == True) == True: if session.is_first_run: session.state["cls"] = 1 session.pause("确定要清空所有记录吗?(请输入「是」或「否」)") if stripped_arg == "是": async with db.pool.acquire() as conn: state = await conn.execute( """delete from notebook where qid={0}; update quser set noteind = 0 where qid = {0};""".format( session.event.user_id ) ) session.finish("完 全 清 空 !") else: session.finish("删除撤销!")
async def _(session: CommandSession): if session.is_first_run: parser = ArgumentParser(session=session) subparser = parser.add_mutually_exclusive_group() subparser.add_argument("-s", "--subs", nargs="+", help="订阅指定的 rss 源") subparser.add_argument("-r", "--route", nargs="+", help="获取自定路由的 rss 源的资讯") subparser.add_argument("-d", "--delete", nargs="+", help="删除 rss 订阅") subparser.add_argument("-l", "--list", action="store_true", default=False, help="列出已订阅的源") subparser.add_argument("-a", "--add", help="开通rss源") parser.add_argument("rss", nargs="*", help="获取已存在的 rss 源资讯") argv = parser.parse_args(session.current_arg_text.strip().split(" ")) session.state["ls"] = [] session.state["list"] = argv.list if argv.list: return if argv.subs != None: session.state["subs"] = argv.subs ls = argv.subs if argv.delete != None: session.state["del"] = argv.delete ls = argv.delete if argv.rss != []: session.state["rss"] = argv.rss ls = argv.rss if argv.route != None: session.state["route"] = argv.route session.state["ls"] = argv.route if len(session.state["ls"]) == 0: session.finish("查询路由地址不能为空哦!") return if argv.add != None: await session.send(str(session.event.user_id)) result = await add_rss(argv.add.strip(), str(session.event.user_id)) session.finish(result) ls = list(set(ls)) if session.event.detail_type == "group": async with db.pool.acquire() as conn: values = await conn.fetch( "select safe from mg where gid = {}".format( session.event.group_id)) if len(values) > 0 and values[0]["safe"]: ls = [i for i in ls if "r18" not in i] for key in doc: if key in ls[:]: session.state["ls"].append((gtfun(key), key)) ls.remove(key) if len(ls) > 0 and " ".join(ls).strip() != "": await session.send( unescape("没有添加「{}」的订阅源!请联系".format(" ".join(ls)) + cq.at(545870222) + "添加订阅!")) if len(session.state["ls"]) == 0: await session.send( "本次资讯{}为空哦!".format("查看" if session.state["rss"] != [] else "订阅")) session.finish( AutoReply( "Rss 指令帮助菜单", "以下是 rss 指令支持的源", [(i, j) for i, j in doc.items() if "r18" not in i], ))