Пример #1
0
    async def disable_list(self, ctx):
        """List of disabled commands"""

        state = state_instance.get_state(ctx.guild.id)
        cmds = state.get_commands()

        dis_cmds = ""
        for cmd in cmds:
            comd = state.get_var(cmd)
            if comd.server_wide == False:
                dis_cmds += f"`{cmd}` disabled server-wide\n"
            if len(comd.channels) > 0:
                dis_cmds += f"`{cmd}` disabled in channels {str(comd.channels).strip('{}')}\n"
            if len(comd.roles) > 0:
                dis_cmds += f"`{cmd}` disabled for roles {str(comd.roles).strip('{}')}\n"

        if dis_cmds == "":
            return await ctx.send(
                "Disabled command list is empty, darkness is its only friend now"
            )

        dlist = discord.Embed(title="Disabled Commands",
                              description=dis_cmds,
                              color=discord.Colour.from_rgb(0, 250, 141),
                              timestamp=ctx.message.created_at)

        dlist.set_author(
            name=
            "Note: Disabling all commands server-wide will override all rules of other commands. Also, disabling for roles checks if the member has that role as the toprole. IQ is required to use these command"
        )

        dlist.set_footer(text=f"Requested by {ctx.author}",
                         icon_url=ctx.author.avatar_url)

        await ctx.send(embed=dlist)
Пример #2
0
    async def prefix(self, ctx, *, prefix=None):
        """Gets the current prefix or changes the prefix"""

        embed = discord.Embed(color=discord.Colour.from_rgb(0, 0, 0),
                              timestamp=ctx.message.created_at)
        state = state_instance.get_state(ctx.guild.id)
        if prefix == None:
            embed.add_field(name="Current Prefix",
                            value=f"Current prefix `{state.bot_prefix}`",
                            inline=False)
            embed.set_footer(text=f"Requested by {ctx.author}",
                             icon_url=ctx.author.avatar_url)
        elif prefix != None:
            if ctx.message.author.id in al_admins:
                state.bot_prefix = prefix
                embed.add_field(
                    name="Prefix",
                    value=f"Prefix changed to `{state.bot_prefix}`",
                    inline=False)
                embed.set_footer(text=f"Requested by {ctx.author}",
                                 icon_url=ctx.author.avatar_url)
                print("prefix changed to {} in {}".format(
                    prefix, ctx.guild.id))
            else:
                embed = discord.Embed(
                    title="You thought you could do that, how gae.",
                    timestamp=ctx.message.created_at)

        await ctx.send(embed=embed)
Пример #3
0
    async def disable(self,
                      ctx,
                      command: ComCog,
                      role_chan: typing.Union[discord.TextChannel,
                                              discord.Role, str] = None):
        """You can provide a command to be disabled in a channel, for a particular role or server wide(don't pass anything)"""

        command, cmd = command

        state = state_instance.get_state(ctx.guild.id)
        comd = state.get_var(str(cmd))
        if isinstance(role_chan, discord.TextChannel):
            chann = comd.channels
            chann.add(str(role_chan))
            val = state.command(comd.server_wide, chann, comd.roles, False)
            await ctx.send(f"Disabled `{command}` in {role_chan.mention}")
        elif isinstance(role_chan, discord.Role):
            rol = comd.roles
            rol.add(str(role_chan))
            val = state.command(comd.server_wide, comd.channels, rol, False)
            await ctx.send(f"Disabled `{command}` for {role_chan.mention}")
        elif role_chan != None:
            raise commands.errors.BadArgument()
        else:
            val = state.command(False, set(), set(), False)
            if command == "all":
                self.unforce(state)
            await ctx.send(f"Disabled `{command}` server-wide")
        state.set_var(str(cmd), val)
Пример #4
0
    async def disable_debugmode(self, ctx):
        """Disable debugmode"""

        state = state_instance.get_state(ctx.guild.id)
        state.set_var("debugmode", True)

        await ctx.send("Disabled debugmode...")
Пример #5
0
    async def enable_list(self, ctx):
        """Get the commands which are overrirding the disable all rules for channels or roles"""

        state = state_instance.get_state(ctx.guild.id)
        cmds = state.get_commands()

        en_cmds = ""
        for cmd in cmds:
            comd = state.get_var(cmd)
            if comd.forced:
                en_cmds += f"\t`{cmd}` forced enabled\n"

        if en_cmds == "":
            return await ctx.send(
                "Looks like someone is obedient towards the rules, no commands are overriding any roles(¬‿¬)"
            )

        elist = discord.Embed(title="Forced enabled Commands",
                              description=en_cmds,
                              color=discord.Colour.from_rgb(0, 250, 141),
                              timestamp=ctx.message.created_at)

        elist.set_author(
            name=
            "Note: Overridded rules don't have rules for channels or roles, These are overriding only `all disabled` rule"
        )

        elist.set_footer(text=f"Requested by {ctx.author}",
                         icon_url=ctx.author.avatar_url)

        await ctx.send(embed=elist)
Пример #6
0
    async def mute(self, ctx, member: discord.Member, *, reason: str = None):
        """Server mute the mentioned user(only text channels), requires you to have manage roles permission"""

        state = state_instance.get_state(ctx.guild.id)
        text_channels = ctx.guild.text_channels
        mute_role = None
        if await permissions.check_priv(ctx, member):
            return
        if state.mute_exists:
            mute_role = get(ctx.guild.roles, name="Muted")
        else:
            mute_role = await ctx.guild.create_role(name="Muted")
            for channel in text_channels:
                await channel.set_permissions(mute_role,
                                              send_messages=False,
                                              manage_permissions=False,
                                              manage_channels=False,
                                              manage_webhooks=False,
                                              manage_messages=False)
            state.mute_exists = True

        for role in member.roles[::-1]:
            if role.name == "Muted":
                return await ctx.send(f"{member.name} is already muted")
        try:
            await member.add_roles(mute_role,
                                   reason=default.responsible(
                                       ctx.author, reason))
            await ctx.send(default.actionmessage("muted"))
        except Exception as e:
            await ctx.send(e)
