Skip to content

Feat: Renaming of snippets and aliases #3383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,61 @@ async def snippet_edit(self, ctx, name: str.lower, *, value):
embed = create_not_found_embed(name, self.bot.snippets.keys(), "Snippet")
await ctx.send(embed=embed)

@snippet.command(name="rename")
@checks.has_permissions(PermissionLevel.SUPPORTER)
async def snippet_rename(self, ctx, name: str.lower, *, value):
"""
Rename a snippet.

To rename a multi-word snippet name, use quotes: ```
{prefix}snippet rename "two word" this is a new two word snippet.
```
"""
if name in self.bot.snippets:
if self.bot.get_command(value):
embed = discord.Embed(
title="Error",
color=self.bot.error_color,
description=f"A command with the same name already exists: `{value}`.",
)
return await ctx.send(embed=embed)
elif value in self.bot.snippets:
embed = discord.Embed(
title="Error",
color=self.bot.error_color,
description=f"Snippet `{value}` already exists.",
)
return await ctx.send(embed=embed)

if value in self.bot.aliases:
embed = discord.Embed(
title="Error",
color=self.bot.error_color,
description=f"An alias that shares the same name exists: `{value}`.",
)
return await ctx.send(embed=embed)

if len(value) > 120:
embed = discord.Embed(
title="Error",
color=self.bot.error_color,
description="Snippet names cannot be longer than 120 characters.",
)
return await ctx.send(embed=embed)
old_snippet_value = self.bot.snippets[name]
self.bot.snippets.pop(name)
self.bot.snippets[value] = old_snippet_value
await self.bot.config.update()

embed = discord.Embed(
title="Renamed snippet",
color=self.bot.main_color,
description=f'`{name}` has been renamed to "{value}".',
)
else:
embed = create_not_found_embed(name, self.bot.snippets.keys(), "Snippet")
await ctx.send(embed=embed)

@commands.command(usage="<category> [options]")
@checks.has_permissions(PermissionLevel.MODERATOR)
@checks.thread_only()
Expand Down
52 changes: 52 additions & 0 deletions cogs/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,58 @@ async def alias_edit(self, ctx, name: str.lower, *, value):
embed = await self.make_alias(name, value, "Edited")
return await ctx.send(embed=embed)

@alias.command(name="rename")
@checks.has_permissions(PermissionLevel.MODERATOR)
async def alias_rename(self, ctx, name: str.lower, *, value):
"""
Rename an alias.
"""
if name not in self.bot.aliases:
embed = utils.create_not_found_embed(name, self.bot.aliases.keys(), "Alias")
return await ctx.send(embed=embed)

embed = None
if self.bot.get_command(value):
embed = discord.Embed(
title="Error",
color=self.bot.error_color,
description=f"A command with the same name already exists: `{value}`.",
)

elif value in self.bot.aliases:
embed = discord.Embed(
title="Error",
color=self.bot.error_color,
description=f"Another alias with the same name already exists: `{value}`.",
)

elif value in self.bot.snippets:
embed = discord.Embed(
title="Error",
color=self.bot.error_color,
description=f"A snippet with the same name already exists: `{value}`.",
)

elif len(value) > 120:
embed = discord.Embed(
title="Error",
color=self.bot.error_color,
description="Alias names cannot be longer than 120 characters.",
)

if embed is None:
old_alias_value = self.bot.aliases[name]
self.bot.aliases.pop(name)
self.bot.aliases[value] = old_alias_value
await self.bot.config.update()

embed = discord.Embed(
title="Alias renamed",
color=self.bot.main_color,
description=f'`{name}` has been renamed to "{value}".',
)
return await ctx.send(embed=embed)

@commands.group(aliases=["perms"], invoke_without_command=True)
@checks.has_permissions(PermissionLevel.OWNER)
async def permissions(self, ctx):
Expand Down
Loading