-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
52 lines (38 loc) · 1.45 KB
/
main.py
File metadata and controls
52 lines (38 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from app.container import init_container
from config import config
from logger import setup_logging, get_logger
def main():
setup_logging()
log = get_logger(__name__)
# Print startup information
log.info("TGAntiSpamBot starting up...")
log.info("Bot mode: %s", config.bot.mode)
log.info("Bot token configured: %s", 'Yes' if config.bot.token else 'No')
log.info("Main admin ID: %s", config.bot.main_admin_id)
log.info("AI enabled: %s", config.bot.ai_enabled)
if config.bot.ai_enabled:
log.info("AI model: %s", config.ai.model)
log.info("AI base URL: %s", config.ai.base_url)
init_container()
match config.bot.mode:
case "polling":
log.info("Starting in polling mode")
from app.bot.run_polling import run_polling
run_polling()
case "webhook":
log.info("Starting in webhook mode")
log.info("Webhook URL: %s", config.bot.webhook_url)
log.info("Webhook path: %s", config.bot.webhook_path)
log.info("Port: %s", config.bot.port)
import uvicorn
from app.bot.run_webhook import create_webhook_app
app = create_webhook_app()
uvicorn.run(
app,
host="0.0.0.0",
port=config.bot.port,
)
case _:
raise RuntimeError(f"Unknown bot mode: {config.bot.mode}")
if __name__ == "__main__":
main()