async def setmode(session: CommandSession): mode = session.get('mode') gid = session.ctx['group_id'] if mode == 'clr': data = loadjson(gid) try: del data['mode'] except Exception: pass await session.send('默认规则清除成功') dumpjson(gid, data) elif mode == 'show': data = loadjson(gid) try: currentmode = data['mode'] except KeyError: await session.send('当前没有设定规则,默认使用coc规则') return try: currentmode = int(currentmode) except Exception: pass if currentmode in ['coc', 'dnd']: await session.send(f'当前规则是{currentmode}规则') else: await session.send(f'当前默认骰是{currentmode}') elif (mode in ['coc', 'dnd']) or (str(type(mode)) == "<class 'int'>" and 1 <= mode <= 1000): data = loadjson(gid) data['mode'] = mode dumpjson(gid, data) await session.send('设定成功') else: await session.send('请将模式设定为coc,dnd或1-1000范围内的整数')
async def repeat(session: CommandSession): arg = session.current_arg_text if arg == 'off': arg = 0 try: rate = float(arg) except Exception: if arg == '': await session.send('请输入参数,请通过.help rep查看帮助') elif arg == 'show': gid = session.ctx['group_id'] data = loadjson(gid) try: rate = data['repRate'] except Exception: await session.send('当前复读几率为0%') return await session.send(f'当前复读机率为{rate}%') else: await session.send('未知参数,请通过.help rep查看帮助') return role = session.ctx['sender']['role'] if role not in ['owner', 'admin']: await session.send('只有管理员或群主才可使用此命令') return if 0 <= rate <= 100: gid = session.ctx['group_id'] data = loadjson(gid) data['repRate'] = rate dumpjson(gid, data) await session.send('设定成功') else: await session.send('请输入一个在0-100之间的数')
async def draw10(session: CommandSession): uid = str(session.ctx['sender']['user_id']) gid = session.ctx['group_id'] data = loadjson(gid) try: nickname = data['name'][uid] except Exception: nickname = session.ctx['sender']['nickname'] try: with open('.//app_addon//arknights_operators.json', 'r', encoding='utf-8') as f: operators = load(f) except Exception: await session.send('干员数据库读取错误') return output = [] stars = [random.randint(1, 100) for i in range(10)] for i in stars: if 1 <= i <= 40: op = random.choice(operators['3']) output.append(f'【3星】{op}') elif 41 <= i <= 90: op = random.choice(operators['4']) output.append(f'【4星】{op}') elif 91 <= i <= 98: op = random.choice(operators['5']) output.append(f'【5星】{op}') elif i in [99, 100]: op = random.choice(operators['6']) output.append(f'【6星】{op}') await session.send('{}的方舟十连抽出了:\n{}'.format(nickname, '\n'.join(output)))
async def rollInitiative(session: CommandSession): shift = session.get('shift') try: shiftint = int(shift) except Exception: if shift != '': await session.send('请输入一个加/减法算式') return uid = str(session.ctx['sender']['user_id']) gid = session.ctx['group_id'] data = loadjson(gid) try: nickname = data['name'][uid] except Exception: nickname = session.ctx['sender']['nickname'] try: data['initiative'] except Exception: data['initiative'] = {} try: data['initName'] except Exception: data['initName'] = {} init = random.randint(1, 20) data['initName'][uid] = nickname if shift == '': data['initiative'][uid] = init await session.send(f'{nickname}的先攻骰点:\nD20={init}') else: data['initiative'][uid] = init + shiftint if str(shiftint) == shift and not '-' in shift: await session.send(f'{nickname}的先攻骰点:\nD20+调整值={str(init)}+{shift}={init+shiftint}') else: await session.send(f'{nickname}的先攻骰点:\nD20+调整值={str(init)}{shift}={init+shiftint}') dumpjson(gid, data)
async def jrrp(session: CommandSession): uid = str(session.ctx['sender']['user_id']) gid = session.ctx['group_id'] data = loadjson(gid) try: nickname = data['name'][uid] except Exception: nickname = session.ctx['sender']['nickname'] await session.send(f'{nickname}今天的人品值:{random.randint(1,100)}')
async def name(session: CommandSession): name = session.get('name') uid = str(session.ctx['sender']['user_id']) gid = session.ctx['group_id'] data = loadjson(gid) try: data['name'] except Exception: data['name'] = {} data['name'][uid] = name dumpjson(gid, data) await session.send('设定成功')
async def sayagain(session: CommandSession): gid = session.ctx['group_id'] data = loadjson(gid) try: rate = float(data['repRate']/100) except Exception: return if rate == 0.0: return else: text = session.current_arg if random() <= rate: await session.send(text)
async def diceprivate(session: CommandSession): uid = str(session.ctx['sender']['user_id']) gid = session.ctx['group_id'] data = loadjson(gid) try: nickname = data['name'][uid] except Exception: nickname = session.ctx['sender']['nickname'] if session.get('mode') == 'default': defaultdice = 100 try: mode = data['mode'] except Exception: mode = 'coc' if mode == 'dnd': defaultdice = 20 elif mode == 'coc': pass else: defaultdice = int(mode) await session.send( f'{nickname}的D{defaultdice}的结果是:\n{random.randint(1,defaultdice)}', ensure_private=True) await session.send('掷骰结果已私聊发送') elif session.get('mode') == 'INT': try: num = int(session.get('num')) await session.send( f'{nickname}的D{num}的结果是:\n{random.randint(1,num)}', ensure_private=True) await session.send('掷骰结果已私聊发送') except Exception: await session.send('参数不合法,用.help h查看帮助') elif session.get('mode') == 'D': times = int(session.get('times')) num = int(session.get('num')) if not (times > 0 and num > 0): await session.send('参数不合法,用.help h查看帮助') return temp = [str(random.randint(1, num)) for i in range(times)] expression = '+'.join(temp) if times != 1: output = f'{nickname}的{session.current_arg_text.upper()}的结果是:\n{expression}={eval(expression)}' elif times == 1: output = f'{nickname}的{session.current_arg_text.upper()}的结果是:\n{eval(expression)}' await session.send(output, ensure_private=True) await session.send('掷骰结果已私聊发送')
async def readInitiative(session: CommandSession): gid = session.ctx['group_id'] data = loadjson(gid) try: initiative = data['initiative'] except KeyError: await session.send('没有先攻骰点数据') return initiative = sorted(initiative.items(), key=lambda item: item[1], reverse=True) output = [] i = 1 for item in initiative: try: nickname = data['name'][item[0]] except Exception: nickname = data['initName'][item[0]] output.append(f'{i}.{nickname} {item[1]}') i += 1 await session.send('先攻顺序:\n{}'.format('\n'.join(output)))
async def rc(session: CommandSession): mode = session.get('mode') if mode == 'Error': await session.send('指令格式有误,请通过[.help rc]查看帮助') return elif mode == 'NoText': await session.send('请输入技能名') return gid = session.ctx['group_id'] uid = str(session.ctx['sender']['user_id']) data = loadjson(gid) if mode == 'Normal': try: mode = data['mode'] except Exception: mode = 'coc' try: nickname = data['name'][uid] except Exception: nickname = session.ctx['sender']['nickname'] if mode == 'dnd': mod = '' skname = session.get('skname') try: lvl = int(data[uid][skname]) except Exception: await session.send('未设定此属性值') return if 1 <= lvl <= 30: mod = modifier[lvl] elif lvl < 1: mod = '-5' elif lvl > 30: mod = '+10' roll = str(random.randint(1, 20)) expression = ''.join([roll, mod]) await session.send( f'{nickname}的{skname}检定的结果是:\nD20+调整值={expression}={eval(expression)}' ) else: skname = session.get('skname') lvl = 0 if mode == 'custom': lvl = int(session.get('lvl')) else: try: lvl = int(data[uid][skname]) except Exception: await session.send('未设定此属性值') return roll = random.randint(1, 100) out = '' if roll <= 5: out = '大成功' elif roll >= 96: out = '大失败' elif lvl / 2 < roll <= lvl: out = '成功' elif lvl / 5 < roll <= lvl / 2: out = '困难成功' elif roll <= lvl / 5: out = '极难成功' else: out = '失败' await session.send(f'{nickname}的{skname}检定的结果是:\n{roll}/{lvl},{out}')
async def setsp(session: CommandSession): mode = session.get('mode') if mode == 'NoText': await session.send('请输入参数') return uid = str(session.ctx['sender']['user_id']) gid = session.ctx['group_id'] data = loadjson(gid) if mode == 'clr': try: del data[uid] finally: await session.send('删除成功') elif mode == 'change': changelist = session.get('changelist') try: data[uid] except Exception: data[uid] = {} for item in changelist: skname = re.search(r'.+?(?=(\d))', item).group() lvl = re.search(r'(\d)+', item).group() data[uid][skname] = lvl await session.send('设定成功') elif mode == 'shift': try: nickname = data['name'][uid] except Exception: nickname = session.ctx['sender']['nickname'] shiftlist = session.get('shiftlist') try: data[uid] except Exception: await session.send(f'{nickname}未设定属性值') return output = [] for item in shiftlist: skname = re.search(r'.+?(?=[\+\-\*\/])', item).group() try: oglvl = data[uid][skname] except Exception: output.append(f"{skname}:未设定原值") continue shiftlvl = re.search(r'[0-9,\.,\+,\-,\*,\/]+', item).group() newlvl = int(eval(f"{oglvl}{shiftlvl}")) data[uid][skname] = str(newlvl) output.append(f"{skname}:{oglvl}{shiftlvl}={newlvl}") await session.send('{}的属性已更新:\n{}'.format(nickname, '\n'.join(output))) elif mode == 'del': for item in session.get('dellist'): try: del data[uid][item] finally: pass await session.send('删除成功') elif mode == 'show': try: nickname = data['name'][uid] except Exception: nickname = session.ctx['sender']['nickname'] try: data[uid] except Exception: await session.send(f'{nickname}当前未设定任何属性') return output = [] for item in data[uid].keys(): output.append(f'{item}:{data[uid][item]}') await session.send('{}的当前属性:\n{}'.format(nickname, '\n'.join(output))) dumpjson(gid, data)