[V3 Cog/Data Manager] Bundled Cog Data (#1063)

* Refactor find_spec out of core_commands

* Fix version error when not installed

* initial

* Fix find_cogs call

* Enable copying

* Add helper method for cog creators

* Add warning

* My dpy skillz need work
This commit is contained in:
Will
2017-10-27 20:06:47 -04:00
committed by GitHub
parent 77e29ff43b
commit 09b3642559
5 changed files with 227 additions and 35 deletions

View File

@@ -14,9 +14,7 @@ from discord.ext import commands
from redbot.core import checks
from redbot.core import i18n
import redbot.cogs # Don't remove this line or core cogs won't load
__all__ = ["find_spec", "Core"]
__all__ = ["Core"]
log = logging.getLogger("red")
@@ -26,20 +24,6 @@ OWNER_DISCLAIMER = ("⚠ **Only** the person who is hosting Red should be "
"system.** ⚠")
async def find_spec(bot, cog_name: str):
try:
spec = await bot.cog_mgr.find_cog(cog_name)
except RuntimeError:
real_name = ".{}".format(cog_name)
try:
mod = importlib.import_module(real_name, package='redbot.cogs')
except ImportError:
spec = None
else:
spec = mod.__spec__
return spec
_ = i18n.CogI18n("Core", __file__)
@@ -50,8 +34,9 @@ class Core:
@checks.is_owner()
async def load(self, ctx, *, cog_name: str):
"""Loads a package"""
spec = await find_spec(ctx.bot, cog_name)
if spec is None:
try:
spec = await ctx.bot.cog_mgr.find_cog(cog_name)
except RuntimeError:
await ctx.send(_("No module by that name was found in any"
" cog path."))
return
@@ -83,7 +68,7 @@ class Core:
"""Reloads a package"""
ctx.bot.unload_extension(cog_name)
spec = await find_spec(ctx.bot, cog_name)
spec = await ctx.bot.cog_mgr.find_cog(cog_name)
if spec is None:
await ctx.send(_("No module by that name was found in any"
" cog path."))