コード例 #1
0
ファイル: battle.py プロジェクト: knight6236/kyaru-bot
async def clear_current_dmg_records(app: Mirai, member: Member, args: str):
    if not await is_battle(app, member):
        return
    if member.permission == Permission.Member:
        return await reply_group(app, member.group.id, '无权限使用此命令,请联系会长或管理', [member.id])
    g_data: dict = read_guild(member.group.id)
    members = g_data['members']
    current_date = current_date_str()
    if len(args) > 0:
        if re.match(r'[1-9][0-9]{4,}', args):
            if args in members.keys():
                return await clear_my_dmg_records(app, member, args)
            else:
                return await reply_group(app, member.group.id, args + '还未入会')
        elif isVaildDate(args):
            l = args.split('-')
            current_date = '{}-{:0>2s}-{:0>2s}'.format(l[0], l[1], l[2])
        else:
            return await reply_group(app, member.group.id, '格式不合法')
    tmp = ''
    count = 0
    for key in members.keys():
        member_info = members[key]
        tmp += member_info['name'] + ' '
        if 'records' in member_info:
            records = member_info['records']
            if current_date in records:
                record_arr = records[current_date]
                record_arr.clear()
                count += 1
    write_guild(member.group.id, g_data)
    msg = '本次一共清除了 ' + current_date + ' ' + str(count) + ' 人的出刀记录'
    return await reply_group(app, member.group.id, msg, [member.id])
コード例 #2
0
ファイル: battle.py プロジェクト: knight6236/kyaru-bot
async def delete_current_dmg_records(app: Mirai, member: Member, args: str):
    if not await is_battle(app, member):
        return
    if member.permission == Permission.Member:
        return await reply_group(app, member.group.id, '无权限使用此命令,请联系会长或管理', [member.id])
    sp = args.split(' ', maxsplit=1)
    if len(sp) < 2:
        return await reply_group(app, member.group.id, '参数不足,请按照【删除记录 QQ 记录id】的格式重新输入', [member.id])
    if not re.match(r'[1-9][0-9]{4,}', sp[0]):
        return await reply_group(app, member.group.id, 'QQ格式不正确', [member.id])
    if not re.match(r'[0-9]{7}', sp[1]):
        return await reply_group(app, member.group.id, '记录id格式不正确', [member.id])
    g_data: dict = read_guild(member.group.id)
    members = g_data['members']
    current_date = current_date_str()
    if sp[0] not in members:
        return await reply_group(app, member.group.id, sp[0] + '不在公会里', [member.id])
    records = members[sp[0]]['records']
    # print(records)
    if current_date not in records:
        return await reply_group(app, member.group.id, sp[0] + ' ' + current_date + ' 无出刀记录', [member.id])
    current_records = records[current_date]
    flag = True
    for record in current_records:
        if sp[1] == record['id']:
            flag = False
            current_records.remove(record)
    if flag:
        return await reply_group(app, member.group.id, sp[1] + '不在记录里,请确认后再删除', [member.id])
    write_guild(member.group.id, g_data)
    return await reply_group(app, member.group.id, '已将' + sp[0] + '的' + sp[1] + '伤害记录删除', [member.id])
コード例 #3
0
ファイル: battle.py プロジェクト: knight6236/kyaru-bot
async def sl(app: Mirai, member: Member, arg: str, my=False):
    if not await is_battle(app, member):
        return
    g_data: dict = read_guild(member.group.id)
    members = g_data['members']
    memberId = str(member.id)
    if len(arg) > 0:
        if member.permission == Permission.Member:
            return await reply_group(app, member.group.id, '无权限使用此命令,请联系会长或管理', [member.id])
        if not re.match(r'[1-9][0-9]{4,}', arg):
            return await reply_group(app, member.group.id, 'QQ格式不正确', [member.id])
        if arg not in members:
            return await reply_group(app, member.group.id, arg + '不在公会里', [member.id])
        memberId = arg
    member_info = members[memberId]
    if 'sl' not in member_info:
        member_info['sl'] = []
    sl_list: list = member_info['sl']
    current_date = current_date_str()
    if current_date in sl_list:
        return await reply_group(app, member.group.id, member_info['name'] + '今天已经sl过了')
    else:
        if my:
            return await reply_group(app, member.group.id, member_info['name'] + '今天还未sl')
    sl_list.append(current_date)
    write_guild(member.group.id, g_data)
    return await reply_group(app, member.group.id, '已记录' + member_info['name'] + '今天的sl')
