[V3 RPC] Add basic RPC functionality (#1017)

* Add basic RPC functionality

* Add load/unload/reload rpc commands

* Reorganize without rpc_ready event

* Remove rpc ready event

* Removed bot reference from rpc module

* Close RPC server cleanly

* refactor bot

* Refactor a bit and make RPC server initialization based on a cli flag

* Fix version resolver

* standardize version getters

* Pick a new port number
This commit is contained in:
Will
2017-10-27 20:55:41 -04:00
committed by GitHub
parent 8d8e1c61d8
commit f459a21bef
9 changed files with 175 additions and 8 deletions

View File

@@ -13,6 +13,12 @@ from discord.ext import commands
from redbot.core import checks
from redbot.core import i18n
from redbot.core import rpc
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from redbot.core.bot import Red
__all__ = ["Core"]
@@ -29,6 +35,12 @@ _ = i18n.CogI18n("Core", __file__)
class Core:
"""Commands related to core functions"""
def __init__(self, bot):
self.bot = bot # type: Red
rpc.add_method('core', self.rpc_load)
rpc.add_method('core', self.rpc_unload)
rpc.add_method('core', self.rpc_reload)
@commands.command()
@checks.is_owner()
@@ -410,3 +422,25 @@ class Core:
"to %s") % destination)
else:
await ctx.send(_("Message delivered to %s") % destination)
# RPC handlers
async def rpc_load(self, request):
cog_name = request.params[0]
spec = await self.bot.cog_mgr.find_cog(cog_name)
if spec is None:
raise LookupError("No such cog found.")
self.cleanup_and_refresh_modules(spec.name)
self.bot.load_extension(spec)
async def rpc_unload(self, request):
cog_name = request.params[0]
self.bot.unload_extension(cog_name)
async def rpc_reload(self, request):
await self.rpc_unload(request)
await self.rpc_load(request)