Skip to content

Commit 5c464a8

Browse files
committed
Merge branch 'feat/rest' into dev
# Conflicts: # src/config/models.py # src/start.py
2 parents 97b10d8 + f8f5ac0 commit 5c464a8

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/config/models.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,23 @@ def __bool__(self) -> bool:
4040
return self.enabled
4141

4242

43+
class RestConfig(BaseModel):
44+
enabled: bool = False
45+
health: bool = False
46+
host: str = "0.0.0.0" # noqa: S104
47+
port: int = 6000
48+
49+
def __bool__(self) -> bool:
50+
return self.enabled
51+
52+
4353
class BotConfig(BaseModel):
4454
token: str
4555
public_key: str | None = None
4656
prefix: PrefixConfig | str = PrefixConfig(prefix="!", enabled=False)
4757
slash: SlashConfig = SlashConfig(enabled=False)
4858
cache: CacheConfig = CacheConfig()
49-
rest: bool = False
59+
rest: RestConfig = RestConfig()
5060

5161

5262
class LoggingConfig(BaseModel):

src/start.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from src import custom, i18n
1818
from src.config import config
19-
from src.config.models import BotConfig, Extension
19+
from src.config.models import BotConfig, Extension, RestConfig
2020
from src.i18n.classes import ExtensionTranslation
2121
from src.log import logger, patch
2222
from src.utils import setup_func, unzip_extensions, validate_module
@@ -28,12 +28,20 @@
2828
FunctionlistType = list[tuple[Callable[..., Any], Extension]]
2929

3030

31-
async def start_bot(bot: custom.Bot, token: str, public_key: str | None = None) -> None:
31+
async def start_bot(bot: custom.Bot, token: str, rest_config: RestConfig, public_key: str | None = None) -> None:
3232
try:
3333
if isinstance(bot, custom.CustomRestBot):
3434
if not public_key:
3535
raise TypeError("CustomRestBot requires a public key to start.") # noqa: TRY301
36-
await bot.start(token=token, public_key=public_key)
36+
await bot.start(
37+
token=token,
38+
public_key=public_key,
39+
health=rest_config.health,
40+
uvicorn_options={
41+
"host": rest_config.host,
42+
"port": rest_config.port,
43+
},
44+
)
3745
else:
3846
await bot.start(token)
3947
except LoginFailure as e:
@@ -165,7 +173,7 @@ async def setup_and_start_bot(
165173
bot.prefixed_commands = {}
166174
if not config.slash:
167175
bot._pending_application_commands = [] # pyright: ignore[reportPrivateUsage]
168-
await start_bot(bot, config.token, config.public_key)
176+
await start_bot(bot, config.token, config.rest, config.public_key)
169177

170178

171179
async def setup_and_start_backend(

0 commit comments

Comments
 (0)