1
1
import discord
2
2
from discord .ext import commands
3
+ import datetime
3
4
import traceback
4
5
import inspect
5
6
import json
11
12
from core .paginator import PaginatorSession
12
13
from core .decorators import auth_required , owner_only , trigger_typing
13
14
14
- from prettytable import PrettyTable
15
-
16
15
class Utility :
17
16
'''General commands that provide utility'''
18
17
@@ -22,7 +21,7 @@ def __init__(self, bot):
22
21
def format_cog_help (self , ctx , cog ):
23
22
"""Formats the text for a cog help"""
24
23
sigs = []
25
- prefix = self .bot .config . get ( ' prefix' , 'm.' )
24
+ prefix = self .bot .prefix
26
25
27
26
for cmd in self .bot .commands :
28
27
if cmd .hidden :
@@ -50,8 +49,11 @@ def format_cog_help(self, ctx, cog):
50
49
fmt [index ] += f'`{ prefix + cmd .qualified_name :<{maxlen }} ` - '
51
50
fmt [index ] += f'{ cmd .short_doc :<{maxlen }} \n '
52
51
if hasattr (cmd , 'commands' ):
53
- for c in cmd .commands :
54
- branch = '\u200b └─ ' + c .name
52
+ for i , c in enumerate (cmd .commands ):
53
+ if len (cmd .commands ) == i + 1 : # last
54
+ branch = '\u200b └─ ' + c .name
55
+ else :
56
+ branch = '\u200b ├─ ' + c .name
55
57
if len (fmt [index ] + f"`{ branch :<{maxlen + 1 }} ` - " + f"{ c .short_doc :<{maxlen }} \n " ) > 1024 :
56
58
index += 1
57
59
fmt .append ('' )
@@ -75,7 +77,7 @@ def format_cog_help(self, ctx, cog):
75
77
76
78
def format_command_help (self , ctx , cmd ):
77
79
'''Formats command help.'''
78
- prefix = self .bot .config . get ( ' prefix' , 'm.' )
80
+ prefix = self .bot .prefix
79
81
em = discord .Embed (
80
82
color = discord .Color .green (),
81
83
description = cmd .help
@@ -141,7 +143,7 @@ async def help(self, ctx, *, command: str=None):
141
143
142
144
pages = []
143
145
144
- prefix = self .bot .config . get ( ' prefix' , 'm.' )
146
+ prefix = self .bot .prefix
145
147
146
148
for _ , cog in sorted (self .bot .cogs .items ()):
147
149
em = self .format_cog_help (ctx , cog )
@@ -177,15 +179,15 @@ async def about(self, ctx):
177
179
em .add_field (name = 'Latency' , value = f'{ self .bot .latency * 1000 :.2f} ms' )
178
180
179
181
180
- em .add_field (name = 'Version' , value = f'[`{ __version__ } `](https://github.com/kyb3r/modmail/blob/master/bot.py#L25)' )
182
+ em .add_field (name = 'Version' , value = f'[`{ self . bot . version } `](https://github.com/kyb3r/modmail/blob/master/bot.py#L25)' )
181
183
em .add_field (name = 'Author' , value = '[`kyb3r`](https://github.com/kyb3r)' )
182
184
183
185
em .add_field (name = 'Latest Updates' , value = await self .bot .get_latest_updates ())
184
186
185
187
footer = f'Bot ID: { self .bot .user .id } '
186
188
187
189
if meta :
188
- if __version__ != meta ['latest_version' ]:
190
+ if self . bot . version != meta ['latest_version' ]:
189
191
footer = f"A newer version is available v{ meta ['latest_version' ]} "
190
192
else :
191
193
footer = 'You are up to date with the latest version.'
@@ -208,7 +210,7 @@ async def github(self, ctx):
208
210
data = await self .bot .modmail_api .get_user_info ()
209
211
print (data )
210
212
211
- prefix = self .bot .config . get ( ' prefix' , 'm.' )
213
+ prefix = self .bot .prefix
212
214
213
215
em = discord .Embed (title = 'Github' )
214
216
@@ -230,11 +232,11 @@ async def update(self, ctx):
230
232
231
233
em = discord .Embed (
232
234
title = 'Already up to date' ,
233
- description = f'The latest version is [`{ __version__ } `](https://github.com/kyb3r/modmail/blob/master/bot.py#L25)' ,
235
+ description = f'The latest version is [`{ self . bot . version } `](https://github.com/kyb3r/modmail/blob/master/bot.py#L25)' ,
234
236
color = discord .Color .green ()
235
237
)
236
238
237
- if metadata ['latest_version' ] == __version__ :
239
+ if metadata ['latest_version' ] == self . bot . version :
238
240
data = await self .bot .modmail_api .get_user_info ()
239
241
if not data ['error' ]:
240
242
user = data ['user' ]
@@ -246,7 +248,7 @@ async def update(self, ctx):
246
248
user = data ['user' ]
247
249
em .title = 'Success'
248
250
em .set_author (name = user ['username' ], icon_url = user ['avatar_url' ], url = user ['url' ])
249
- em .set_footer (text = f"Updating modmail v{ __version__ } -> v{ metadata ['latest_version' ]} " )
251
+ em .set_footer (text = f"Updating modmail v{ self . bot . version } -> v{ metadata ['latest_version' ]} " )
250
252
251
253
if commit_data :
252
254
em .description = 'Bot successfully updated, the bot will restart momentarily'
@@ -264,14 +266,24 @@ async def update(self, ctx):
264
266
@commands .command (name = "status" , aliases = ['customstatus' , 'presence' ])
265
267
@commands .has_permissions (administrator = True )
266
268
async def _status (self , ctx , * , message ):
267
- '''Set a custom playing status for the bot.'''
269
+ '''Set a custom playing status for the bot.
270
+
271
+ Set the message to `clear` if you want to remove the playing status.
272
+ '''
273
+
268
274
if message == 'clear' :
275
+ self .bot .config ['status' ] = None
276
+ await self .bot .config .update ()
269
277
return await self .bot .change_presence (activity = None )
278
+
279
+
270
280
await self .bot .change_presence (activity = discord .Game (message ))
281
+ self .bot .config ['status' ] = message
282
+ await self .bot .config .update ()
283
+
271
284
em = discord .Embed (title = 'Status Changed' )
272
285
em .description = message
273
286
em .color = discord .Color .green ()
274
- em .set_footer (text = 'Note: this change is temporary.' )
275
287
await ctx .send (embed = em )
276
288
277
289
@commands .command ()
@@ -285,17 +297,66 @@ async def ping(self, ctx):
285
297
em .color = 0x00FF00
286
298
await ctx .send (embed = em )
287
299
300
+ @commands .command ()
301
+ @commands .has_permissions (administrator = True )
302
+ async def mention (self , ctx , * , mention = None ):
303
+ '''Changes what the bot mentions at the start of each thread.'''
304
+ current = self .bot .config .get ("mention" , "@here" )
305
+ em = discord .Embed (
306
+ title = 'Current text' ,
307
+ color = discord .Color .green (),
308
+ description = f'{ current } '
309
+ )
310
+
311
+ if mention is None :
312
+ await ctx .send (embed = em )
313
+ else :
314
+ em .title = 'Changed mention!'
315
+ em .description = f'On thread creation the bot now says: { mention } '
316
+ self .bot .config ['mention' ] = mention
317
+ await self .bot .config .update ()
318
+ await ctx .send (embed = em )
319
+
320
+ @commands .command ()
321
+ @commands .has_permissions (administrator = True )
322
+ async def prefix (self , ctx , * , prefix = None ):
323
+ '''Changes the prefix for the bot.'''
324
+
325
+ current = self .bot .config .get ("prefix" , "m." )
326
+ em = discord .Embed (
327
+ title = 'Current prefix' ,
328
+ color = discord .Color .green (),
329
+ description = f'{ current } '
330
+ )
331
+
332
+ if prefix is None :
333
+ await ctx .send (embed = em )
334
+ else :
335
+ em .title = 'Changed prefix!'
336
+ em .description = f'Set prefix to `{ prefix } `'
337
+ self .bot .config ['prefix' ] = prefix
338
+
339
+ await self .bot .config .update ()
340
+ await ctx .send (embed = em )
341
+
342
+
288
343
@commands .group ()
289
344
@owner_only ()
290
345
async def config (self , ctx ):
291
- '''Change configuration for the bot.'''
346
+ '''Change configuration for the bot.
347
+
348
+ You shouldn't have to use these commands as other commands such
349
+ as `prefix` and `status` should change config vars for you.
350
+ '''
292
351
if ctx .invoked_subcommand is None :
293
352
cmd = self .bot .get_command ('help' )
294
353
await ctx .invoke (cmd , command = 'config' )
295
354
296
355
@config .command (name = 'set' )
297
356
async def _set (self , ctx , key : str .lower , * , value ):
298
- '''Sets a configuration variable and its value'''
357
+ '''
358
+ Sets a configuration variable and its value
359
+ '''
299
360
300
361
em = discord .Embed (
301
362
title = 'Success' ,
@@ -364,7 +425,76 @@ async def get(self, ctx, key=None):
364
425
await ctx .send (embed = em )
365
426
366
427
428
+ @commands .group (name = 'alias' , aliases = ['aliases' ])
429
+ @commands .has_permissions (manage_messages = True )
430
+ async def aliases (self , ctx ):
431
+ '''Returns a list of aliases that are currently set.'''
432
+ if ctx .invoked_subcommand is not None :
433
+ return
367
434
435
+ embeds = []
436
+
437
+ em = discord .Embed (color = discord .Color .green ())
438
+ em .set_author (name = 'Command aliases' , icon_url = ctx .guild .icon_url )
439
+
440
+ embeds .append (em )
441
+
442
+ em .description = 'Here is a list of aliases that are currently configured.'
443
+
444
+ if not self .bot .aliases :
445
+ em .color = discord .Color .red ()
446
+ em .description = f'You dont have any aliases at the moment.'
447
+ em .set_footer (text = f'Do { self .bot .prefix } help aliases for more commands.' )
448
+
449
+ for name , value in self .bot .aliases .items ():
450
+ if len (em .fields ) == 5 :
451
+ em = discord .Embed (color = discord .Color .green (), description = em .description )
452
+ em .set_author (name = 'Command aliases' , icon_url = ctx .guild .icon_url )
453
+ embeds .append (em )
454
+ em .add_field (name = name , value = value , inline = False )
455
+
456
+ session = PaginatorSession (ctx , * embeds )
457
+ await session .run ()
458
+
459
+ @aliases .command (name = 'add' )
460
+ async def _add (self , ctx , name : str .lower , * , value ):
461
+ '''Add an alias to the bot config.'''
462
+ if 'aliases' not in self .bot .config .cache :
463
+ self .bot .config ['aliases' ] = {}
464
+
465
+ self .bot .config .aliases [name ] = value
466
+ await self .bot .config .update ()
467
+
468
+ em = discord .Embed (
469
+ title = 'Added alias' ,
470
+ color = discord .Color .green (),
471
+ description = f'`{ name } ` points to: { value } '
472
+ )
473
+
474
+ await ctx .send (embed = em )
475
+
476
+ @aliases .command (name = 'del' )
477
+ async def __del (self , ctx , * , name : str .lower ):
478
+ '''Removes a alias from bot config.'''
479
+
480
+ if 'aliases' not in self .bot .config .cache :
481
+ self .bot .config ['aliases' ] = {}
482
+
483
+ em = discord .Embed (
484
+ title = 'Removed alias' ,
485
+ color = discord .Color .green (),
486
+ description = f'`{ name } ` no longer exists.'
487
+ )
488
+
489
+ if not self .bot .config .aliases .get (name ):
490
+ em .title = 'Error'
491
+ em .color = discord .Color .red ()
492
+ em .description = f'Alias `{ name } ` does not exist.'
493
+ else :
494
+ self .bot .config ['aliases' ][name ] = None
495
+ await self .bot .config .update ()
496
+
497
+ await ctx .send (embed = em )
368
498
369
499
@commands .command (hidden = True , name = 'eval' )
370
500
@owner_only ()
@@ -447,12 +577,8 @@ def paginate(text: str):
447
577
break
448
578
await ctx .send (f'```py\n { page } \n ```' )
449
579
450
- if out :
451
- await ctx .message .add_reaction ('\u2705 ' ) # tick
452
- elif err :
453
- await ctx .message .add_reaction ('\u2049 ' ) # x
454
- else :
455
- await ctx .message .add_reaction ('\u2705 ' )
580
+ if err :
581
+ await ctx .message .add_reaction ('\u2049 ' )
456
582
457
583
458
584
def setup (bot ):
0 commit comments