Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RPC] Set custom port with flags #2429

Merged
merged 4 commits into from Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions redbot/core/bot.py
Expand Up @@ -40,6 +40,7 @@ def __init__(self, *args, cli_flags=None, bot_dir: Path = Path.cwd(), **kwargs):
self.db = Config.get_core_conf(force_registration=True)
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.db.register_global(
token=None,
Expand Down
6 changes: 6 additions & 0 deletions redbot/core/cli.py
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion redbot/core/events.py
Expand Up @@ -79,7 +79,7 @@ async def on_ready():
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()]))
Expand Down
6 changes: 3 additions & 3 deletions redbot/core/rpc.py
Expand Up @@ -69,15 +69,15 @@ def __init__(self):
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):
"""
Expand Down