How to use the cogs.utils.checks function in Cogs

To help you get started, we’ve selected a few Cogs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CarlGroth / Carl-Bot / cogs / mod.py View on Github external
    @checks.admin_or_permissions(manage_server=True)
    async def add_word(self, ctx, *, to_be_blacklisted: str=None):
        if to_be_blacklisted is None:
            print(ctx)
            await ctx.channel.send("You need to specify a word to blacklist")
            return
        slugified_word = self.do_slugify(to_be_blacklisted)
        self.c.execute('''INSERT OR IGNORE INTO blacklist
                          VALUES (?, ?)''',
                          (ctx.guild.id, slugified_word))
        self.conn.commit()
        try:
            self.blacklist[str(ctx.guild.id)].append(slugified_word)
        except KeyError:
            self.blacklist[str(ctx.guild.id)] = [slugified_word]
        to_be_blacklisted = self.clean_string(to_be_blacklisted)
        await ctx.send(f'Added "{to_be_blacklisted}" to the blacklist')
github CarlGroth / Carl-Bot / cogs / twitch.py View on Github external
    @checks.admin_or_permissions(manage_server=True)
    async def twitch_limit(self, ctx, limit: int=0):
        self.c.execute('''INSERT OR IGNORE INTO twitch_config VALUES (?, ?, ?, ?, ?)''', (ctx.guild.id, 0, 1, 0, 0))
        self.c.execute('''UPDATE twitch_config SET max_ownership = ? WHERE guild_id=?''', (limit, ctx.guild.id))
        self.conn.commit()
        self.c.execute('''SELECT max_ownership FROM twitch_config WHERE guild_id=?''', (ctx.guild.id,))
        howmany = self.c.fetchone()[0]
        if howmany != 0:
            return await ctx.send(f"Users (non-mods) are now limited to {howmany} streams added")
        await ctx.send("Users can now add as many twitch streamers as they want")
github Godavaru / Godavaru / cogs / nsfw.py View on Github external
    @checks.is_nsfw()
    async def rule34(self, ctx, tag: str):
        """Search for an image on rule34!
        Note: To use this command, the channel must be NSFW."""
        try:
            url = 'https://rule34.xxx/index.php?page=dapi&s=post&q=index&json=1&tags=' + tag
            async with self.bot.session.get(url) as resp:
                js = json.loads(await resp.text())
            non_loli = list(filter(lambda x: 'loli' not in x['tags'] and 'shota' not in x['tags'], js))
            if len(non_loli) == 0:
                return await ctx.send(":warning: All results included loli/shota content; this search is invalid.")
            response = non_loli[random.randint(0, len(non_loli) - 1)]
            img = f"https://img.rule34.xxx/images/{response['directory']}/{response['image']}"
            tags = ', '.join(response['tags'].split(' '))
            em = discord.Embed(
                description=f'{"`" + tags + "`" if len(tags) < 5000 else "[Click me for the tags](" + self.bot.post_to_haste(tags)})`',
                colour=0xff0000)
github Godavaru / Godavaru / cogs / events / command_handler.py View on Github external
def __init__(self, bot):
        self.bot = bot
        self.__sendable_exceptions = (
            checks.ChannelNotNSFW,
            commands.BadArgument,
            commands.UserInputError,
        )
github NabDev / NabBot / cogs / timers.py View on Github external
    @checks.can_embed()
    @commands.group(aliases=["event"], invoke_without_command=True, case_insensitive=True, usage="[event id]")
    async def events(self, ctx: NabCtx, event_id: int = None):
        """Shows a list of upcoming and recent events.

        If a number is specified, it will show details for that event. Same as using `events info`"""
        if event_id is not None:
            await ctx.invoke(self.bot.all_commands.get('events').get_command("info"), event_id)
            return
        embed = discord.Embed(description="For more info about an event, use `/event info (id)`"
                                          "\nTo receive notifications for an event, use `/event sub (id)`")
        async with ctx.pool.acquire() as conn:
            recent_events = await Event.get_recent_by_server_id(conn, ctx.guild.id)
            upcoming_events = await Event.get_upcoming_by_server_id(conn, ctx.guild.id)
        if len(recent_events) + len(upcoming_events) == 0:
            await ctx.send("There are no upcoming events.")
            return
github henry232323 / RPGBot / cogs / user.py View on Github external
    @checks.mod_or_permissions()
    @commands.group(aliases=["exp"], invoke_without_command=True)
    async def experience(self, ctx, member: discord.Member = None):
        """Get your or another user's level information. Help on this command for experience subcommands
        EXP is calculated using a 0.1x^2+5x+4 where x is equal to the user's current level
        Spamming commands or messages will not earn more exp!"""
        if member is None:
            member = ctx.author

        ulvl, uexp = await self.bot.di.get_user_level(member)
        embed = discord.Embed(
            description=(await _(ctx, "Level: {}\nExperience: {}/{}")).format(ulvl, uexp, self.bot.get_exp(ulvl)),
            color=randint(0, 0xFFFFFF), )
        embed.set_author(name=member.display_name, icon_url=member.avatar_url)
        await ctx.send(embed=embed)
github Rapptz / RoboDanny / cogs / repl.py View on Github external
    @checks.is_owner()
    async def _eval(self, ctx, *, body: str):
        env = {
            'bot': self.bot,
            'ctx': ctx,
            'channel': ctx.message.channel,
            'author': ctx.message.author,
            'server': ctx.message.server,
            'message': ctx.message,
            '_': self._last_result
        }

        env.update(globals())

        body = self.cleanup_code(body)
        stdout = io.StringIO()
github dashwav / yin-bot / cogs / logging.py View on Github external
    @checks.is_admin()
    async def voice_logging(self, ctx):
        """Enable and disable logging to channel."""
        if ctx.invoked_subcommand is None:
            desc = ''
            voicelogs = await self.bot.pg_utils.get_voice_channels(
                ctx.guild.id)
            for channel in ctx.guild.channels:
                if channel.id in voicelogs:
                    desc += f'{channel.name} \n'
            local_embed = discord.Embed(
                title=f'Current voice log channel list is: ',
                description=desc,
                color=0x419400
            )
            await ctx.send(embed=local_embed)
github dashwav / nano-chan / cogs / stats.py View on Github external
    @checks.is_admin()
    async def download_guild_history(self, ctx):
        """
        This will go through all the channels
        and download them.
        """
        confirm = await helpers.custom_confirm(
            ctx,
            f'\nAre you sure you want to do this?'
            ' This will literally take just about forever. Like days maybe.\n')
        if not confirm:
            return
        confirm2 = await helpers.custom_confirm(
            ctx,
            f'\nSeriously this is going to take at least 4 hours,'
            ' and it could even go up to a week. Only respond with'
            ' confirm if you **really** mean it\n')
github devakira / NanoBot / cogs / audio.py View on Github external
    @checks.mod_or_permissions(manage_messages=True)
    async def audioset_vote(self, ctx, percent: int):
        """Percentage needed for the masses to skip songs. 0 to disable."""
        server = ctx.message.server

        if percent < 0:
            await self.bot.say("Can't be less than zero.")
            return
        elif percent > 100:
            percent = 100

        if percent == 0:
            enabled = False
            await self.bot.say("Voting disabled. All users can stop or skip.")
        else:
            enabled = True
            await self.bot.say("Vote percentage set to {}%".format(percent))