@@ -9,37 +9,54 @@ class ClearMessagesView(discord.ui.View):
9
9
def __init__ (self , ctx : commands .Context , * , timeout : Optional [float ] = 180 ):
10
10
super ().__init__ (timeout = timeout )
11
11
self .ctx = ctx
12
-
12
+
13
13
async def on_timeout (self ) -> None :
14
14
await self .disable_all_buttons ()
15
15
16
16
async def disable_all_buttons (self , interaction : discord .Interaction = None ):
17
+ """
18
+ Disables all buttons.
19
+ """
17
20
interaction = interaction or self
21
+
18
22
for child in self .children :
19
23
child .disabled = True
24
+
20
25
await interaction .message .edit (view = self )
21
26
self .stop ()
22
27
23
28
async def interaction_check (self , interaction : discord .Interaction ) -> bool :
29
+ """
30
+ Prevents users who weren't the command sender from using buttons.
31
+ """
24
32
if interaction .user .id == self .ctx .author .id :
25
33
return True
26
34
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!" )
28
36
return False
29
-
37
+
30
38
@discord .ui .button (label = "Yes" , style = discord .ButtonStyle .green , emoji = "👍🏻" )
31
39
async def yes (self , interaction : discord .Interaction , _ : discord .Button ):
40
+ """
41
+ Callback method for the yes button.
42
+ """
32
43
await interaction .response .defer () # manually defer interaction for an increased respond time
44
+
33
45
channel_pos = interaction .channel .position
34
46
category = interaction .channel .category
35
47
new_channel = await interaction .channel .clone ()
48
+
36
49
await new_channel .edit (category = category , position = channel_pos )
37
50
await interaction .channel .delete ()
51
+
38
52
self .stop ()
39
-
53
+
40
54
@discord .ui .button (label = "No" , style = discord .ButtonStyle .red , emoji = "👎🏻" )
41
55
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!' )
43
60
await self .disable_all_buttons (interaction )
44
61
45
62
class BlacklistClearButton (discord .ui .View ):
@@ -49,13 +66,19 @@ def __init__(self, ctx: commands.Context, *, data: dict, timeout: Optional[float
49
66
self .ctx = ctx
50
67
51
68
async def interaction_check (self , interaction : discord .Interaction ) -> bool :
69
+ """
70
+ Prevents users who weren't the command sender from using buttons.
71
+ """
52
72
if interaction .user .id == self .ctx .author .id :
53
73
return True
54
74
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!" )
56
76
return False
57
77
58
78
async def disable_all_buttons (self , interaction : discord .Interaction = None ):
79
+ """
80
+ Disables all buttons.
81
+ """
59
82
interaction = interaction or self
60
83
for child in self .children :
61
84
child .disabled = True
@@ -64,21 +87,29 @@ async def disable_all_buttons(self, interaction: discord.Interaction = None):
64
87
65
88
@discord .ui .button (label = "Yes" , style = discord .ButtonStyle .green , emoji = "👍🏻" )
66
89
async def yes (self , interaction : discord .Interaction , _ : discord .Button ):
90
+ """
91
+ Callback method for the yes button.
92
+ """
67
93
await interaction .response .defer () # manually defer interaction for an increased respond time
68
- mention = interaction . user . mention
94
+
69
95
server_id = str (interaction .guild .id )
70
96
server = self .blacklist .get (server_id )
97
+
71
98
if server :
72
99
del self .blacklist [server_id ]
100
+
73
101
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 )
78
105
await self .disable_all_buttons (interaction )
79
106
80
107
@discord .ui .button (label = "No" , style = discord .ButtonStyle .red , emoji = "👎🏻" )
81
108
async def no (self , interaction : discord .Interaction , _ : discord .Button ):
109
+ """
110
+ Callback method for the no button.
111
+ """
82
112
mention = interaction .user .mention
113
+
83
114
await interaction .response .send_message (f":thumbsup: { mention } : Ok!" )
84
115
await self .disable_all_buttons (interaction )
0 commit comments