mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-22 02:37:57 -05:00
[V3 RPC] Swap back to initial RPC library and hook into core commands (#1780)
* Switch RPC libs for websockets support * Implement RPC handling for core * Black reformat * Fix docs for build on travis * Modify RPC to use a Cog base class * Refactor rpc server reference as global * Handle cogbase unload method * Add an init call to handle mutable base attributes * Move RPC server reference back to the bot object * Remove unused import * Add tests for rpc method add/removal * Add tests for rpc method add/removal and cog base unloading * Add one more test * Black reformat * Add RPC mixin...fix MRO * Correct internal rpc method names * Add rpc test html file for debugging/example purposes * Add documentation * Add get_method_info * Update docs with an example RPC call specifying parameter formatting * Make rpc methods UPPER * Black reformat * Fix doc example * Modify this to match new method naming convention * Add more tests
This commit is contained in:
@@ -18,12 +18,13 @@ from discord.voice_client import VoiceClient
|
||||
VoiceClient.warn_nacl = False
|
||||
|
||||
from .cog_manager import CogManager
|
||||
from . import Config, i18n, commands, rpc
|
||||
from . import Config, i18n, commands
|
||||
from .rpc import RPCMixin
|
||||
from .help_formatter import Help, help as help_
|
||||
from .sentry import SentryManager
|
||||
|
||||
|
||||
class RedBase(BotBase):
|
||||
class RedBase(BotBase, RPCMixin):
|
||||
"""Mixin for the main bot class.
|
||||
|
||||
This exists because `Red` inherits from `discord.AutoShardedClient`, which
|
||||
@@ -33,7 +34,7 @@ class RedBase(BotBase):
|
||||
Selfbots should inherit from this mixin along with `discord.Client`.
|
||||
"""
|
||||
|
||||
def __init__(self, cli_flags, bot_dir: Path = Path.cwd(), **kwargs):
|
||||
def __init__(self, *args, cli_flags=None, bot_dir: Path = Path.cwd(), **kwargs):
|
||||
self._shutdown_mode = ExitCodes.CRITICAL
|
||||
self.db = Config.get_core_conf(force_registration=True)
|
||||
self._co_owners = cli_flags.co_owner
|
||||
@@ -107,10 +108,7 @@ class RedBase(BotBase):
|
||||
|
||||
self.cog_mgr = CogManager(paths=(str(self.main_dir / "cogs"),))
|
||||
|
||||
super().__init__(formatter=Help(), **kwargs)
|
||||
|
||||
if self.rpc_enabled:
|
||||
self.rpc = rpc.RPC(self)
|
||||
super().__init__(*args, formatter=Help(), **kwargs)
|
||||
|
||||
self.remove_command("help")
|
||||
|
||||
@@ -235,12 +233,24 @@ class RedBase(BotBase):
|
||||
lib_name = lib.__name__ # Thank you
|
||||
|
||||
# find all references to the module
|
||||
cog_names = []
|
||||
|
||||
# remove the cogs registered from the module
|
||||
for cogname, cog in self.cogs.copy().items():
|
||||
if cog.__module__.startswith(lib_name):
|
||||
self.remove_cog(cogname)
|
||||
|
||||
cog_names.append(cogname)
|
||||
|
||||
# remove all rpc handlers
|
||||
for cogname in cog_names:
|
||||
if cogname.upper() in self.rpc_handlers:
|
||||
methods = self.rpc_handlers[cogname]
|
||||
for meth in methods:
|
||||
self.unregister_rpc_handler(meth)
|
||||
|
||||
del self.rpc_handlers[cogname]
|
||||
|
||||
# first remove all the commands from the module
|
||||
for cmd in self.all_commands.copy().values():
|
||||
if cmd.module.startswith(lib_name):
|
||||
|
||||
Reference in New Issue
Block a user