@@ -48,10 +48,14 @@ async def download_initial_plugins(self):
48
48
try :
49
49
await self .download_plugin_repo (* parsed_plugin [:- 1 ])
50
50
except DownloadError as exc :
51
- msg = f'{ exc } ( { parsed_plugin [0 ]} /{ parsed_plugin [1 ]} - { exc } '
51
+ msg = f'{ parsed_plugin [0 ]} /{ parsed_plugin [1 ]} - { exc } '
52
52
print (Fore .RED + msg + Style .RESET_ALL )
53
-
54
- await self .load_plugin (* parsed_plugin )
53
+ else :
54
+ try :
55
+ await self .load_plugin (* parsed_plugin )
56
+ except DownloadError as exc :
57
+ msg = f'{ parsed_plugin [0 ]} /{ parsed_plugin [1 ]} - { exc } '
58
+ print (Fore .RED + msg + Style .RESET_ALL )
55
59
56
60
async def download_plugin_repo (self , username , repo ):
57
61
try :
@@ -72,6 +76,19 @@ async def download_plugin_repo(self, username, repo):
72
76
73
77
async def load_plugin (self , username , repo , plugin_name ):
74
78
ext = f'plugins.{ username } -{ repo } .{ plugin_name } .{ plugin_name } '
79
+ if 'requirements.txt' in os .listdir (f'plugins/{ username } -{ repo } /{ plugin_name } ' ):
80
+ # Install PIP requirements
81
+ try :
82
+ await self .bot .loop .run_in_executor (
83
+ None , self ._asubprocess_run ,
84
+ f'python3 -m pip install -U -r plugins/{ username } -{ repo } /{ plugin_name } /requirements.txt --user -q -q'
85
+ )
86
+ # -q -q (quiet) so there's no terminal output unless there's an error
87
+ except subprocess .CalledProcessError as exc :
88
+ error = exc .stderr .decode ('utf8' ).strip ()
89
+ if error :
90
+ raise DownloadError (f'Unable to download requirements: ```\n { error } \n ```' ) from exc
91
+
75
92
try :
76
93
self .bot .load_extension (ext )
77
94
except ModuleNotFoundError as exc :
@@ -91,6 +108,9 @@ async def plugin(self, ctx):
91
108
@plugin .command ()
92
109
async def add (self , ctx , * , plugin_name ):
93
110
"""Adds a plugin"""
111
+ if plugin_name in self .bot .config .plugins :
112
+ return await ctx .send ('Plugin already installed' )
113
+
94
114
message = await ctx .send ('Downloading plugin...' )
95
115
async with ctx .typing ():
96
116
if len (plugin_name .split ('/' )) >= 3 :
@@ -107,7 +127,7 @@ async def add(self, ctx, *, plugin_name):
107
127
try :
108
128
await self .load_plugin (* parsed_plugin )
109
129
except DownloadError as exc :
110
- return await ctx .send (f'Unable to start plugin: { exc } ' )
130
+ return await ctx .send (f'Unable to load plugin: ` { exc } ` ' )
111
131
112
132
# if it makes it here, it has passed all checks and should
113
133
# be entered into the config
@@ -157,6 +177,9 @@ def onerror(func, path, exc_info):
157
177
@plugin .command ()
158
178
async def update (self , ctx , * , plugin_name ):
159
179
"""Updates a certain plugin"""
180
+ if plugin_name not in self .bot .config .plugins :
181
+ return await ctx .send ('Plugin not installed' )
182
+
160
183
async with ctx .typing ():
161
184
username , repo , name = self .parse_plugin (plugin_name )
162
185
try :
@@ -167,18 +190,21 @@ async def update(self, ctx, *, plugin_name):
167
190
cmd
168
191
)
169
192
except subprocess .CalledProcessError as exc :
170
- error = exc .stdout .decode ('utf8' ).strip ()
171
- await ctx .send (f'Error when updating: { error } ' )
193
+ error = exc .stderr .decode ('utf8' ).strip ()
194
+ await ctx .send (f'Error while updating: { error } ' )
172
195
else :
173
196
output = cmd .stdout .decode ('utf8' ).strip ()
197
+ await ctx .send (f'```\n { output } \n ```' )
174
198
175
199
if output != 'Already up to date.' :
176
200
# repo was updated locally, now perform the cog reload
177
201
ext = f'plugins.{ username } -{ repo } .{ name } .{ name } '
178
202
importlib .reload (importlib .import_module (ext ))
179
- self .load_plugin (username , repo , name )
180
203
181
- await ctx .send (f'```\n { output } \n ```' )
204
+ try :
205
+ self .load_plugin (username , repo , name )
206
+ except DownloadError :
207
+ await ctx .send (f'Unable to start plugin: `{ exc } `' )
182
208
183
209
@plugin .command (name = 'list' )
184
210
async def list_ (self , ctx ):
0 commit comments