Skip to content

Commit 255f732

Browse files
committed
v3.0.3 snippets/alias edit
1 parent 50257af commit 255f732

File tree

4 files changed

+109
-22
lines changed

4 files changed

+109
-22
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
8+
# v3.0.3
9+
10+
### Added
11+
12+
- New commands, `?alias edit <name> <target>` and `?snippets edit <name> <target>`.
13+
- They can be used to edit aliases and snippets respectively.
14+
715
# v3.0.2
816

917
### Added

bot.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "3.0.2"
1+
__version__ = "3.0.3"
22

33
import asyncio
44
import logging
@@ -271,6 +271,10 @@ def main_category(self) -> typing.Optional[discord.TextChannel]:
271271
def blocked_users(self) -> typing.Dict[str, str]:
272272
return self.config.get("blocked", {})
273273

274+
@property
275+
def blocked_whitelisted_users(self) -> typing.List[str]:
276+
return self.config.get("blocked_whitelist", [])
277+
274278
@property
275279
def prefix(self) -> str:
276280
return self.config.get("prefix", "?")
@@ -443,7 +447,7 @@ async def retrieve_emoji(self) -> typing.Tuple[str, str]:
443447
async def _process_blocked(self, message: discord.Message) -> bool:
444448
sent_emoji, blocked_emoji = await self.retrieve_emoji()
445449

446-
if str(message.author.id) in self.config.blocked_whitelist:
450+
if str(message.author.id) in self.blocked_whitelisted_users:
447451
if str(message.author.id) in self.blocked_users:
448452
del self.config.blocked[str(message.author.id)]
449453
await self.config.update()

cogs/modmail.py

