2222SOFTWARE.
2323'''
2424
25- __version__ = '1.5.1 '
25+ __version__ = '1.5.0 '
2626
2727from contextlib import redirect_stdout
2828from urllib .parse import urlparse
2929from copy import deepcopy
30+ import functools
3031import asyncio
3132import textwrap
3233import traceback
4647from utils .paginator import PaginatorSession
4748from utils .api import Github , ModmailApiClient
4849
49-
5050class Modmail (commands .Bot ):
5151
5252 def __init__ (self ):
@@ -90,6 +90,19 @@ async def get_pre(bot, message):
9090 '''Returns the prefix.'''
9191 p = bot .config .get ('PREFIX' ) or 'm.'
9292 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
93106
94107 async def on_connect (self ):
95108 print ('---------------' )
@@ -138,14 +151,6 @@ async def on_message(self, message):
138151 message .content = f'{ prefix } reply { self .snippets [cmd ]} '
139152
140153 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 )
149154
150155 async def on_message_delete (self , message ):
151156 '''Support for deleting linked messages'''
@@ -272,6 +277,7 @@ def uptime(self):
272277 return fmt .format (d = days , h = hours , m = minutes , s = seconds )
273278
274279 @commands .command ()
280+ @trigger_typing
275281 async def help (self , ctx ):
276282 prefix = self .config .get ('PREFIX' , 'm.' )
277283
@@ -286,6 +292,7 @@ async def help(self, ctx):
286292 await session .run ()
287293
288294 @commands .command ()
295+ @trigger_typing
289296 async def about (self , ctx ):
290297 em = discord .Embed (color = discord .Color .green (), timestamp = datetime .datetime .utcnow ())
291298 em .set_author (name = 'Mod Mail - Information' , icon_url = self .user .avatar_url )
@@ -328,6 +335,8 @@ async def about(self, ctx):
328335 await ctx .send (embed = em )
329336
330337 @commands .group (invoke_without_subcommand = True )
338+ @owner_only ()
339+ @trigger_typing
331340 async def github (self , ctx ):
332341 if ctx .invoked_subcommand :
333342 return
@@ -355,6 +364,8 @@ async def github(self, ctx):
355364 await ctx .send (embed = em )
356365
357366 @github .command (name = 'login' )
367+ @owner_only ()
368+ @trigger_typing
358369 async def _login (self , ctx ):
359370 client = ModmailApiClient (self )
360371
@@ -380,6 +391,8 @@ async def _login(self, ctx):
380391 await ctx .author .send (embed = em )
381392
382393 @github .command (name = 'logout' )
394+ @owner_only ()
395+ @trigger_typing
383396 async def _logout (self , ctx ):
384397 client = ModmailApiClient (self )
385398 data = await client .logout ()
@@ -403,12 +416,10 @@ async def _logout(self, ctx):
403416 await ctx .send (embed = em )
404417
405418 @commands .command ()
419+ @owner_only ()
420+ @trigger_typing
406421 async def update (self , ctx ):
407422 '''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
412423
413424 client = ModmailApiClient (self )
414425
@@ -456,6 +467,7 @@ async def update(self, ctx):
456467 await ctx .send (embed = em )
457468
458469 @commands .command ()
470+ @trigger_typing
459471 @commands .has_permissions (administrator = True )
460472 async def setup (self , ctx , * , modrole : discord .Role = None ):
461473 '''Sets up a server for modmail'''
@@ -505,6 +517,7 @@ async def _snippets(self, ctx):
505517 await session .run ()
506518
507519 @commands .command ()
520+ @trigger_typing
508521 @commands .has_permissions (administrator = True )
509522 async def disable (self , ctx , delete_archives : bool = False ):
510523 '''Close all threads and disable modmail.'''
@@ -551,6 +564,7 @@ async def _close(self, ctx):
551564 await ctx .channel .delete ()
552565
553566 @commands .command ()
567+ @trigger_typing
554568 @commands .has_permissions (manage_channels = True )
555569 async def archive (self , ctx ):
556570 '''
@@ -590,6 +604,7 @@ async def archive(self, ctx):
590604 await ctx .message .delete ()
591605
592606 @commands .command ()
607+ @trigger_typing
593608 @commands .has_permissions (administrator = True )
594609 async def ping (self , ctx ):
595610 """Pong! Returns your websocket latency."""
@@ -795,6 +810,7 @@ async def find_user_id_from_channel(self, channel):
795810 return int (matches [0 ])
796811
797812 @commands .command ()
813+ @trigger_typing
798814 async def reply (self , ctx , * , msg = '' ):
799815 '''Reply to users using this command.'''
800816 ctx .message .content = msg
@@ -809,6 +825,7 @@ async def reply(self, ctx, *, msg=''):
809825 await self .process_reply (ctx .message , user_id = user_id )
810826
811827 @commands .command ()
828+ @trigger_typing
812829 @commands .has_permissions (manage_channels = True )
813830 async def contact (self , ctx , * , user : discord .Member = None ):
814831 '''Create a thread with a specified member.'''
@@ -847,6 +864,7 @@ async def _status(self, ctx, *, message):
847864 await ctx .send (embed = em )
848865
849866 @commands .command ()
867+ @trigger_typing
850868 @commands .has_permissions (manage_channels = True )
851869 async def blocked (self , ctx ):
852870 '''Returns a list of blocked users'''
@@ -880,6 +898,7 @@ async def blocked(self, ctx):
880898 await ctx .send (embed = em )
881899
882900 @commands .command ()
901+ @trigger_typing
883902 @commands .has_permissions (manage_channels = True )
884903 async def block (self , ctx , id = None ):
885904 '''Block a user from using modmail.'''
@@ -915,6 +934,7 @@ async def block(self, ctx, id=None):
915934 await ctx .send (embed = em )
916935
917936 @commands .command ()
937+ @trigger_typing
918938 @commands .has_permissions (manage_channels = True )
919939 async def unblock (self , ctx , id = None ):
920940 '''Unblocks a user from using modmail.'''
@@ -950,12 +970,9 @@ async def unblock(self, ctx, id=None):
950970 await ctx .send (embed = em )
951971
952972 @commands .command (hidden = True , name = 'eval' )
973+ @owner_only ()
953974 async def _eval (self , ctx , * , body : str ):
954975 """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
959976
960977 env = {
961978 'bot' : self ,
0 commit comments