[V3 RPC] Initial RPC library switch (#1634)

* Initial RPC library switch

* Use weak refs to the methods so cog unload works

* Add docs

* Black fixes

* Add jsonrpcserver to Pipfile.lock
This commit is contained in:
Will
2018-05-22 20:29:26 -04:00
committed by palmtree5
parent abfee70eb3
commit 73a427f6aa
8 changed files with 179 additions and 99 deletions

View File

@@ -21,22 +21,9 @@ from .cog_manager import CogManager
from . import Config, i18n, commands, rpc
from .help_formatter import Help, help as help_
from .sentry import SentryManager
from .utils import TYPE_CHECKING
if TYPE_CHECKING:
from aiohttp_json_rpc import JsonRpc
# noinspection PyUnresolvedReferences
class RpcMethodMixin:
async def rpc__cogs(self, request):
return list(self.cogs.keys())
async def rpc__extensions(self, request):
return list(self.extensions.keys())
class RedBase(BotBase, RpcMethodMixin):
class RedBase(BotBase):
"""Mixin for the main bot class.
This exists because `Red` inherits from `discord.AutoShardedClient`, which
@@ -104,10 +91,11 @@ class RedBase(BotBase, RpcMethodMixin):
self.cog_mgr = CogManager(paths=(str(self.main_dir / "cogs"),))
self.register_rpc_methods()
super().__init__(formatter=Help(), **kwargs)
if self.rpc_enabled:
self.rpc = rpc.RPC(self)
self.remove_command("help")
self.add_command(help_)
@@ -275,10 +263,6 @@ class RedBase(BotBase, RpcMethodMixin):
if pkg_name.startswith("redbot.cogs"):
del sys.modules["redbot.cogs"].__dict__[name]
def register_rpc_methods(self):
rpc.add_method("bot", self.rpc__cogs)
rpc.add_method("bot", self.rpc__extensions)
class Red(RedBase, discord.AutoShardedClient):
"""