Example #1
0
    async def prefix_add(self, ctx: Context, prefix: Prefix) -> None:
        """Appends a prefix to the list of custom prefixes.

        Previously set prefixes are not overridden.

        To have a word prefix, you should quote it and end it with
        a space, e.g. "hello " to set the prefix to "hello ". This
        is because Discord removes spaces when sending messages so
        the spaces are not preserved.

        Multi-word prefixes must be quoted also.

        You must have Manage Server permission to use this command.
        """

        parsed = cast(str, prefix)

        current_prefixes = self.bot.get_raw_guild_prefixes(ctx.guild.id)
        current_prefixes.append(parsed)
        try:
            await self.bot.set_guild_prefixes(ctx.guild, current_prefixes)
        except Exception as e:
            await ctx.send(f"{ctx.tick(False)} {e}")
        else:
            await ctx.send(ctx.tick(True))
Example #2
0
    async def prefix_remove(self, ctx: Context, prefix: Prefix) -> None:
        """Removes a prefix from the list of custom prefixes.

        This is the inverse of the 'prefix add' command. You can
        use this to remove prefixes from the default set as well.

        You must have Manage Server permission to use this command.
        """

        parsed = cast(str, Prefix)

        current_prefixes = self.bot.get_raw_guild_prefixes(ctx.guild.id)

        try:
            current_prefixes.remove(parsed)
        except ValueError:
            await ctx.send("I do not have this prefix registered.")
            return

        try:
            await self.bot.set_guild_prefixes(ctx.guild, current_prefixes)
        except Exception as e:
            await ctx.send(f"{ctx.tick(False)} {e}")
        else:
            await ctx.send(ctx.tick(True))
Example #3
0
    async def prefix_clear(self, ctx: Context) -> None:
        """Removes all custom prefixes.

        After this, the bot will listen to only mention prefixes.

        You must have Manage Server permission to use this command.
        """

        await self.bot.set_guild_prefixes(ctx.guild, [])
        await ctx.send(ctx.tick(True))
Example #4
0
    async def unignore(self, ctx: Context, *entities: ChannelOrMember) -> None:
        """Allows channels or members to use the bot again.

        If nothing is specified, it unignores the current channel.

        To use this command you must have the Manage Server permission.
        """

        if not entities:
            query = "DELETE FROM plonks WHERE guild_id=$1 AND entity_id=$2;"
            await ctx.db.execute(query, ctx.guild.id, ctx.channel.id)
        else:
            query = "DELETE FROM plonks WHERE guild_id=$1 AND entity_id = ANY($2::bigint[]);"
            entities = [c.id for c in entities]
            await ctx.db.execute(query, ctx.guild.id, entities)

        self.is_plonked.invalidate_containing(f"{ctx.guild.id!r}:")
        await ctx.send(ctx.tick(True))
Example #5
0
    async def ignore(self, ctx: Context, *entities: ChannelOrMember) -> None:
        """Ignores text channels or members from using the bot.

        If no channel or member is specified, the current channel is ignored.

        Users with Manage Server can still use the bot, regardless of ignore
        status.

        To use this command you must have Manage Server permissions.
        """

        if not entities:
            # shortcut for a single insert
            query = "INSERT INTO plonks (guild_id, entity_id) VALUES ($1, $2) ON CONFLICT DO NOTHING;"
            await ctx.db.execute(query, ctx.guild.id, ctx.channel.id)

            # invalidate the cache for this guild
            self.is_plonked.invalidate_containing(f"{ctx.guild.id!r}:")
        else:
            await self._bulk_ignore_entries(ctx, entities)

        await ctx.send(ctx.tick(True))
Example #6
0
 async def global_unblock(self, ctx: Context, object_id: int):
     """Unblocks a user or guild globally."""
     await self.bot.remove_from_blacklist(object_id)
     await ctx.send(ctx.tick(True))
Example #7
0
 async def global_block(self, ctx: Context, object_id: int):
     """Blocks a user or guild globally."""
     await self.bot.add_to_blacklist(object_id)
     await ctx.send(ctx.tick(True))