Exemplo n.º 1
0
 async def blacklist(self, ctx, *, args: str) -> None:
     """
     blacklist the users provided to the command, both mentions and ids are valid.
     :param ctx: context of the invocation
     :param args: members provided to blacklist
     :return: None
     """
     member_set = await convert_content_to_member_set(ctx, args.split())
     for member in member_set:
         if member_has_role(
                 member,
                 roles()["admin"]) and ctx.message.author.id != int(
                     config["owner"]):
             await ctx.channel.send("You cannot blacklist an admin.")
         else:
             if member_has_role(
                     member,
                     roles()["moderator"]) and not member_has_role(
                         ctx.message.author,
                         roles()["admin"]):
                 await ctx.channel.send(
                     "Only admins can blacklist an moderator.")
             else:
                 self.blocker_service.blacklist(
                     Member(ctx.guild.id, member.id))
                 await ctx.channel.send("Blacklisted {}".format(
                     member.mention))
Exemplo n.º 2
0
class KarmaBlocker(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.blocker_service = BlockerService()

    @has_role(roles()['admin'])
    @commands.command(
        brief='blacklists a member from this bot, requires admin',
        description='prefix blacklist member')
    async def blacklist(self, ctx, member):
        if len(ctx.message.mentions) == 1:
            self.blocker_service.blacklist(
                Member(ctx.message.guild.id, ctx.message.mentions[0].id))
        else:
            self.blocker_service.blacklist(Member(ctx.message.guild.id,
                                                  member))
        await ctx.channel.send('Blacklisted {}'.format(member))

    @has_role(roles()['admin'])
    @commands.command(
        brief=
        'removes existing blacklists of a member from this bot, requires admin',
        description='prefix whitelist member')
    async def whitelist(self, ctx, *, member):
        if len(ctx.message.mentions) == 1:
            self.blocker_service.whitelist(
                Member(ctx.message.guild.id, ctx.message.mentions[0].id))
        else:
            self.blocker_service.whitelist(Member(ctx.message.guild.id,
                                                  member))
        await ctx.channel.send('Whitelisted {}'.format(member))
Exemplo n.º 3
0
 async def reset(self, ctx, *, args: str) -> None:
     """
     reset karma of the users provided to the command, both mentions and ids are valid.
     :param ctx: context of the invocation
     :param args: members provided to reset karma
     :return: None
     """
     # convert args to discord.Member
     member_set = await convert_content_to_member_set(ctx, args.split())
     for member in member_set:
         if member_has_role(
                 member,
                 roles()["admin"]) and ctx.message.author.id != int(
                     config["owner"]):
             await ctx.channel.send(
                 "You cannot reset the karma of an admin.")
         else:
             if member_has_role(
                     member,
                     roles()["moderator"]) and not member_has_role(
                         ctx.message.author,
                         roles()["admin"]):
                 await ctx.channel.send(
                     "Only admins can reset the karma of an moderator.")
             else:
                 self.karma_service.delete_all_karma(
                     KarmaMember(ctx.guild.id, member.id))
                 await ctx.channel.send("Removed all Karma from {}".format(
                     member.mention))
Exemplo n.º 4
0
class KarmaReducer(commands.Cog):
    # Class all about reducing the Karma of a Member
    def __init__(self, bot, karma_service=KarmaMemberService(datasource.karma)):
        self.bot = bot
        self.karma_service = karma_service

    @guild_only()
    @has_any_role(roles()['admin'], roles()['moderator'])
    @commands.command(brief='Reset all karma of a member in the guild',
                      usage='{}reset member_id\n{}reset <@!member_id>'
                      .format(config['prefix'], config['prefix']))
    async def reset(self, ctx, *, args: str) -> None:
        """
        reset karma of the users provided to the command, both mentions and ids are valid.
        :param ctx: context of the invocation
        :param args: members provided to reset karma
        :return: None
        """
        # convert args to discord.Member
        member_set = await convert_content_to_member_set(ctx, args.split())
        for member in member_set:
            if member_has_role(member, roles()['admin']) and ctx.message.author.id != int(config['owner']):
                await ctx.channel.send(f'Skipping {member.display_name}, You cannot reset the karma of an admin.')
                continue

            if member_has_role(member, roles()['moderator']) \
                    and not member_has_role(ctx.message.author, roles()['admin']):
                await ctx.channel.send(f'Skipping {member.display_name}, ' +
                                       'Only admins can reset the karma of an moderator.')
                continue

            self.karma_service.delete_all_karma(KarmaMember(ctx.guild.id, member.id))
            await ctx.channel.send(f'Removed all Karma for {member.mention}')
Exemplo n.º 5
0
class KarmaReducer(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.karma_service = KarmaService()

    # remove all karma from member
    @has_any_role(roles()['admin'], roles()['moderator'])
    @commands.command(
        brief='Reset all karma of a member, requires admin or moderator',
        description='prefix reset member_id')
    async def reset(self, ctx, member):
        guild_id: str = str(ctx.message.guild.id)
        self.karma_service.delete_all_karma(KarmaMember(guild_id, member))
        await ctx.channel.send('Removed all Karma from {}'.format(member))
Exemplo n.º 6
0
 def predicate(ctx):
     role = str(permission_map[command_name])
     caller = ctx.message.author
     log.info(f'Checking on permission {role} for command: {command_name} and user: {ctx.message.author.id}')
     if role.lower() == 'everyone':
         return True
     elif role.lower() == 'owner':
         if caller.id == int(config['owner']):
             return True
     elif role.lower() == 'moderator':
         if member_has_role(caller, roles()['moderator']) \
                 or member_has_role(caller, roles()['admin']) \
                 or caller.id == int(config['owner']):
             return True
     elif role.lower() == 'admin':
         if member_has_role(caller, roles()['admin']) \
                 or caller.id == int(config['owner']):
             return True
     return False
Exemplo n.º 7
0
class KarmaReducer(commands.Cog):
    # Class all about reducing the Karma of a Member
    def __init__(self, bot,
                 karma_service=KarmaMemberService(datasource.karma)):
        self.bot = bot
        self.karma_service = karma_service

    @guild_only()
    @has_any_role(roles()["admin"], roles()["moderator"])
    @commands.command(
        brief="Reset all karma of a member in the guild",
        usage="{}reset member_id\n{}reset <@!member_id>".format(
            config["prefix"], config["prefix"]),
    )
    async def reset(self, ctx, *, args: str) -> None:
        """
        reset karma of the users provided to the command, both mentions and ids are valid.
        :param ctx: context of the invocation
        :param args: members provided to reset karma
        :return: None
        """
        # convert args to discord.Member
        member_set = await convert_content_to_member_set(ctx, args.split())
        for member in member_set:
            if member_has_role(
                    member,
                    roles()["admin"]) and ctx.message.author.id != int(
                        config["owner"]):
                await ctx.channel.send(
                    "You cannot reset the karma of an admin.")
            else:
                if member_has_role(
                        member,
                        roles()["moderator"]) and not member_has_role(
                            ctx.message.author,
                            roles()["admin"]):
                    await ctx.channel.send(
                        "Only admins can reset the karma of an moderator.")
                else:
                    self.karma_service.delete_all_karma(
                        KarmaMember(ctx.guild.id, member.id))
                    await ctx.channel.send("Removed all Karma from {}".format(
                        member.mention))
Exemplo n.º 8
0
    async def whitelist(self, ctx, *, args: str) -> None:
        """
        whitelist the users provided to the command, both mentions and ids are valid.
        :param ctx: context of the invocation
        :param args: members provided to whitelist
        :return: None
        """
        member_set = await convert_content_to_member_set(ctx, args.split())
        for member in member_set:
            if member_has_role(member, roles()['admin']) and ctx.message.author.id != int(config['owner']):
                await ctx.channel.send(f'Skipping {member.display_name}, You cannot whitelist an admin.')
                continue

            if member_has_role(member, roles()['moderator']) \
                    and not member_has_role(ctx.message.author, roles()['admin']):
                await ctx.channel.send(f'Skipping {member.display_name}, Only admins can whitelist an moderator.')

            self.blocker_service.whitelist(Member(ctx.guild.id, member.id))
            await ctx.channel.send(f'Whitelisted {member.mention}')
Exemplo n.º 9
0
    async def reset(self, ctx, *, args: str) -> None:
        """
        reset karma of the users provided to the command, both mentions and ids are valid.
        :param ctx: context of the invocation
        :param args: members provided to reset karma
        :return: None
        """
        # convert args to discord.Member
        member_set = await convert_content_to_member_set(ctx, args.split())
        for member in member_set:
            if member_has_role(member, roles()['admin']) and ctx.message.author.id != int(config['owner']):
                await ctx.channel.send(f'Skipping {member.display_name}, You cannot reset the karma of an admin.')
                continue

            if member_has_role(member, roles()['moderator']) \
                    and not member_has_role(ctx.message.author, roles()['admin']):
                await ctx.channel.send(f'Skipping {member.display_name}, ' +
                                       'Only admins can reset the karma of an moderator.')
                continue

            self.karma_service.delete_all_karma(KarmaMember(ctx.guild.id, member.id))
            await ctx.channel.send(f'Removed all Karma for {member.mention}')
Exemplo n.º 10
0
 def predicate(ctx):
     role = str(permission_map[command_name])
     caller = ctx.message.author
     log.info(
         f"Checking on permission {role} for command: {command_name} and user: {ctx.message.author.id}"
     )
     if role.lower() == "everyone":
         return True
     elif role.lower() == "owner":
         if caller.id == int(config["owner"]):
             return True
     elif role.lower() == "moderator":
         if (member_has_role(caller,
                             roles()["moderator"])
                 or member_has_role(caller,
                                    roles()["admin"])
                 or caller.id == int(config["owner"])):
             return True
     elif role.lower() == "admin":
         if member_has_role(caller,
                            roles()["admin"]) or caller.id == int(
                                config["owner"]):
             return True
     return False
Exemplo n.º 11
0
class SettingsManager(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    # edit config defined in config.yaml, return messages if incorrect args are provided.
    # no checks on non existing configuration
    @has_role(roles()['admin'])
    @commands.command(
        brief='change configuration parameters, requires admin',
        description=
        'change config params to new value, last value in params is new_value')
    async def config(self, ctx, *, params: str):
        args = params.split()
        if len(args) > 3:
            await ctx.channel.send(
                'You cannot send a message with more than three arguments.')
        elif len(args) <= 1:
            await ctx.channel.send('Your message needs at least two arguments.'
                                   )
        else:
            if config[args[0]] is not None and args[0] != 'token' and args[
                    0] != 'prefix':
                if len(args) == 3:
                    if config[args[0]][args[1]] is not None \
                            and args[0] != 'token' and args[0] != 'prefix':
                        config[args[0]][args[1]] = args[2]
                        write_config()
                        await ctx.channel.send(
                            'Configuration parameter {} {} has been changed to {}'
                            .format(args[0], args[1], args[2]))
                else:
                    config[args[0]] = args[1]
                    write_config()
                    await ctx.channel.send(
                        'Configuration parameter {} has been changed to {}'.
                        format(args[0], args[1]))