コード例 #4
0
ファイル: battle.py プロジェクト: knight6236/kyaru-bot
async def start_battle(app, member: Member, arg):
    if not await is_guild_member(app, member):
        return
    if member.permission == Permission.Member:
        return await reply_group(app, member.group.id, '无权限使用此命令,请联系会长或管理')
    g_data: dict = read_guild(member.group.id)
    if 'server' not in g_data:
        g_data['server'] = 'cn'
        write_guild(member.group.id, g_data)
    guild_data = {'battle_state': '开启', 'report_after_order': '关闭', 'apply_after_order': '关闭', 'current_stage': 1,
                  'current_boss': 1, 'current_loop': 1, 'battling_members': {}, 'tree_members': {},
                  'cache_boss': boss_data[g_data['server']][0][0].copy(),
                  'current_boss_data': boss_data[g_data['server']][0].copy()}
    write_battle(member.group.id, guild_data)
    return await reply_group(app, member.group.id, '会战已开启')
コード例 #5
0
ファイル: battle.py プロジェクト: knight6236/kyaru-bot
async def clear_all_dmg_records(app: Mirai, member: Member, args: str):
    if not await is_battle(app, member):
        return
    if member.permission == Permission.Member:
        return await reply_group(app, member.group.id, '无权限使用此命令,请联系会长或管理', [member.id])
    g_data: dict = read_guild(member.group.id)
    members = g_data['members']
    for key in members.keys():
        member_info = members[key]
        if 'records' in member_info:
            records: dict = member_info['records']
            records.clear()
    write_guild(member.group.id, g_data)
    msg = '本次已清除全部历史出刀记录'
    return await reply_group(app, member.group.id, msg, [member.id])
コード例 #6
0
ファイル: battle.py プロジェクト: knight6236/kyaru-bot
async def clear_my_dmg_records(app: Mirai, member: Member, args: str):
    if not await is_battle(app, member):
        return
    g_data: dict = read_guild(member.group.id)
    members = g_data['members']
    current_date = current_date_str()
    if len(args) > 0:
        member_info = members[args]
        msg = members[args]['name'] + '(' + args + ') ' + current_date
    else:
        member_info = members[str(member.id)]
        msg = member_info['name'] + ' ' + current_date
    if 'records' not in member_info:
        msg += ' 还没有出刀记录\n'
    else:
        records = member_info['records']
        if current_date in records:
            record_arr = records[current_date]
            record_arr.clear()
            write_guild(member.group.id, g_data)
        msg += ' 出刀记录已清除\n'
    return await reply_group(app, member.group.id, msg, [member.id])
コード例 #7
0
ファイル: battle.py プロジェクト: knight6236/kyaru-bot
async def modify_current_dmg_records(app: Mirai, member: Member, args: str):
    if not await is_battle(app, member):
        return
    if member.permission == Permission.Member:
        return await reply_group(app, member.group.id, '无权限使用此命令,请联系会长或管理', [member.id])
    sp = args.split(' ', maxsplit=2)
    if len(sp) < 3:
        return await reply_group(app, member.group.id, '参数不足,请按照【修改记录 QQ 记录id 伤害】的格式重新输入', [member.id])
    if not re.match(r'[1-9][0-9]{4,}', sp[0]):
        return await reply_group(app, member.group.id, 'QQ格式不正确', [member.id])
    if not re.match(r'[0-9]{7}', sp[1]):
        return await reply_group(app, member.group.id, '记录id格式不正确', [member.id])
    g_data: dict = read_guild(member.group.id)
    members = g_data['members']
    current_date = current_date_str()
    if sp[0] not in members:
        return await reply_group(app, member.group.id, sp[0] + '不在公会里', [member.id])
    records = members[sp[0]]['records']
    # print(records)
    if current_date not in records:
        return await reply_group(app, member.group.id, sp[0] + ' ' + current_date + ' 无出刀记录', [member.id])
    current_records = records[current_date]
    flag = True
    for record in current_records:
        if sp[1] == record['id']:
            flag = False
            if check_dmg(sp[2]):
                if sp[2].endswith('*'):
                    record['dmg'] = round(float(sp[2][:len(sp[2]) - 1]), 4)
                    record['tail'] = 1
                else:
                    record['dmg'] = round(float(sp[2]), 4)
                    record['tail'] = 0
            else:
                return await reply_group(app, member.group.id, '伤害值不合法,请重新输入', [member.id])
    if flag:
        return await reply_group(app, member.group.id, sp[1] + '不在记录里,请确认后再修改', [member.id])
    write_guild(member.group.id, g_data)
    return await reply_group(app, member.group.id, '已将' + sp[0] + '的伤害修改为' + sp[2], [member.id])
