示例#1
0
def user(**kwargs):
    """
    Send in vk list of squad's user or list of leaders (associates and leaders)
    """
    roles = [0, 1, 3, 5, 7]

    if kwargs['role_id'] not in roles:
        vk_api.send(kwargs['chat'], "Access Denied")
        return

    # TeamLeader
    if kwargs['role_id'] in roles[0:3]:
        com = kwargs['msg']['text'].split()
        if len(com) == 2:
            com[1] = com[1].upper()
            if com[1] not in squads.get_squads():
                vk_api.send(kwargs['chat'], "Wrong squad")
                return
            squad_users = squads.squad_users(com[1])
            msg = ''
            for i in squad_users:
                msg = msg + '[id' + str(i) + '|' + str(squad_users[i]) + ']\n'
            if msg == '':
                vk_api.send(kwargs['chat'], "Empty...")
            else:
                vk_api.send(kwargs['chat'], msg)
            return
        elif len(com) == 1:
            leaders = list()
            for squad in squads.get_squads():
                for lead in squads.get_leaders(squad):
                    leaders.append(lead)
            msg = ''
            for i in leaders:
                msg = msg + '[id' + str(i) + '|' + users.get_profile(
                    i)['nickname'] + ']: ' + str(users.get_role(i)) + '\n'
            if msg == '':
                vk_api.send(kwargs['chat'], "Empty...")
            else:
                vk_api.send(kwargs['chat'], msg)
            return
        else:
            # TODO
            vk_api.send(kwargs['chat'], "Wrong arguments, (source) is needed")
    # SquadLeader
    else:
        squad_users = squads.squad_users(
            users.get_squad(kwargs['msg']['from_id']))
        msg = ''
        for i in squad_users:
            msg = msg + '[id' + str(i) + '|' + str(squad_users[i]) + ']\n'
        if msg == '':
            vk_api.send(kwargs['chat'], "Empty...")
        else:
            vk_api.send(kwargs['chat'], msg)
    return
示例#2
0
def del_squad(**kwargs):
    """
    Delete squad from DB
    """
    # TeamLeaders only
    roles = [0, 1, 3]

    if kwargs['role_id'] not in roles:
        vk_api.send(kwargs['chat'], "Access Denied")
        return

    com = kwargs['msg']['text'].split()
    if len(com) != 2:
        vk_api.send(kwargs['chat'], "Wrong argument, source is needed")
        return

    if com[1] not in squads.get_squads():
        vk_api.send(kwargs['chat'], "Squad already doesn't exists")
        return

    # TODO: Check for user in squad

    squads.del_squad(com[1])
    vk_api.send(kwargs['chat'], "Squad deleted")
    return
示例#3
0
def squad_list(**kwargs):
    """
    Send in vk squad list
    """
    roles = [0, 1, 3]

    if kwargs['role_id'] not in roles:
        vk_api.send(kwargs['chat'], "Access Denied")
        return

    msg = ', '.join(squads.get_squads())

    vk_api.send(kwargs['chat'], msg)
    return
示例#4
0
def remove_all():
    """
    Set target 0 for all squads
    [WARNING] Long requests, can works double
    :return: None
    """
    for src in get_squads():
        if src in ignored_squads:
            pass
        else:
            params["source"] = src
            params["target"] = 0
            params["token"] = get_token(src)

            if debug:
                time.sleep(2)
                print("request to " + url + " with " + str(params) + ' and ' + str(headers))
            else:
                requests.get(url, params, headers=headers)
    return
示例#5
0
def target(**kwargs):
    """
    Send target to HW API
    """
    roles = [0, 1, 3, 5, 7]

    if kwargs['role_id'] not in roles:
        vk_api.send(kwargs['chat'], "Access Denied")
        return

    com = kwargs['msg']['text'].split()

    # TeamLeader
    if kwargs['role_id'] in roles[0:3]:
        if len(com) == 3:

            try:
                com[2] = int(com[2])
            except ValueError:
                vk_api.send(kwargs['chat'], "Wrong target, should be number")
                return

            if 0 <= com[2] <= 7:
                if com[2] == fraction:
                    vk_api.send(kwargs['chat'], 'Attack on yourself')
                    return
            else:
                # target = -1 or 9
                vk_api.send(kwargs['chat'], 'Wrong target')
                return

            if com[1] != 'all':
                com[1] = com[1].upper()
                if com[1] not in squads.get_squads():
                    vk_api.send(kwargs['chat'], "Wrong source")
                    return
                if com[1] in ignored_squads:
                    vk_api.send(kwargs['chat'], "Dead squad")
                    return

                hw_api.set_target(com[1], com[2])
            else:
                for source in squads.get_squads():
                    if source in ignored_squads:
                        pass
                    else:
                        hw_api.set_target(source, com[2])
            vk_api.send(kwargs['chat'], "Target sent!")
            return

        elif len(com) == 2:

            try:
                com[1] = int(com[1])
            except ValueError:
                vk_api.send(kwargs['chat'], "Wrong target, should be number")
                return

            if 0 <= com[1] <= 7:
                if com[1] == fraction:
                    vk_api.send(kwargs['chat'], 'Attack on yourself')
                    return
            else:
                # target = -1 or 9
                vk_api.send(kwargs['chat'], 'Wrong target')
                return

            hw_api.set_target(str(fraction), com[1])
            vk_api.send(kwargs['chat'], "target sent!")
            return

        else:
            vk_api.send(kwargs['chat'],
                        "Wrong arguments, (source and) target needed")
            return

    # Squad Leader
    else:
        if len(com) != 2:
            vk_api.send(kwargs['chat'], "Wrong arguments, target needed")
            return

        try:
            com[1] = int(com[1])
        except ValueError:
            vk_api.send(kwargs['chat'], "Wrong target, should be number")
            return

        if 0 <= com[1] <= 7:
            if com[1] == fraction:
                vk_api.send(kwargs['chat'], 'Attack on yourself')
                return
        else:
            # target = -1 or 9
            vk_api.send(kwargs['chat'], 'Wrong target')
            return

        source = users.get_squad(kwargs['msg']['from_id'])
        hw_api.set_target(source, com[1])
        vk_api.send(kwargs['chat'], "target sent!")
        return