@@ -30,8 +30,8 @@ async def setup(self, ctx):
3030 await categ .edit (position = 0 )
3131
3232 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. ' )
3535
3636 await ctx .send ('Successfully set up server.' )
3737
@@ -87,9 +87,6 @@ async def _add(self, ctx, name: str.lower, *, value):
8787 async def __del (self , ctx , * , name : str .lower ):
8888 """Removes a snippet from bot config."""
8989
90- if 'snippets' not in self .bot .config .cache :
91- self .bot .config ['snippets' ] = {}
92-
9390 em = discord .Embed (
9491 title = 'Removed snippet' ,
9592 color = discord .Color .green (),
@@ -101,7 +98,7 @@ async def __del(self, ctx, *, name: str.lower):
10198 em .color = discord .Color .red ()
10299 em .description = f'Snippet `{ name } ` does not exist.'
103100 else :
104- self .bot .config ['snippets' ][name ] = None
101+ del self .bot .config ['snippets' ][name ]
105102 await self .bot .config .update ()
106103
107104 await ctx .send (embed = em )
@@ -138,8 +135,7 @@ async def _close(self, ctx):
138135 pass
139136
140137 # Logging
141- categ = self .bot .main_category
142- log_channel = categ .channels [0 ]
138+ log_channel = self .bot .log_channel
143139
144140 log_data = await self .bot .modmail_api .post_log (ctx .channel .id , {
145141 'open' : False , 'closed_at' : str (datetime .datetime .utcnow ()), 'closer' : {
@@ -151,6 +147,9 @@ async def _close(self, ctx):
151147 }
152148 })
153149
150+ if isinstance (log_data , str ):
151+ print (log_data ) # error
152+
154153 log_url = f"https://logs.modmail.tk/{ log_data ['user_id' ]} /{ log_data ['key' ]} "
155154
156155 user = thread .recipient .mention if thread .recipient else f'`{ thread .id } `'
@@ -300,19 +299,19 @@ async def blocked(self, ctx):
300299 users = []
301300 not_reachable = []
302301
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 ) )
305304 if user :
306- users .append (user )
305+ users .append (( user , reason ) )
307306 else :
308- not_reachable .append (id )
307+ not_reachable .append (( id , reason ) )
309308
310309 em .description = 'Here is a list of blocked users.'
311310
312311 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 ))
314313 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 )
316315
317316 if not users and not not_reachable :
318317 em .description = 'Currently there are no blocked users'
@@ -322,7 +321,7 @@ async def blocked(self, ctx):
322321 @commands .command ()
323322 @trigger_typing
324323 @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 ):
326325 """Block a user from using modmail."""
327326
328327 if user is None :
@@ -332,21 +331,18 @@ async def block(self, ctx, *, user: Union[discord.Member, discord.User, obj]=Non
332331 else :
333332 raise commands .UserInputError
334333
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+
340335 mention = user .mention if hasattr (user , 'mention' ) else f'`{ user .id } `'
341336
342337 em = discord .Embed ()
343338 em .color = discord .Color .green ()
344339
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 ()
347343
348344 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 ' '
350346
351347 await ctx .send (embed = em )
352348 else :
@@ -369,18 +365,14 @@ async def unblock(self, ctx, *, user: Union[discord.Member, discord.User, obj]=N
369365 else :
370366 raise commands .UserInputError
371367
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-
377368 mention = user .mention if hasattr (user , 'mention' ) else f'`{ user .id } `'
378369
379370 em = discord .Embed ()
380371 em .color = discord .Color .green ()
381372
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 ()
384376
385377 em .title = 'Success'
386378 em .description = f'{ mention } is no longer blocked'
0 commit comments