mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[RPC] Set custom port with flags (#2429)
* [RPC] Set custom port with flags * Add changelog entry
This commit is contained in:
parent
3b0fa0c05d
commit
ee293876d9
1
changelog.d/2429.enhance.rst
Normal file
1
changelog.d/2429.enhance.rst
Normal file
@ -0,0 +1 @@
|
||||
Add the option to modify the RPC port with the ``--rpc-port`` flag.
|
||||
@ -45,6 +45,7 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin): # pylint: d
|
||||
self._config = Config.get_core_conf(force_registration=False)
|
||||
self._co_owners = cli_flags.co_owner
|
||||
self.rpc_enabled = cli_flags.rpc
|
||||
self.rpc_port = cli_flags.rpc_port
|
||||
self._last_exception = None
|
||||
self._config.register_global(
|
||||
token=None,
|
||||
|
||||
@ -117,6 +117,12 @@ def parse_cli_flags(args):
|
||||
action="store_true",
|
||||
help="Enables the built-in RPC server. Please read the docs prior to enabling this!",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--rpc-port",
|
||||
type=int,
|
||||
default=6133,
|
||||
help="The port of the built-in RPC server to use. Default to 6133.",
|
||||
)
|
||||
parser.add_argument("--token", type=str, help="Run Red with the given token.")
|
||||
parser.add_argument(
|
||||
"--no-instance",
|
||||
|
||||
@ -79,7 +79,7 @@ def init_events(bot, cli_flags):
|
||||
print("Loaded packages: " + ", ".join(packages))
|
||||
|
||||
if bot.rpc_enabled:
|
||||
await bot.rpc.initialize()
|
||||
await bot.rpc.initialize(bot.rpc_port)
|
||||
|
||||
guilds = len(bot.guilds)
|
||||
users = len(set([m for m in bot.get_all_members()]))
|
||||
|
||||
@ -69,15 +69,15 @@ class RPC:
|
||||
self._runner = web.AppRunner(self.app)
|
||||
self._site: Optional[web.TCPSite] = None
|
||||
|
||||
async def initialize(self):
|
||||
async def initialize(self, port: int):
|
||||
"""
|
||||
Finalizes the initialization of the RPC server and allows it to begin
|
||||
accepting queries.
|
||||
"""
|
||||
await self._runner.setup()
|
||||
self._site = web.TCPSite(self._runner, host="127.0.0.1", port=6133)
|
||||
self._site = web.TCPSite(self._runner, host="127.0.0.1", port=port)
|
||||
await self._site.start()
|
||||
log.debug("Created RPC server listener.")
|
||||
log.debug("Created RPC server listener on port %s", port)
|
||||
|
||||
async def close(self):
|
||||
"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user