[RPC] Set custom port with flags (#2429)

* [RPC] Set custom port with flags

* Add changelog entry
This commit is contained in:
El Laggron 2019-10-22 04:46:56 +02:00 committed by Michael H
parent 3b0fa0c05d
commit ee293876d9
5 changed files with 12 additions and 4 deletions

View File

@ -0,0 +1 @@
Add the option to modify the RPC port with the ``--rpc-port`` flag.

View File

@ -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,

View File

@ -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",

View File

@ -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()]))

View File

@ -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):
"""