Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.

Commit 2bb8189

Browse files
committed
Improved vc rename command
1 parent 25e550a commit 2bb8189

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

general/voice_channel/cog.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ def __init__(self, team_roles: list[str]):
199199
if name := name.strip():
200200
self.names[name_list].add(name)
201201

202+
self.allowed_names: set[str] = set()
203+
for path in Path(__file__).parent.joinpath("names").iterdir():
204+
if not path.name.endswith(".txt"):
205+
continue
206+
207+
with path.open() as file:
208+
for name in file.readlines():
209+
if name := name.strip():
210+
self.allowed_names.add(name.lower())
211+
202212
def prepare(self) -> bool:
203213
return bool(self.names)
204214

@@ -1047,14 +1057,19 @@ async def send_voice_info(self, target: Messageable, channel: DynChannel):
10471057
await self.update_control_message(channel, messages[-1])
10481058

10491059
@voice.command(name="rename")
1050-
@VoiceChannelPermission.dyn_rename.check
1051-
@optional_permissions(VoiceChannelPermission.override_owner)
1060+
@optional_permissions(VoiceChannelPermission.dyn_rename, VoiceChannelPermission.override_owner)
10521061
@docs(t.commands.voice_rename)
1053-
async def voice_rename(self, ctx: Context, *, name: str):
1062+
async def voice_rename(self, ctx: Context, *, name: Optional[str]):
10541063
channel, voice_channel = await self.get_channel(ctx.author, check_owner=True)
10551064
text_channel: TextChannel = self.get_text_channel(channel)
10561065
old_name = voice_channel.name
10571066

1067+
if not name:
1068+
name = await self.get_channel_name(ctx.guild)
1069+
elif name.lower() not in self.allowed_names:
1070+
if not await VoiceChannelPermission.dyn_rename.check_permissions(ctx.author):
1071+
raise CommandError(t.no_custom_name)
1072+
10581073
if any(c.id != voice_channel.id and name == c.name for c in voice_channel.guild.voice_channels):
10591074
conf_embed = Embed(title=t.rename_confirmation, description=t.rename_description, color=Colors.Voice)
10601075
async with confirm(ctx, conf_embed) as (result, msg):

general/voice_channel/translations/en.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ dyn_voice_help_content: |
5757
:unlock: `{prefix}vc unlock` - unlock and unhide this voice channel
5858
:white_check_mark: `{prefix}vc add <member>` - add a member to this voice channel
5959
:x: `{prefix}vc remove <member>` - kick and remove a member from this voice channel
60+
:label: `{prefix}vc rename [<name>]` - rename this voice channel
6061
:tools: `{prefix}vc owner <member>` - transfer ownership of this voice channel
6162
:information_source: `{prefix}vc info [<channel>]` - show information about a voice channel
6263
:grey_question: `{prefix}vc help` - show this embed
@@ -98,11 +99,12 @@ renamed: ":label: {} has renamed this channel from `{}` to `{}`."
9899
rename_failed: Renaming this channel failed.
99100
rename_rate_limit: |
100101
Thanks to [Discord's stupid channel edit rate limit](https://support.discord.com/hc/en-us/community/posts/360067755532-Increase-rate-limit-for-editing-channel-description), I can't rename this channel right now. :rolling_eyes:
101-
Please try again later or create a new channel.
102+
Please try again later.
102103
rename_confirmation: Rename this Voice Channel?
103104
rename_description: A voice channel with this name already exists. Do you want to rename this voice channel anyway?
104105
canceled: ":x: Canceled"
105106
confirmed: "Confirmed :white_check_mark:"
107+
no_custom_name: You are not allowed to set a custom channel name! Omit the `name` parameter to choose a random name or pick a name from [theses lists](https://github.com/PyDrocsid/cogs/tree/develop/general/voice_channel/names)!
106108

107109
voice_info: "Voice Channel Information"
108110
voice_owner: "Owner"

0 commit comments

Comments
 (0)