1
- import asyncio
2
1
import importlib
3
2
import os
4
3
import shutil
@@ -20,7 +19,8 @@ class Plugins:
20
19
21
20
These addons could have a range of features from moderation to simply
22
21
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
24
24
"""
25
25
def __init__ (self , bot : Bot ):
26
26
self .bot = bot
@@ -76,18 +76,23 @@ async def download_plugin_repo(self, username, repo):
76
76
77
77
async def load_plugin (self , username , repo , plugin_name ):
78
78
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 ):
80
81
# Install PIP requirements
81
82
try :
82
83
await self .bot .loop .run_in_executor (
83
84
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'
85
87
)
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
87
90
except subprocess .CalledProcessError as exc :
88
91
error = exc .stderr .decode ('utf8' ).strip ()
89
92
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
91
96
92
97
try :
93
98
self .bot .load_extension (ext )
@@ -161,11 +166,12 @@ async def remove(self, ctx, *, plugin_name):
161
166
# if there are no more of such repos, delete the folder
162
167
def onerror (func , path , exc_info ):
163
168
if not os .access (path , os .W_OK ):
164
- # Is the error an access error ?
169
+ # Is the error an access error?
165
170
os .chmod (path , stat .S_IWUSR )
166
171
func (path )
167
172
168
- shutil .rmtree (f'plugins/{ username } -{ repo } ' , onerror = onerror )
173
+ shutil .rmtree (f'plugins/{ username } -{ repo } ' ,
174
+ onerror = onerror )
169
175
except Exception as exc :
170
176
print (exc )
171
177
self .bot .config .plugins .append (plugin_name )
@@ -205,15 +211,16 @@ async def update(self, ctx, *, plugin_name):
205
211
importlib .reload (importlib .import_module (ext ))
206
212
207
213
try :
208
- self .load_plugin (username , repo , name )
209
- except DownloadError :
214
+ await self .load_plugin (username , repo , name )
215
+ except DownloadError as exc :
210
216
await ctx .send (f'Unable to start plugin: `{ exc } `' )
211
217
212
218
@plugin .command (name = 'list' )
213
219
async def list_ (self , ctx ):
214
220
"""Shows a list of currently enabled plugins"""
215
221
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 )
217
224
else :
218
225
await ctx .send ('No plugins installed' )
219
226
0 commit comments