Skip to content

Commit 0f1b8ae

Browse files
committed
Changed output messages and added doc comments
1 parent 416dc39 commit 0f1b8ae

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
lines changed

cogs/misc/misc_cog.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ async def choose(self, ctx: commands.Context, *choices: str):
7979
~choose [...choices]
8080
```
8181
"""
82-
await ctx.send(random.choice(choices))
82+
embed = discord.Embed(title=f'🎲 I choose {random.choice(choices)}')
83+
await ctx.send(embed=embed)
8384

8485
@commands.command()
8586
async def meme(self, ctx: commands.Context):

utils/buttons.py

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,54 @@ class ClearMessagesView(discord.ui.View):
99
def __init__(self, ctx: commands.Context, *, timeout: Optional[float] = 180):
1010
super().__init__(timeout=timeout)
1111
self.ctx = ctx
12-
12+
1313
async def on_timeout(self) -> None:
1414
await self.disable_all_buttons()
1515

1616
async def disable_all_buttons(self, interaction: discord.Interaction = None):
17+
"""
18+
Disables all buttons.
19+
"""
1720
interaction = interaction or self
21+
1822
for child in self.children:
1923
child.disabled = True
24+
2025
await interaction.message.edit(view=self)
2126
self.stop()
2227

2328
async def interaction_check(self, interaction: discord.Interaction) -> bool:
29+
"""
30+
Prevents users who weren't the command sender from using buttons.
31+
"""
2432
if interaction.user.id == self.ctx.author.id:
2533
return True
2634
else:
27-
await interaction.response.send_message("This isn't your interaction, and thus you can't use this!")
35+
await interaction.response.send_message(":x: This isn't your interaction!")
2836
return False
29-
37+
3038
@discord.ui.button(label="Yes", style=discord.ButtonStyle.green, emoji="👍🏻")
3139
async def yes(self, interaction: discord.Interaction, _: discord.Button):
40+
"""
41+
Callback method for the yes button.
42+
"""
3243
await interaction.response.defer() # manually defer interaction for an increased respond time
44+
3345
channel_pos = interaction.channel.position
3446
category = interaction.channel.category
3547
new_channel = await interaction.channel.clone()
48+
3649
await new_channel.edit(category=category, position=channel_pos)
3750
await interaction.channel.delete()
51+
3852
self.stop()
39-
53+
4054
@discord.ui.button(label="No", style=discord.ButtonStyle.red, emoji="👎🏻")
4155
async def no(self, interaction: discord.Interaction, _: discord.Button):
42-
await interaction.response.send_message('Aborting command')
56+
"""
57+
Callback method for the no button.
58+
"""
59+
await interaction.response.send_message('👍🏻 Aborting command!')
4360
await self.disable_all_buttons(interaction)
4461

4562
class BlacklistClearButton(discord.ui.View):
@@ -49,13 +66,19 @@ def __init__(self, ctx: commands.Context, *, data: dict, timeout: Optional[float
4966
self.ctx = ctx
5067

5168
async def interaction_check(self, interaction: discord.Interaction) -> bool:
69+
"""
70+
Prevents users who weren't the command sender from using buttons.
71+
"""
5272
if interaction.user.id == self.ctx.author.id:
5373
return True
5474
else:
55-
await interaction.response.send_message("This isn't your interaction, and thus you can't use this!")
75+
await interaction.response.send_message(":x: This isn't your interaction!")
5676
return False
5777

5878
async def disable_all_buttons(self, interaction: discord.Interaction = None):
79+
"""
80+
Disables all buttons.
81+
"""
5982
interaction = interaction or self
6083
for child in self.children:
6184
child.disabled = True
@@ -64,21 +87,29 @@ async def disable_all_buttons(self, interaction: discord.Interaction = None):
6487

6588
@discord.ui.button(label="Yes", style=discord.ButtonStyle.green, emoji="👍🏻")
6689
async def yes(self, interaction: discord.Interaction, _: discord.Button):
90+
"""
91+
Callback method for the yes button.
92+
"""
6793
await interaction.response.defer() # manually defer interaction for an increased respond time
68-
mention = interaction.user.mention
94+
6995
server_id = str(interaction.guild.id)
7096
server = self.blacklist.get(server_id)
97+
7198
if server:
7299
del self.blacklist[server_id]
100+
73101
interaction.client.update_json('./files/blacklist.json', self.blacklist)
74-
await interaction.followup.send(
75-
f":thumbsup: {mention}: The blacklist for this server" \
76-
f" has successfully been deleted."
77-
)
102+
embed = discord.Embed(title='🛠️ Blacklist successfully deleted.')
103+
104+
await interaction.followup.send(embed=embed)
78105
await self.disable_all_buttons(interaction)
79106

80107
@discord.ui.button(label="No", style=discord.ButtonStyle.red, emoji="👎🏻")
81108
async def no(self, interaction: discord.Interaction, _: discord.Button):
109+
"""
110+
Callback method for the no button.
111+
"""
82112
mention = interaction.user.mention
113+
83114
await interaction.response.send_message(f":thumbsup: {mention}: Ok!")
84115
await self.disable_all_buttons(interaction)

0 commit comments

Comments
 (0)