async def redirect_remove(self, ctx, *, cmds: str): if cmds != "all": cmds = cmds.replace(" ", "").split(",") realcmds = [ name.lower() for name in cmds if name in [command.name.lower() for command in self.bot.commands] ] if not realcmds: raise customerrors.InvalidCommandSpecified() description = f"{ctx.author.mention}, the commands `{'` `'.join(realcmds)}` will no longer be redirected." rtype = 'override' else: description = f"{ctx.author.mention}, all commands will no longer be redirected." realcmds = None rtype = 'all' panel = await gcmds.confirmation(ctx, description) try: for reaction in reactions: await panel.add_reaction(reaction) except Exception: return await gcmds.cancelled(ctx, "remove redirect") def reacted(reaction: discord.Reaction, user: discord.User): return reaction.emoji in reactions and user.id == ctx.author.id and reaction.message.id == panel.id try: result = await self.bot.wait_for("reaction_add", check=reacted, timeout=30) except asyncio.TimeoutError: return await gcmds.timeout(ctx, "remove redirect", 30) await gcmds.smart_delete(panel) if result[0].emoji == reactions[0]: try: async with self.bot.db.acquire() as con: if realcmds: for name in realcmds: await con.execute( f"DELETE FROM redirects WHERE command='{name}' AND guild_id={ctx.guild.id}" ) else: for command in self.bot.commands: await con.execute( f"DELETE FROM redirects WHERE command='{command.name.lower()}' AND guild_id={ctx.guild.id}" ) except Exception: raise customerrors.RedirectRemoveError() embed = discord.Embed( title="Redirects Removed Successfully", description= f"{ctx.author.mention}, the redirects were removed successfully", color=discord.Color.blue()) return await ctx.channel.send(embed=embed) else: return await gcmds.cancelled(ctx, "remove redirect")
async def redirect_set(self, ctx, channel: discord.TextChannel, *, cmds: str): if cmds != "all": cmds = cmds.replace(" ", "").split(",") realcmds = [ name.lower() for name in cmds if name in [command.name.lower() for command in self.bot.commands] ] if not realcmds: raise customerrors.InvalidCommandSpecified() description = f"{ctx.author.mention}, the commands `{'` `'.join(realcmds)}` will be redirected to {channel.mention}." rtype = 'override' else: description = f"{ctx.author.mention}, all commands will be redirected to {channel.mention}." realcmds = None rtype = 'all' panel = await gcmds.confirmation(ctx, description) try: for reaction in reactions: await panel.add_reaction(reaction) except Exception: return await gcmds.cancelled(ctx, "set redirect") def reacted(reaction: discord.Reaction, user: discord.User): return reaction.emoji in reactions and user.id == ctx.author.id and reaction.message.id == panel.id try: result = await self.bot.wait_for("reaction_add", check=reacted, timeout=30) except asyncio.TimeoutError: return await gcmds.timeout(ctx, "set redirect", 30) await gcmds.smart_delete(panel) if result[0].emoji == reactions[0]: try: async with self.bot.db.acquire() as con: if realcmds: for name in realcmds: result = await con.fetchval( f"SELECT type FROM redirects WHERE guild_id={ctx.guild.id} AND command='{name}'" ) if not result: values = f"($tag${rtype}$tag$, '{name}', {channel.id}, {ctx.guild.id}, {ctx.author.id})" await con.execute( f"INSERT INTO redirects(type, command, channel_id, guild_id, author_id) VALUES {values}" ) else: await con.execute( f"UPDATE redirects SET type='override', channel_id={channel.id}, " f"author_id={ctx.author.id} WHERE command='{name}' AND guild_id={ctx.guild.id}" ) else: for command in self.bot.commands: result = await con.fetchval( f"SELECT type FROM redirects WHERE guild_id={ctx.guild.id} AND command='{command.name.lower()}'" ) if not result: values = f"($tag${rtype}$tag$, '{command.name.lower()}', {channel.id}, {ctx.guild.id}, {ctx.author.id})" await con.execute( f"INSERT INTO redirects(type, command, channel_id, guild_id, author_id) VALUES {values}" ) else: await con.execute( f"UPDATE redirects SET type='all', channel_id={channel.id}, " f"author_id={ctx.author.id} WHERE command='{command.name.lower()}' AND guild_id={ctx.guild.id}" ) except Exception: raise customerrors.RedirectSetError() embed = discord.Embed( title="Redirects Set Successfully", description= f"{ctx.author.mention}, the redirects were set successfully", color=discord.Color.blue()) return await ctx.channel.send(embed=embed) else: return await gcmds.cancelled(ctx, "set redirect")