Esempio n. 1
0
def perm_check(session: CommandSession,
               permunit: str,
               Remotely: dict = None,
               user: bool = False):
    if Remotely != None:
        return permissiongroup.perm_check(Remotely['message_type'],
                                          Remotely['sent_id'], permgroupname,
                                          permunit)
    elif user:
        return permissiongroup.perm_check('private', session.event['user_id'],
                                          permgroupname, permunit)
    return permissiongroup.perm_check(
        session.event['message_type'],
        (session.event['group_id'] if session.event['message_type'] == 'group'
         else session.event['user_id']), permgroupname, permunit)
async def permDel(session: CommandSession):
    message_type = session.event['message_type']
    #group_id = (session.event['group_id'] if message_type == 'group' else None)
    user_id = session.event['user_id']
    if message_type != 'private':
        return
    #if perm_check(session,'-listener',user = True):
    #    await session.send('操作被拒绝,权限不足(p)')
    #    return
    logger.info(CQsessionToStr(session))
    arglimit = [
        {
            'name':'groupname', #参数名
            'des':'权限组名', #参数错误描述
            'type':'str', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理)
            'strip':True, #是否strip
            'lower':False, #是否转换为小写
            'default':None, #默认值
            'func':None, #函数,当存在时使用函数进行二次处理
            're':None, #正则表达式匹配(match函数)
            'vlimit':{ 
                #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值
            }
        },
        {
            'name':'perm_unit', #参数名
            'des':'权限组名', #参数错误描述
            'type':'str', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理)
            'strip':True, #是否strip
            'lower':False, #是否转换为小写
            'default':'', #默认值
            'func':None, #函数,当存在时使用函数进行二次处理
            're':None, #正则表达式匹配(match函数)
            'vlimit':{ 
                #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值
            }
        },
        {
            'name':'msgtype', #参数名
            'des':'消息类型', #参数错误描述
            'type':'str', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理)
            'strip':True, #是否strip
            'lower':True, #是否转换为小写
            'default':message_type, #默认值
            'func':None, #函数,当存在时使用函数进行二次处理
            're':None, #正则表达式匹配(match函数)
            'vlimit':{ 
                #参数限制表(限制参数内容,空表则不限制),'*':''表示允许任意字符串,值不为空时任意字符串将被转变为这个值
                '私聊':'private',
                'private':'private',
                '群聊':'group',
                'group':'group',
                '好友':'private',
                '群':'group',
            }
        },
        {
            'name':'send_id', #参数名
            'des':'对象ID', #参数错误描述
            'type':'int', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理)
            'strip':True, #是否strip
            'lower':False, #是否转换为小写
            'default':user_id, #默认值
            'func':None, #函数,当存在时使用函数进行二次处理
            're':None, #正则表达式匹配(match函数)
            'vlimit':{ 
                #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值
            }
        }
    ]
    res = argDeal(session.current_arg_text.strip(),arglimit)
    if not res[0]:
        await session.send(res[1]+'=>'+res[2])
        return
    args = res[1]
    if args['perm_unit'] == '':
        args['perm_unit'] = None

    if perm_check(args['msgtype'],args['send_id'],args['groupname'],args['perm_unit']):
        await session.send("该权限已存在!")
        return
    res = perm_del(args['msgtype'],args['send_id'],user_id,args['groupname'],args['perm_unit'])
    await session.send(res[1])