Skip to content

Commit 4967f10

Browse files
committed
Merge branch 'plugin' of https://github.com/kyb3r/modmail into plugin
2 parents 8bfa1fd + be93056 commit 4967f10

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ ENV/
102102
*.json
103103
!app.json
104104

105-
#Pycharm
105+
# Pycharm
106106
.idea/
107107

108-
#MacOS
108+
# MacOS
109109
.DS_Store
110110

111-
# custom
111+
# VS Code
112112
.vscode/
113113

114114
# Modmail

bot.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,18 @@
3232
from types import SimpleNamespace
3333

3434
import discord
35-
from aiohttp import ClientSession
36-
from colorama import init, Fore, Style
3735
from discord.enums import ActivityType
3836
from discord.ext import commands
3937
from discord.ext.commands.view import StringView
38+
39+
from aiohttp import ClientSession
40+
from colorama import init, Fore, Style
4041
from emoji import UNICODE_EMOJI
4142
from motor.motor_asyncio import AsyncIOMotorClient
4243

4344
from core.changelog import Changelog
44-
from core.clients import ModmailApiClient, SelfHostedClient, PluginDatabaseClient
45+
from core.clients import ModmailApiClient, SelfHostedClient
46+
from core.clients import PluginDatabaseClient
4547
from core.config import ConfigManager
4648
from core.models import Bot
4749
from core.thread import ThreadManager

cogs/plugins.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import importlib
32
import os
43
import 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

core/clients.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,6 @@ class PluginDatabaseClient:
539539
def __init__(self, bot: Bot):
540540
self.bot = bot
541541

542-
def get_partition(self, cog_cls):
543-
cls_name = cog_cls.__class__.__name__
542+
def get_partition(self, cog):
543+
cls_name = cog.__class__.__name__
544544
return self.bot.db.plugins[cls_name]

0 commit comments

Comments
 (0)