async def convert(self, ctx: commands.Context, arg: str) -> discord.Role: admin = ctx.command.instance if admin is None: raise commands.BadArgument("Admin is not loaded.") conf = admin.conf selfroles = await conf.guild(ctx.guild).selfroles() role_converter = commands.RoleConverter() role = await role_converter.convert(ctx, arg) if role.id not in selfroles: raise commands.BadArgument("The provided role is not a valid selfrole.") return role
async def convert(self, ctx: commands.Context, arg: str) -> str: if arg.lower() in ("allow", "whitelist", "allowed"): return "allow" if arg.lower() in ("deny", "blacklist", "denied"): return "deny" raise commands.BadArgument( '"{arg}" is not a valid rule. Valid rules are "allow" or "deny"'. format(arg=arg))
async def convert(self, ctx: commands.Context, arg: str) -> Installable: downloader = ctx.bot.get_cog("Downloader") if downloader is None: raise commands.CommandError("Downloader not loaded.") cog = discord.utils.get(await downloader.installed_cogs(), name=arg) if cog is None: raise commands.BadArgument("That cog is not installed") return cog
async def convert(self, ctx: commands.Context, arg: str) -> Tuple[str]: ret = ctx.bot.get_cog(arg) if ret: return "cogs", ret.__class__.__name__ ret = ctx.bot.get_command(arg) if ret: return "commands", ret.qualified_name raise commands.BadArgument( 'Cog or command "{arg}" not found. Please note that this is case sensitive.' "".format(arg=arg))
async def convert(cls, ctx: commands.Context, argument: str): downloader_cog = ctx.bot.get_cog("Downloader") if downloader_cog is None: raise commands.CommandError("No Downloader cog found.") # noinspection PyProtectedMember repo_manager = downloader_cog._repo_manager poss_repo = repo_manager.get_repo(argument) if poss_repo is None: raise commands.BadArgument( "Repo by the name {} does not exist.".format(argument)) return poss_repo
async def user( self, ctx: commands.Context, user: str, number: int, delete_pinned: bool = False ): """Deletes last X messages from specified user. Examples: cleanup user @\u200bTwentysix 2 cleanup user Red 6""" channel = ctx.channel if not channel.permissions_for(ctx.guild.me).manage_messages: await ctx.send("I need the Manage Messages permission to do this.") return member = None try: member = await commands.converter.MemberConverter().convert(ctx, user) except commands.BadArgument: try: _id = int(user) except ValueError: raise commands.BadArgument() else: _id = member.id author = ctx.author is_bot = self.bot.user.bot if number > 100: cont = await self.check_100_plus(ctx, number) if not cont: return def check(m): if m.author.id == _id: return True elif m == ctx.message: return True else: return False to_delete = await self.get_messages_for_deletion( ctx, channel, number, check=check, limit=1000, before=ctx.message, delete_pinned=delete_pinned, ) reason = ( "{}({}) deleted {} messages " " made by {}({}) in channel {}." "".format(author.name, author.id, len(to_delete), member or "???", _id, channel.name) ) log.info(reason) if is_bot: # For whatever reason the purge endpoint requires manage_messages await mass_purge(to_delete, channel) else: await slow_deletion(to_delete)