Пример #7
0
def check_availabilty(ctx):
    cmd = ctx.command
    
    state = state_instance.get_state(ctx.guild.id)
    if cmd.root_parent:
        cmd = cmd.root_parent
    
    if str(cmd) == "enable" or str(cmd) == "disable" or str(cmd) == "reboot":
        return True
    
    al = state.get_var("all")
    comd = state.get_var(str(cmd))
    tc = ctx.channel
    rol = ctx.author.top_role
    
    if str(tc) in al.channels:
        return comd.forced
    if str(rol) in al.roles:
        return comd.forced
    if str(tc) in comd.channels:
        return False
    if str(rol) in comd.roles:
        return False

    availability = comd.server_wide if al.server_wide else comd.forced
    return availability
Пример #8
0
    async def on_guild_join(self, guild):

        state_instance.get_state(guild.id)

        if not self.config.join_message:
            return

        try:
            to_send = sorted([
                chan for chan in guild.channels
                if chan.permissions_for(guild.me).send_messages
                and isinstance(chan, discord.TextChannel)
            ],
                             key=lambda x: x.position)[0]
        except IndexError:
            pass
        else:
            await to_send.send(self.config.join_message)
Пример #9
0
def check_mute(ctx):
    state = state_instance.get_state(ctx.guild.id)
    roles = ctx.guild.roles
    for role in roles:
        if role.name == "Muted":
            state.mute_exists = True
            return True
    state.mute_exists = False
    return True
Пример #10
0
    async def on_command_error(self, ctx, err):
        if hasattr(ctx.command, "on_error"):
            return  # Don't interfere with custom error handlers

        gstate = state_instance.get_state(ctx.guild.id)

        if isinstance(err, errors.MissingRequiredArgument) or isinstance(
                err, errors.BadArgument):
            helper = str(
                ctx.invoked_subcommand) if ctx.invoked_subcommand else str(
                    ctx.command)
            await ctx.send(
                "Bruh, take a look at the syntax of this command (ˉ﹃ˉ)")
            await ctx.send_help(helper)

        elif isinstance(err, errors.CommandInvokeError):
            error = f"Command invoke error:\n{default.traceback_maker(err.original)}"
            if "2000 or fewer" in str(err) or len(
                    ctx.message.clean_content) > 1900:
                return await ctx.send(
                    "You attempted to make the command display more than 2,000 characters...\n"
                    f"Both error and command will be ignored. Baka.")

            await ctx.send("There was an error processing the command ಥ_ಥ")
            honeybadger.notify(err,
                               context={
                                   'Command':
                                   ctx.message.clean_content,
                                   'Traceback':
                                   default.traceback_maker(err.original,
                                                           only_traceback=True)
                               })
            logging.error("Ignoring exception in command {}:".format(
                ctx.command))
            logging.error("\n" + "".join(
                traceback.format_exception(type(error), err,
                                           err.__traceback__)))

        elif isinstance(err, errors.CheckFailure):
            pass

        elif isinstance(err, errors.CommandOnCooldown):
            embed = discord.Embed(
                title="Cooldown",
                color=discord.Colour.from_rgb(0, 250, 141),
                description="**This command is on cooldown... try again in {}**"
                .format(default.format_seconds(err.retry_after)),
                timestamp=ctx.message.created_at)

            await ctx.send(embed=embed)

        if isinstance(err, commands.CommandNotFound):
            if not gstate.debugmode:
                return
            await ctx.send(f'>>> No command "{ctx.invoked_with}" found.',
                           delete_after=5)
Пример #11
0
    async def enable(self,
                     ctx,
                     command: ComCog,
                     role_chan: typing.Union[discord.TextChannel, discord.Role,
                                             str] = None):
        """Enables a given command"""

        command, cmd = command

        state = state_instance.get_state(ctx.guild.id)
        comd = state.get_var(str(cmd))
        if isinstance(role_chan, discord.TextChannel):
            chann = comd.channels
            chann.discard(str(role_chan))
            val = state.command(comd.server_wide, chann, comd.roles,
                                False) if str(role_chan) not in state.get_var(
                                    "all").channels else state.command(
                                        comd.server_wide, chann, comd.roles,
                                        True)
            await ctx.send(f"Enabled `{command}` in {role_chan.mention}")
        elif isinstance(role_chan, discord.Role):
            rol = comd.roles
            rol.discard(str(role_chan))
            val = state.command(comd.server_wide, comd.channels, rol,
                                False) if str(role_chan) not in state.get_var(
                                    "all").roles else state.command(
                                        comd.server_wide, comd.channels, rol,
                                        True)
            await ctx.send(f"Enabled `{command}` for {role_chan.mention}")
        elif role_chan != None:
            raise commands.errors.BadArgument()
        else:
            if command != "all":
                all_cmds = state.get_var("all")
                val = state.command(
                    True, set(), set(),
                    False) if all_cmds.server_wide else state.command(
                        True, set(), set(), True)
            else:
                val = state.command(True, set(), set(), False)
            await ctx.send(f"Enabled `{command}` server-wide")
        state.set_var(str(cmd), val)
Пример #12
0
def get_prefix(bot, message):
    gstate = state_instance.get_state(message.guild.id)
    return command_prefix + all_cases(gstate.bot_prefix)