File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,13 +10,16 @@ async def get_restricted_mode(user_id: int):
1010 return restricted_mode .scalar ()
1111
1212
13- async def get_bot_config ():
13+ async def get_bot_config (session ):
1414 """Get bot configuration. Creates default config if not exists."""
15- config = await Client .DB .get (BotConfig , 1 )
15+ query = select (BotConfig ).where (BotConfig .id == 1 )
16+ result = await session .execute (query )
17+ config = result .scalar_one_or_none ()
1618
1719 if not config :
1820 config = BotConfig (id = 1 )
19- await Client .DB .merge (config )
21+ session .add (config )
22+ await session .commit ()
2023
2124 return config
2225
Original file line number Diff line number Diff line change @@ -69,14 +69,18 @@ async def main():
6969 # Load bot configuration and initialize py1337x
7070
7171 logger .info ("Loading bot configuration" )
72- bot_config = await get_bot_config ()
73-
74- if bot_config .proxy_1337x :
75- logger .info (f"Initializing py1337x with proxy: { bot_config .proxy_1337x } " )
76- Client .py1337x = AsyncPy1337x (base_url = f"https://www.{ bot_config .proxy_1337x } " )
77- else :
78- logger .info ("Initializing py1337x with default proxy" )
79- Client .py1337x = AsyncPy1337x ()
72+ async with Client .DB .session () as session :
73+ bot_config = await get_bot_config (session )
74+ session .add (bot_config )
75+
76+ if bot_config .proxy_1337x :
77+ logger .info (f"Initializing py1337x with proxy: { bot_config .proxy_1337x } " )
78+ Client .py1337x = AsyncPy1337x (
79+ base_url = f"https://www.{ bot_config .proxy_1337x } "
80+ )
81+ else :
82+ logger .info ("Initializing py1337x with default proxy" )
83+ Client .py1337x = AsyncPy1337x ()
8084
8185 if "--no-init" not in argv :
8286 logger .info ("Initializing requirements for bot" )
You can’t perform that action at this time.
0 commit comments