Esempio n. 1
0
 async def has_role(self, user, role_name):
     if type(user) == Member:
         return utils.has_role(user, role_name)
     else:
         guild = await self.bot.fetch_guild(config.guild_id)
         member = await guild.fetch_member(user.id)
         return utils.has_role(member, role_name)
Esempio n. 2
0
    def has_role(self,
                 role: Role,
                 room: Room,
                 ignore_grole: bool = False) -> bool:
        """Check if user has a PS room role or higher.

        Higher global roles ovveride room roles.

        Args:
            role (Role): PS role (i.e. "voice", "driver").
            room (Room): Room to check.
            ignore_grole (bool): True if global roles should be ignored.

        Returns:
            bool: True if user meets the required criteria.
        """
        if (not ignore_grole and self.global_rank
                and utils.has_role(role, self.global_rank)):
            return True

        room_rank = self.rank(room)
        if room_rank:
            return utils.has_role(role, room_rank)

        return False
Esempio n. 3
0
    def wrapper(**kwargs: str) -> str:
        rank_check = kwargs.get("room", "_rank")
        if required_rank is None:
            if rank_check not in web_session:
                abort(401)
        elif not utils.has_role(required_rank, web_session.get(rank_check)):
            abort(401)

        return func(**kwargs)
Esempio n. 4
0
async def vs(client, message, args):
    group_id = settings['group']['vs']
    expert_id = settings['group']['vs-expert']
    group = get_role_by_id(message.channel.server, group_id)
    expert = get_role_by_id(message.channel.server, expert_id)

    if args.expert:
        if not has_role(message.author, expert_id):
            await private_msg(message.author,
                              "You need to be an expert to do that.")
        elif args.remove:
            for mention in message.mentions:
                await client.remove_roles(mention, expert)
                await private_msg(mention, "You are no longer an VS expert.")
        else:
            for mention in message.mentions:
                await client.add_roles(mention, expert)
                await private_msg(mention, "Welcome to the VS experts!")
    else:
        if args.remove:
            await client.remove_roles(message.author, group)
        else:
            await client.add_roles(message.author, group)
Esempio n. 5
0
def test_has_role(role: Role, userrank: str, expected: bool) -> None:
    assert utils.has_role(role, userrank) == expected