1- import asyncio
21import importlib
32import os
43import shutil
@@ -20,7 +19,8 @@ class Plugins:
2019
2120 These addons could have a range of features from moderation to simply
2221 making your life as a moderator easier!
23- Learn how to create a plugin yourself here: https://github.com/kyb3r/modmail/wiki/Plugins
22+ Learn how to create a plugin yourself here:
23+ https://github.com/kyb3r/modmail/wiki/Plugins
2424 """
2525 def __init__ (self , bot : Bot ):
2626 self .bot = bot
@@ -76,18 +76,23 @@ async def download_plugin_repo(self, username, repo):
7676
7777 async def load_plugin (self , username , repo , plugin_name ):
7878 ext = f'plugins.{ username } -{ repo } .{ plugin_name } .{ plugin_name } '
79- if 'requirements.txt' in os .listdir (f'plugins/{ username } -{ repo } /{ plugin_name } ' ):
79+ dirname = f'plugins/{ username } -{ repo } /{ plugin_name } '
80+ if 'requirements.txt' in os .listdir (dirname ):
8081 # Install PIP requirements
8182 try :
8283 await self .bot .loop .run_in_executor (
8384 None , self ._asubprocess_run ,
84- f'python3 -m pip install -U -r plugins/{ username } -{ repo } /{ plugin_name } /requirements.txt --user -q -q'
85+ f'python3 -m pip install -U -r { dirname } /'
86+ 'requirements.txt --user -q -q'
8587 )
86- # -q -q (quiet) so there's no terminal output unless there's an error
88+ # -q -q (quiet)
89+ # so there's no terminal output unless there's an error
8790 except subprocess .CalledProcessError as exc :
8891 error = exc .stderr .decode ('utf8' ).strip ()
8992 if error :
90- raise DownloadError (f'Unable to download requirements: ```\n { error } \n ```' ) from exc
93+ raise DownloadError (
94+ f'Unable to download requirements: ```\n { error } \n ```'
95+ ) from exc
9196
9297 try :
9398 self .bot .load_extension (ext )
@@ -161,11 +166,12 @@ async def remove(self, ctx, *, plugin_name):
161166 # if there are no more of such repos, delete the folder
162167 def onerror (func , path , exc_info ):
163168 if not os .access (path , os .W_OK ):
164- # Is the error an access error ?
169+ # Is the error an access error?
165170 os .chmod (path , stat .S_IWUSR )
166171 func (path )
167172
168- shutil .rmtree (f'plugins/{ username } -{ repo } ' , onerror = onerror )
173+ shutil .rmtree (f'plugins/{ username } -{ repo } ' ,
174+ onerror = onerror )
169175 except Exception as exc :
170176 print (exc )
171177 self .bot .config .plugins .append (plugin_name )
@@ -205,15 +211,16 @@ async def update(self, ctx, *, plugin_name):
205211 importlib .reload (importlib .import_module (ext ))
206212
207213 try :
208- self .load_plugin (username , repo , name )
209- except DownloadError :
214+ await self .load_plugin (username , repo , name )
215+ except DownloadError as exc :
210216 await ctx .send (f'Unable to start plugin: `{ exc } `' )
211217
212218 @plugin .command (name = 'list' )
213219 async def list_ (self , ctx ):
214220 """Shows a list of currently enabled plugins"""
215221 if self .bot .config .plugins :
216- await ctx .send ('```\n ' + '\n ' .join (self .bot .config .plugins ) + '\n ```' )
222+ msg = '```\n ' + '\n ' .join (self .bot .config .plugins ) + '\n ```'
223+ await ctx .send (msg )
217224 else :
218225 await ctx .send ('No plugins installed' )
219226
0 commit comments