Exemplo n.º 1
0
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之间的数')
Exemplo n.º 2
0
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范围内的整数')
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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('设定成功')
Exemplo n.º 5
0
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)