예제 #1
0
    async def mute(self,
                   ctx: commands.Context,
                   member: discord.Member,
                   time: int = 1,
                   *,
                   reason: str = None) -> None:
        role: discord.Role = await commands.RoleConverter().convert(
            ctx, "Muted")
        await member.add_roles(role, reason=reason)
        await add_entry(self.db, COMMANDS["MUTE"].collection,
                        ctx.message.author, member, reason)

        replacement: dict = {
            "{member}": member.mention,
            "{time}": time,
            "{reason}": reason or ""
        }
        await ctx.send(embed=CommandEmbed(
            replace_placeholders(COMMANDS["MUTE"].title, replacement),
            replace_placeholders(COMMANDS["MUTE"].description, replacement),
            member,
        ))

        await asyncio.sleep(time * 60)
        await member.remove_roles(role)
예제 #2
0
    async def kick(self, ctx: commands.Context, member: discord.Member, *, reason: str = None) -> None:
        await _kick(self.db, ctx.message.author, member, reason)

        replacement: dict = {"{member}": member.mention, "{reason}": reason or ""}
        await ctx.send(embed=CommandEmbed(
            replace_placeholders(COMMANDS["KICK"].title, replacement),
            replace_placeholders(COMMANDS["KICK"].description, replacement),
            member,
        ))
예제 #3
0
    async def unban(self, ctx: commands.Context, *, member: str) -> None:
        banned_user: list[discord.Member] = await ctx.guild.bans()
        for user in banned_user:
            if (user.user.name, user.user.discriminator) == (*member.split("#"),):
                await user.unban()

                replacement: dict = {"{member}": user.mention}
                await ctx.send(embed=CommandEmbed(
                    replace_placeholders(COMMANDS["UNBAN"].title, replacement),
                    replace_placeholders(COMMANDS["UNBAN"].description, replacement),
                    user,
                ))

                break
예제 #4
0
    async def ban(self, ctx: commands.Context, member: discord.Member, time: int, *, reason: str = None) -> None:
        await member.ban(reason=reason)
        await add_entry(self.db, COMMANDS["BAN"].collection, ctx.message.author, member, reason)

        replacement: dict = {"{member}": member.mention, "{reason}": reason or "", "{time}": str(time)}
        await ctx.send(embed=CommandEmbed(
            replace_placeholders(COMMANDS["BAN"].title, replacement),
            replace_placeholders(COMMANDS["BAN"].description, replacement),
            member,
        ))

        if time <= 0:
            return None

        await asyncio.sleep(86400 * time)
        await member.unban()
예제 #5
0
    async def on_message(self, message: discord.Message) -> None:
        if message.content.startswith("m."):
            return None

        censored_words: collections.AsyncIterable = self.db[COMMANDS["CENSOR"].collection].find()
        async for word in censored_words:
            if word["_id"] in message.content.lower():
                await _warn(
                    self.db,
                    collections.namedtuple("Author", "id")(self.bot.user.id),
                    message.author,
                    COMMANDS["CENSOR"].reason,
                )

                replacement: dict = {"{member}": message.author.mention, "{reason}": COMMANDS["CENSOR"].reason}
                await message.reply(embed=CommandEmbed(
                    replace_placeholders(COMMANDS["CENSOR"].title, replacement),
                    replace_placeholders(COMMANDS["CENSOR"].description, replacement),
                    message.author,
                ))
예제 #6
0
    async def on_command_error(self, ctx: commands.Context, error) -> None:
        if isinstance(error, commands.CommandNotFound):
            replacement: dict = {"{command}": error.args[0].split()[1]}

            logging.error(replace_placeholders(ERRORS["CNF"].log, replacement))
            await ctx.send(embed=ErrorEmbed(
                replace_placeholders(ERRORS["CNF"].embed, replacement)))

        elif isinstance(error, commands.MissingRequiredArgument):
            replacement: dict = {
                "{command}": str(ctx.command),
                "{argument}": error.args[0].split()[0]
            }

            logging.warning(
                replace_placeholders(ERRORS["MRA"].log, replacement))
            await ctx.send(embed=ErrorEmbed(
                replace_placeholders(ERRORS["MRA"].embed, replacement)))

        elif isinstance(error, commands.RoleNotFound):
            replacement: dict = {"{role}": error.args[0].split()[1]}

            logging.error(replace_placeholders(ERRORS["RNF"].log, replacement))
            await ctx.send(embed=ErrorEmbed(
                replace_placeholders(ERRORS["RNF"].embed, replacement)))

            if "Muted" in error.args[0]:
                await ctx.guild.create_role(
                    name="Muted",
                    permissions=discord.Permissions(read_message_history=True,
                                                    read_messages=True),
                    reason="Automatically created role for mute command.",
                )

        elif isinstance(error, commands.MemberNotFound):
            replacement: dict = {"{member}": error.args[0]}

            logging.warning(
                replace_placeholders(ERRORS["MNF"].log, replacement))
            await ctx.send(embed=ErrorEmbed(
                replace_placeholders(ERRORS["MNF"].embed, replacement)))

        else:
            logging.error(error)