コード例 #8
0
ファイル: battle.py プロジェクト: knight6236/kyaru-bot
async def report_dmg(app, member, arg: str):
    if not await is_battle(app, member):
        return
    guild_data = read_battle(member.group.id)
    current_boss = guild_data['current_boss']
    boss = guild_data['current_boss_data'][current_boss - 1]
    killers = boss['killers']

    if guild_data['report_after_order'] == '开启' and str(member.id) not in killers:
        return await reply_group(app, member.group, '请先预约再报刀,或者联系管理关闭报刀前预约')

    sp = arg.split(' ', maxsplit=1)
    if len(sp) == 1:
        memberId = str(member.id)
        dmg = sp[0]
    elif len(sp) == 2:
        if not re.match(r'[1-9][0-9]{4,}', sp[0]):
            return await reply_group(app, member.group.id, ILLEGAL_ERR, [member.id])
        g_data: dict = read_guild(member.group.id)
        members = g_data['members']
        if sp[0] not in members.keys():
            return await reply_group(app, member.group.id, sp[0] + '还未入会')
        memberId = sp[0]
        dmg = sp[1]
    if check_dmg(dmg):
        record = {"id": "0", "boss": current_boss, "dmg": 0, "tail": 0}
        if dmg.endswith('*'):
            dmg = dmg[:len(dmg) - 1]
            record['tail'] = 1
        record['dmg'] = float(dmg)

        if float(dmg) > boss['real_hp']:
            return await reply_group(app, member.group.id, '无效数据,伤害不会比剩余血量高, 实际剩余血量:' + str(round(boss['real_hp'], 4)),
                                     [member.id])

        # 记录出刀数据
        g_data: dict = read_guild(member.group.id)
        members = g_data['members']
        current_member = members[memberId]
        records = {}
        if 'records' in current_member:
            records = current_member['records']
        else:
            current_member['records'] = {}
        current_date = current_date_str()
        current_arr = []
        if current_date in records:
            current_arr = records[current_date]

        normal_count = 0
        tail_count = 0
        for ca in current_arr:
            if ca['tail'] == 0:
                normal_count += 1
            elif ca['tail'] == 1:
                tail_count += 1
        if normal_count >= 3 and record['tail'] == 0:
            return await reply_group(app, member.group.id, '每日完整刀不能大于3刀,请重新报刀,或联系管理调整出刀记录', [member.id])
        if tail_count >= 6 and record['tail'] == 1:
            return await reply_group(app, member.group.id, '每日尾刀和补偿刀不能大于6刀,请重新报刀,或联系管理调整出刀记录', [member.id])

        c_count: int = 1
        for m_id in members:
            m_info = members[m_id]
            if 'records' in m_info:
                m_rs = m_info['records']
                if current_date in m_rs:
                    c_arr = m_rs[current_date]
                    c_count += len(c_arr)
        today = datetime.datetime.now().strftime("%m%d")
        current_id = today + '{:0>3s}'.format(str(c_count))
        print_msg(current_id=current_id)
        record['id'] = current_id
        current_arr.append(record)
        records[current_date] = current_arr
        current_member['records'] = records
        write_guild(member.group.id, g_data)

        # print_msg(memberId=memberId, killers=killers)
        if memberId in killers:
            await cancel_boss(app, member, current_boss, False, False, guild_data)

        battling_members = guild_data['battling_members']
        # pprint(battling_members)
        if memberId in battling_members:
            await cancel_battle(app, member, False, guild_data)

        boss['real_hp'] = round(boss['real_hp'] - float(dmg), 4)
        write_battle(member.group.id, guild_data)

        await reply_group(app, member.group.id,
                          '报刀成功, 老' + str(current_boss) + '实际剩余血量:' + str(round(boss['real_hp'], 4)),
                          [member.id])
    else:
        return await reply_group(app, member.group.id, ILLEGAL_ERR, [member.id])