@@ -30,8 +30,8 @@ async def setup(self, ctx):
30
30
await categ .edit (position = 0 )
31
31
32
32
c = await self .bot .modmail_guild .create_text_channel (name = 'bot-logs' , category = categ )
33
- await c .edit (topic = 'Manually add user id \' s to block users. \n \n '
34
- 'Blocked \n ------- \n \n ' )
33
+ await c .edit (topic = 'You can delete this channel if you set up your own log channel.' )
34
+ await c . send ( 'Use the `config set log_channel_id` command to set up a custom log channel. ' )
35
35
36
36
await ctx .send ('Successfully set up server.' )
37
37
@@ -87,9 +87,6 @@ async def _add(self, ctx, name: str.lower, *, value):
87
87
async def __del (self , ctx , * , name : str .lower ):
88
88
"""Removes a snippet from bot config."""
89
89
90
- if 'snippets' not in self .bot .config .cache :
91
- self .bot .config ['snippets' ] = {}
92
-
93
90
em = discord .Embed (
94
91
title = 'Removed snippet' ,
95
92
color = discord .Color .green (),
@@ -101,7 +98,7 @@ async def __del(self, ctx, *, name: str.lower):
101
98
em .color = discord .Color .red ()
102
99
em .description = f'Snippet `{ name } ` does not exist.'
103
100
else :
104
- self .bot .config ['snippets' ][name ] = None
101
+ del self .bot .config ['snippets' ][name ]
105
102
await self .bot .config .update ()
106
103
107
104
await ctx .send (embed = em )
@@ -138,8 +135,7 @@ async def _close(self, ctx):
138
135
pass
139
136
140
137
# Logging
141
- categ = self .bot .main_category
142
- log_channel = categ .channels [0 ]
138
+ log_channel = self .bot .log_channel
143
139
144
140
log_data = await self .bot .modmail_api .post_log (ctx .channel .id , {
145
141
'open' : False , 'closed_at' : str (datetime .datetime .utcnow ()), 'closer' : {
@@ -151,6 +147,9 @@ async def _close(self, ctx):
151
147
}
152
148
})
153
149
150
+ if isinstance (log_data , str ):
151
+ print (log_data ) # error
152
+
154
153
log_url = f"https://logs.modmail.tk/{ log_data ['user_id' ]} /{ log_data ['key' ]} "
155
154
156
155
user = thread .recipient .mention if thread .recipient else f'`{ thread .id } `'
@@ -300,19 +299,19 @@ async def blocked(self, ctx):
300
299
users = []
301
300
not_reachable = []
302
301
303
- for id in self .bot .blocked_users :
304
- user = self .bot .get_user (id )
302
+ for id , reason in self .bot .blocked_users . items () :
303
+ user = self .bot .get_user (int ( id ) )
305
304
if user :
306
- users .append (user )
305
+ users .append (( user , reason ) )
307
306
else :
308
- not_reachable .append (id )
307
+ not_reachable .append (( id , reason ) )
309
308
310
309
em .description = 'Here is a list of blocked users.'
311
310
312
311
if users :
313
- em .add_field (name = 'Currently Known' , value = ' ' .join (u .mention for u in users ))
312
+ em .add_field (name = 'Currently Known' , value = '\n ' .join (u .mention + ( f' - ` { r } `' if r else '' ) for u , r in users ))
314
313
if not_reachable :
315
- em .add_field (name = 'Unknown' , value = '\n ' .join (f'`{ i } `' for i in not_reachable ), inline = False )
314
+ em .add_field (name = 'Unknown' , value = '\n ' .join (f'`{ i } `' + ( f' - ` { r } `' if r else '' ) for i , r in not_reachable ), inline = False )
316
315
317
316
if not users and not not_reachable :
318
317
em .description = 'Currently there are no blocked users'
@@ -322,7 +321,7 @@ async def blocked(self, ctx):
322
321
@commands .command ()
323
322
@trigger_typing
324
323
@commands .has_permissions (manage_channels = True )
325
- async def block (self , ctx , * , user : Union [discord .Member , discord .User , obj ]= None ):
324
+ async def block (self , ctx , user : Union [discord .Member , discord .User , obj ]= None , * , reason = None ):
326
325
"""Block a user from using modmail."""
327
326
328
327
if user is None :
@@ -332,21 +331,18 @@ async def block(self, ctx, *, user: Union[discord.Member, discord.User, obj]=Non
332
331
else :
333
332
raise commands .UserInputError
334
333
335
- categ = self .bot .main_category
336
- top_chan = categ .channels [0 ] # bot-info
337
- topic = str (top_chan .topic )
338
- topic += '\n ' + str (user .id )
339
-
334
+
340
335
mention = user .mention if hasattr (user , 'mention' ) else f'`{ user .id } `'
341
336
342
337
em = discord .Embed ()
343
338
em .color = discord .Color .green ()
344
339
345
- if str (user .id ) not in top_chan .topic :
346
- await top_chan .edit (topic = topic )
340
+ if str (user .id ) not in self .bot .blocked_users :
341
+ self .bot .config .blocked [str (user .id )] = reason
342
+ await self .bot .config .update ()
347
343
348
344
em .title = 'Success'
349
- em .description = f'{ mention } is now blocked'
345
+ em .description = f'{ mention } is now blocked ' + f'for ` { reason } `' if reason else ' '
350
346
351
347
await ctx .send (embed = em )
352
348
else :
@@ -369,18 +365,14 @@ async def unblock(self, ctx, *, user: Union[discord.Member, discord.User, obj]=N
369
365
else :
370
366
raise commands .UserInputError
371
367
372
- categ = self .bot .main_category
373
- top_chan = categ .channels [0 ] # thread-logs
374
- topic = str (top_chan .topic )
375
- topic = topic .replace ('\n ' + str (user .id ), '' )
376
-
377
368
mention = user .mention if hasattr (user , 'mention' ) else f'`{ user .id } `'
378
369
379
370
em = discord .Embed ()
380
371
em .color = discord .Color .green ()
381
372
382
- if str (user .id ) in top_chan .topic :
383
- await top_chan .edit (topic = topic )
373
+ if str (user .id ) in self .bot .blocked_users :
374
+ del self .bot .config .blocked [str (user .id )]
375
+ await self .bot .config .update ()
384
376
385
377
em .title = 'Success'
386
378
em .description = f'{ mention } is no longer blocked'
0 commit comments