2
2
Contains commands relating to administrator tasks.
3
3
"""
4
4
5
+ import black
5
6
import discord .ext .commands as commands
6
7
import discord .ui as UI
7
8
import helpers
@@ -143,7 +144,7 @@ async def unban(ctx: commands.Context, user: discord.User):
143
144
await helpers .lift_ban (ctx , "permanent" , user )
144
145
145
146
146
- @commands .command ()
147
+ @commands .command (aliases = [ 'bladd' ] )
147
148
@commands .has_permissions (manage_messages = True )
148
149
@commands .cooldown (1 , 2 , commands .BucketType .user )
149
150
async def blacklist (ctx : commands .Context , * , word : str ):
@@ -161,6 +162,7 @@ async def blacklist(ctx: commands.Context, *, word: str):
161
162
"""
162
163
filepath = 'files/blacklist.json'
163
164
id = str (ctx .guild .id )
165
+ word = word .lower ()
164
166
165
167
with open (filepath , 'r' ) as file :
166
168
blacklist : dict = json .load (file )
@@ -180,6 +182,61 @@ async def blacklist(ctx: commands.Context, *, word: str):
180
182
await ctx .send (f':tools: \' { word } \' has been added to the blacklist.' )
181
183
182
184
185
+ @commands .command (aliases = ['blclear' ])
186
+ @commands .has_permissions (manage_messages = True )
187
+ async def clearblacklist (ctx : commands .Context ):
188
+ """
189
+ Clears the blacklist for a server.
190
+
191
+ Parameters
192
+ ----------
193
+
194
+ ctx (Context):
195
+ Command invocation context.
196
+ """
197
+ filepath = 'files/blacklist.json'
198
+ id = str (ctx .guild .id )
199
+
200
+ with open (filepath ) as file :
201
+ blacklist : dict = json .load (file )
202
+
203
+ mention = ctx .author .mention
204
+
205
+ if id not in blacklist .keys ():
206
+ return await ctx .send (f':x: { mention } : This server does not have any words blacklisted.' )
207
+
208
+ yes_button = UI .Button (label = 'Yes' , style = discord .ButtonStyle .green , emoji = '👍🏻' )
209
+ no_button = UI .Button (label = 'No' , style = discord .ButtonStyle .red , emoji = '👎🏻' )
210
+
211
+ async def yes (interaction : discord .Interaction ):
212
+ for server_id in blacklist .keys ():
213
+ if server_id == id :
214
+ del blacklist [server_id ]
215
+
216
+ with open (filepath , 'w' ) as file :
217
+ json .dump (blacklist , file , indent = 4 )
218
+
219
+ return await interaction .message .channel .send (f':thumbsup: { mention } : The blacklist for this server'
220
+ + f'has successfully been deleted.' )
221
+
222
+ yes_button .callback = yes
223
+
224
+ async def no (interaction : discord .Interaction ):
225
+ return await interaction .message .channel .send (f':thumbsup: { mention } : Ok!' )
226
+
227
+ no_button .callback = no
228
+
229
+ view = UI .View ()
230
+ view .add_item (yes_button )
231
+ view .add_item (no_button )
232
+
233
+ await ctx .send (
234
+ f':warning: { mention } : Are you sure you\' d like to clear your server\' s blacklist?\n '
235
+ + f'This action cannot be undone.' ,
236
+ view = view
237
+ )
238
+
239
+
183
240
# |----- REGISTERING MODULE -----|
184
241
185
242
@@ -193,4 +250,13 @@ def setup(client: commands.Bot):
193
250
client (Bot):
194
251
Client instance, to add the commands to.
195
252
"""
196
- helpers .add_commands (client , clear , kick , ban , softban , unban , blacklist )
253
+ helpers .add_commands (
254
+ client ,
255
+ clear ,
256
+ kick ,
257
+ ban ,
258
+ softban ,
259
+ unban ,
260
+ blacklist ,
261
+ clearblacklist
262
+ )
0 commit comments