22
22
SOFTWARE.
23
23
'''
24
24
25
- __version__ = '1.5.1 '
25
+ __version__ = '1.5.0 '
26
26
27
27
from contextlib import redirect_stdout
28
28
from urllib .parse import urlparse
29
29
from copy import deepcopy
30
+ import functools
30
31
import asyncio
31
32
import textwrap
32
33
import traceback
46
47
from utils .paginator import PaginatorSession
47
48
from utils .api import Github , ModmailApiClient
48
49
49
-
50
50
class Modmail (commands .Bot ):
51
51
52
52
def __init__ (self ):
@@ -90,6 +90,19 @@ async def get_pre(bot, message):
90
90
'''Returns the prefix.'''
91
91
p = bot .config .get ('PREFIX' ) or 'm.'
92
92
return [p , f'<@{ bot .user .id } > ' , f'<@!{ bot .user .id } > ' ]
93
+
94
+ def owner_only ():
95
+ async def predicate (ctx ):
96
+ allowed = [int (x ) for x in ctx .bot .config .get ('OWNERS' , '0' ).split (',' )]
97
+ return ctx .author .id in allowed
98
+ return commands .check (predicate )
99
+
100
+ def trigger_typing (func ):
101
+ @functools .wraps (func )
102
+ async def wrapper (self , ctx , * args , ** kwargs ):
103
+ await ctx .trigger_typing ()
104
+ return await func (self , ctx , * args , ** kwargs )
105
+ return wrapper
93
106
94
107
async def on_connect (self ):
95
108
print ('---------------' )
@@ -138,14 +151,6 @@ async def on_message(self, message):
138
151
message .content = f'{ prefix } reply { self .snippets [cmd ]} '
139
152
140
153
await self .process_commands (message )
141
-
142
- async def process_commands (self , message ):
143
- if message .author .bot :
144
- return
145
- ctx = await self .get_context (message )
146
- if ctx .command is not None :
147
- await ctx .trigger_typing ()
148
- await self .invoke (ctx )
149
154
150
155
async def on_message_delete (self , message ):
151
156
'''Support for deleting linked messages'''
@@ -272,6 +277,7 @@ def uptime(self):
272
277
return fmt .format (d = days , h = hours , m = minutes , s = seconds )
273
278
274
279
@commands .command ()
280
+ @trigger_typing
275
281
async def help (self , ctx ):
276
282
prefix = self .config .get ('PREFIX' , 'm.' )
277
283
@@ -286,6 +292,7 @@ async def help(self, ctx):
286
292
await session .run ()
287
293
288
294
@commands .command ()
295
+ @trigger_typing
289
296
async def about (self , ctx ):
290
297
em = discord .Embed (color = discord .Color .green (), timestamp = datetime .datetime .utcnow ())
291
298
em .set_author (name = 'Mod Mail - Information' , icon_url = self .user .avatar_url )
@@ -328,6 +335,8 @@ async def about(self, ctx):
328
335
await ctx .send (embed = em )
329
336
330
337
@commands .group (invoke_without_subcommand = True )
338
+ @owner_only ()
339
+ @trigger_typing
331
340
async def github (self , ctx ):
332
341
if ctx .invoked_subcommand :
333
342
return
@@ -355,6 +364,8 @@ async def github(self, ctx):
355
364
await ctx .send (embed = em )
356
365
357
366
@github .command (name = 'login' )
367
+ @owner_only ()
368
+ @trigger_typing
358
369
async def _login (self , ctx ):
359
370
client = ModmailApiClient (self )
360
371
@@ -380,6 +391,8 @@ async def _login(self, ctx):
380
391
await ctx .author .send (embed = em )
381
392
382
393
@github .command (name = 'logout' )
394
+ @owner_only ()
395
+ @trigger_typing
383
396
async def _logout (self , ctx ):
384
397
client = ModmailApiClient (self )
385
398
data = await client .logout ()
@@ -403,12 +416,10 @@ async def _logout(self, ctx):
403
416
await ctx .send (embed = em )
404
417
405
418
@commands .command ()
419
+ @owner_only ()
420
+ @trigger_typing
406
421
async def update (self , ctx ):
407
422
'''Updates the bot, this only works with heroku users.'''
408
- allowed = [int (x ) for x in self .config .get ('OWNERS' , '' ).split (',' )]
409
-
410
- if ctx .author .id not in allowed :
411
- return
412
423
413
424
client = ModmailApiClient (self )
414
425
@@ -456,6 +467,7 @@ async def update(self, ctx):
456
467
await ctx .send (embed = em )
457
468
458
469
@commands .command ()
470
+ @trigger_typing
459
471
@commands .has_permissions (administrator = True )
460
472
async def setup (self , ctx , * , modrole : discord .Role = None ):
461
473
'''Sets up a server for modmail'''
@@ -505,6 +517,7 @@ async def _snippets(self, ctx):
505
517
await session .run ()
506
518
507
519
@commands .command ()
520
+ @trigger_typing
508
521
@commands .has_permissions (administrator = True )
509
522
async def disable (self , ctx , delete_archives : bool = False ):
510
523
'''Close all threads and disable modmail.'''
@@ -551,6 +564,7 @@ async def _close(self, ctx):
551
564
await ctx .channel .delete ()
552
565
553
566
@commands .command ()
567
+ @trigger_typing
554
568
@commands .has_permissions (manage_channels = True )
555
569
async def archive (self , ctx ):
556
570
'''
@@ -590,6 +604,7 @@ async def archive(self, ctx):
590
604
await ctx .message .delete ()
591
605
592
606
@commands .command ()
607
+ @trigger_typing
593
608
@commands .has_permissions (administrator = True )
594
609
async def ping (self , ctx ):
595
610
"""Pong! Returns your websocket latency."""
@@ -795,6 +810,7 @@ async def find_user_id_from_channel(self, channel):
795
810
return int (matches [0 ])
796
811
797
812
@commands .command ()
813
+ @trigger_typing
798
814
async def reply (self , ctx , * , msg = '' ):
799
815
'''Reply to users using this command.'''
800
816
ctx .message .content = msg
@@ -809,6 +825,7 @@ async def reply(self, ctx, *, msg=''):
809
825
await self .process_reply (ctx .message , user_id = user_id )
810
826
811
827
@commands .command ()
828
+ @trigger_typing
812
829
@commands .has_permissions (manage_channels = True )
813
830
async def contact (self , ctx , * , user : discord .Member = None ):
814
831
'''Create a thread with a specified member.'''
@@ -847,6 +864,7 @@ async def _status(self, ctx, *, message):
847
864
await ctx .send (embed = em )
848
865
849
866
@commands .command ()
867
+ @trigger_typing
850
868
@commands .has_permissions (manage_channels = True )
851
869
async def blocked (self , ctx ):
852
870
'''Returns a list of blocked users'''
@@ -880,6 +898,7 @@ async def blocked(self, ctx):
880
898
await ctx .send (embed = em )
881
899
882
900
@commands .command ()
901
+ @trigger_typing
883
902
@commands .has_permissions (manage_channels = True )
884
903
async def block (self , ctx , id = None ):
885
904
'''Block a user from using modmail.'''
@@ -915,6 +934,7 @@ async def block(self, ctx, id=None):
915
934
await ctx .send (embed = em )
916
935
917
936
@commands .command ()
937
+ @trigger_typing
918
938
@commands .has_permissions (manage_channels = True )
919
939
async def unblock (self , ctx , id = None ):
920
940
'''Unblocks a user from using modmail.'''
@@ -950,12 +970,9 @@ async def unblock(self, ctx, id=None):
950
970
await ctx .send (embed = em )
951
971
952
972
@commands .command (hidden = True , name = 'eval' )
973
+ @owner_only ()
953
974
async def _eval (self , ctx , * , body : str ):
954
975
"""Evaluates python code"""
955
- allowed = [int (x ) for x in self .config .get ('OWNERS' , '' ).split (',' )]
956
-
957
- if ctx .author .id not in allowed :
958
- return
959
976
960
977
env = {
961
978
'bot' : self ,
0 commit comments