Skip to content

Commit 5e506ee

Browse files
committed
add new config keys for the webserver related pieces
1 parent 4a4424b commit 5e506ee

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

config.template.toml

+4
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ url = 'http://snekbox:8060/eval' # default url
3131

3232
[GITHUB] # optional
3333
bot_secret = ""
34+
35+
[WEBSERVER] # optional
36+
host = "127.0.0.1"
37+
port = 2332

launcher.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,16 @@ async def main() -> None:
6363
extension.name,
6464
)
6565

66-
app: Application = Application(bot=bot)
67-
config: uvicorn.Config = uvicorn.Config(app, port=2332)
68-
server: uvicorn.Server = uvicorn.Server(config)
69-
70-
tasks.add(asyncio.create_task(bot.start(core.CONFIG["TOKENS"]["bot"])))
71-
await server.serve()
66+
server_config = core.CONFIG.get("WEBSERVER")
67+
if server_config:
68+
app: Application = Application(bot=bot)
69+
config: uvicorn.Config = uvicorn.Config(app, host=server_config["host"], port=server_config["port"])
70+
server: uvicorn.Server = uvicorn.Server(config)
71+
72+
tasks.add(asyncio.create_task(bot.start(core.CONFIG["TOKENS"]["bot"])))
73+
await server.serve()
74+
else:
75+
await bot.start(core.CONFIG["TOKENS"]["bot"])
7276

7377

7478
try:

types_/config.py

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class Suggestions(TypedDict):
3434
webhook_url: str
3535

3636

37+
class Webserver(TypedDict):
38+
host: str
39+
port: int
40+
41+
3742
class Config(TypedDict):
3843
prefix: str
3944
owner_ids: NotRequired[list[int]]
@@ -43,3 +48,4 @@ class Config(TypedDict):
4348
SNEKBOX: NotRequired[Snekbox]
4449
BADBIN: BadBin
4550
SUGGESTIONS: NotRequired[Suggestions]
51+
WEBSERVER: NotRequired[Webserver]

0 commit comments

Comments
 (0)