understanding commited on
Commit
8c619c4
·
verified ·
1 Parent(s): 2bfb43c

Update bot/__main__.py

Browse files
Files changed (1) hide show
  1. bot/__main__.py +14 -6
bot/__main__.py CHANGED
@@ -18,8 +18,11 @@ def _validate_required_secrets() -> None:
18
  if not Telegram.API_ID: missing.append("API_ID")
19
  if not Telegram.API_HASH: missing.append("API_HASH")
20
  if not Telegram.OWNER_ID: missing.append("OWNER_ID")
 
 
21
  if not (Telegram.BOT_TOKEN or Telegram.SESSION_STRING):
22
- missing.append("BOT_TOKEN (preferred) or SESSION_STRING (legacy)")
 
23
  if not Workers.WORKER1_URL: missing.append("WORKER1_URL")
24
  if not Workers.WORKER2_URL: missing.append("WORKER2_URL")
25
  if not Workers.BOT_BACKEND_KEY: missing.append("BOT_BACKEND_KEY")
@@ -32,16 +35,21 @@ async def main():
32
  _validate_required_secrets()
33
 
34
  quart_app = create_app()
35
- uv_cfg = UvicornConfig(app=quart_app, host=Server.BIND_ADDRESS, port=Server.PORT, log_config=LOGGER_CONFIG_JSON)
 
 
 
 
 
36
  uv_server = UvicornServer(uv_cfg)
37
 
38
  bot, user = create_clients()
39
- user_app = user or (bot if not Telegram.BOT_TOKEN else None)
40
 
41
- setup_handlers(bot, user_app=user_app)
 
42
 
43
  await bot.start()
44
- if user and user is not bot:
45
  await user.start()
46
 
47
  asyncio.create_task(log_startup(bot))
@@ -54,7 +62,7 @@ async def main():
54
  await asyncio.sleep(3600)
55
  finally:
56
  try:
57
- if user and user is not bot:
58
  await user.stop()
59
  finally:
60
  await bot.stop()
 
18
  if not Telegram.API_ID: missing.append("API_ID")
19
  if not Telegram.API_HASH: missing.append("API_HASH")
20
  if not Telegram.OWNER_ID: missing.append("OWNER_ID")
21
+
22
+ # ✅ Need BOT_TOKEN or SESSION_STRING (bot session)
23
  if not (Telegram.BOT_TOKEN or Telegram.SESSION_STRING):
24
+ missing.append("BOT_TOKEN or SESSION_STRING (bot session)")
25
+
26
  if not Workers.WORKER1_URL: missing.append("WORKER1_URL")
27
  if not Workers.WORKER2_URL: missing.append("WORKER2_URL")
28
  if not Workers.BOT_BACKEND_KEY: missing.append("BOT_BACKEND_KEY")
 
35
  _validate_required_secrets()
36
 
37
  quart_app = create_app()
38
+ uv_cfg = UvicornConfig(
39
+ app=quart_app,
40
+ host=Server.BIND_ADDRESS,
41
+ port=Server.PORT,
42
+ log_config=LOGGER_CONFIG_JSON
43
+ )
44
  uv_server = UvicornServer(uv_cfg)
45
 
46
  bot, user = create_clients()
 
47
 
48
+ # ✅ IMPORTANT: only user session can fetch restricted channel messages
49
+ setup_handlers(bot, user_app=user)
50
 
51
  await bot.start()
52
+ if user:
53
  await user.start()
54
 
55
  asyncio.create_task(log_startup(bot))
 
62
  await asyncio.sleep(3600)
63
  finally:
64
  try:
65
+ if user:
66
  await user.stop()
67
  finally:
68
  await bot.stop()