+45-14
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,21 @@ async def snippets_add(self, ctx, name: str.lower, *, value):
147147
{prefix}snippets add "two word" this is a two word snippet.
148148
```
149149
"""
150+
if name in self.bot.config.snippets:
151+
embed = discord.Embed(
152+
title="Error",
153+
color=discord.Color.red(),
154+
description=f"Snippet `{name}` already exists.",
155+
)
156+
else:
157+
self.bot.config.snippets[name] = value
158+
await self.bot.config.update()
150159

151-
self.bot.config.snippets[name] = value
152-
await self.bot.config.update()
153-
154-
embed = discord.Embed(
155-
title="Added snippet",
156-
color=self.bot.main_color,
157-
description=f"`{name}` points to: {value}",
158-
)
160+
embed = discord.Embed(
161+
title="Added snippet",
162+
color=self.bot.main_color,
163+
description=f'`{name}` will now send "{value}".',
164+
)
159165

160166
await ctx.send(embed=embed)
161167

@@ -164,7 +170,7 @@ async def snippets_add(self, ctx, name: str.lower, *, value):
164170
async def snippets_remove(self, ctx, *, name: str.lower):
165171
"""Remove a snippet."""
166172

167-
if self.bot.config.snippets.get(name):
173+
if name in self.bot.config.snippets:
168174
embed = discord.Embed(
169175
title="Removed snippet",
170176
color=self.bot.main_color,
@@ -182,6 +188,27 @@ async def snippets_remove(self, ctx, *, name: str.lower):
182188

183189
await ctx.send(embed=embed)
184190

191+
@snippets.command(name="edit")
192+
@checks.has_permissions(PermissionLevel.SUPPORTER)
193+
async def snippets_edit(self, ctx, name: str.lower, *, value):
194+
if name in self.bot.config.snippets:
195+
self.bot.config.snippets[name] = value
196+
await self.bot.config.update()
197+
198+
embed = discord.Embed(
199+
title="Edited snippet",
200+
color=self.bot.main_color,
201+
description=f'`{name}` will now send "{value}".',
202+
)
203+
204+
else:
205+
embed = discord.Embed(
206+
title="Error",
207+
color=discord.Color.red(),
208+
description=f"Snippet `{name}` does not exist.",
209+
)
210+
await ctx.send(embed=embed)
211+
185212
@commands.command()
186213
@checks.has_permissions(PermissionLevel.MODERATOR)
187214
@checks.thread_only()
@@ -193,7 +220,11 @@ async def move(self, ctx, *, category: discord.CategoryChannel):
193220
"""
194221
thread = ctx.thread
195222
await thread.channel.edit(category=category, sync_permissions=True)
196-
await ctx.message.add_reaction("✅")
223+
sent_emoji, _ = await self.bot.retrieve_emoji()
224+
try:
225+
await ctx.message.add_reaction(sent_emoji)
226+
except (discord.HTTPException, discord.InvalidArgument):
227+
pass
197228

198229
@staticmethod
199230
async def send_scheduled_close_message(ctx, after, silent=False):
@@ -823,16 +854,16 @@ async def blocked_whitelist(self, ctx, *, user: User = None):
823854
mention = getattr(user, "mention", f"`{user.id}`")
824855
msg = ""
825856

826-
if str(user.id) in self.bot.config.blocked_whitelist:
857+
if str(user.id) in self.bot.blocked_whitelisted_users:
827858
embed = discord.Embed(
828859
title="Success",
829860
description=f"{mention} is no longer whitelisted.",
830861
color=self.bot.main_color,
831862
)
832-
self.bot.config.blocked_whitelist.remove(str(user.id))
863+
self.bot.blocked_whitelisted_users.remove(str(user.id))
833864
return await ctx.send(embed=embed)
834865

835-
self.bot.config.blocked_whitelist.append(str(user.id))
866+
self.bot.blocked_whitelisted_users.append(str(user.id))
836867

837868
if str(user.id) in self.bot.blocked_users:
838869
msg = self.bot.blocked_users.get(str(user.id))
@@ -891,7 +922,7 @@ async def block(
891922

892923
mention = getattr(user, "mention", f"`{user.id}`")
893924

894-
if str(user.id) in self.bot.config.blocked_whitelist:
925+
if str(user.id) in self.bot.blocked_whitelisted_users:
895926
embed = discord.Embed(
896927
title="Error",
897928
description=f"Cannot block {mention}, user is whitelisted.",

cogs/utility.py

+50-6
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ async def alias_add(self, ctx, name: str.lower, *, value):
838838
if "aliases" not in self.bot.config.cache:
839839
self.bot.config["aliases"] = {}
840840

841-
if self.bot.get_command(name) or self.bot.config.aliases.get(name):
841+
if self.bot.get_command(name) or name in self.bot.config.aliases:
842842
embed = Embed(
843843
title="Error",
844844
color=Color.red(),
@@ -847,22 +847,22 @@ async def alias_add(self, ctx, name: str.lower, *, value):
847847
)
848848
return await ctx.send(embed=embed)
849849

850-
if not self.bot.get_command(value.split()[0]):
850+
linked_command = value.split()[0]
851+
if not self.bot.get_command(linked_command):
851852
embed = Embed(
852853
title="Error",
853854
color=Color.red(),
854855
description="The command you are attempting to point "
855-
f"to does not exist: `{value.split()[0]}`.",
856+
f"to does not exist: `{linked_command}`.",
856857
)
857-
return await ctx.send(embed=embed)
858858

859859
self.bot.config.aliases[name] = value
860860
await self.bot.config.update()
861861

862862
embed = Embed(
863863
title="Added alias",
864864
color=self.bot.main_color,
865-
description=f"`{name}` points to: {value}",
865+
description=f'`{name}` points to: "{value}".',
866866
)
867867

868868
return await ctx.send(embed=embed)
@@ -875,7 +875,7 @@ async def alias_remove(self, ctx, *, name: str.lower):
875875
if "aliases" not in self.bot.config.cache:
876876
self.bot.config["aliases"] = {}
877877

878-
if self.bot.config.aliases.get(name):
878+
if name in self.bot.config.aliases:
879879
del self.bot.config["aliases"][name]
880880
await self.bot.config.update()
881881

@@ -894,6 +894,50 @@ async def alias_remove(self, ctx, *, name: str.lower):
894894

895895
return await ctx.send(embed=embed)
896896

897+
@alias.command(name="edit")
898+
@checks.has_permissions(PermissionLevel.MODERATOR)
899+
async def alias_edit(self, ctx, name: str.lower, *, value):
900+
if "aliases" not in self.bot.config.cache:
901+
self.bot.config["aliases"] = {}
902+
903+
if name not in self.bot.config.aliases:
904+
embed = Embed(
905+
title="Error",
906+
color=Color.red(),
907+
description=f"Alias `{name}` does not exist.",
908+
)
909+
910+
return await ctx.send(embed=embed)
911+
912+
if self.bot.get_command(name):
913+
embed = Embed(
914+
title="Error",
915+
color=Color.red(),
916+
description="A command or alias already exists "
917+
f"with the same name: `{name}`.",
918+
)
919+
return await ctx.send(embed=embed)
920+
921+
linked_command = value.split()[0]
922+
if not self.bot.get_command(linked_command):
923+
embed = Embed(
924+
title="Error",
925+
color=Color.red(),
926+
description="The command you are attempting to point "
927+
f"to does not exist: `{linked_command}`.",
928+
)
929+
return await ctx.send(embed=embed)
930+
931+
self.bot.config.aliases[name] = value
932+
await self.bot.config.update()
933+
934+
embed = Embed(
935+
title="Edited alias",
936+
color=self.bot.main_color,
937+
description=f'`{name}` now points to: "{value}".',
938+
)
939+
return await ctx.send(embed=embed)
940+
897941
@commands.group(aliases=["perms"], invoke_without_command=True)
898942
@checks.has_permissions(PermissionLevel.OWNER)
899943
async def permissions(self, ctx):

0 commit comments

Comments
 (0)