Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (49 loc) · 1.79 KB
/
Copy pathmain.py
File metadata and controls
62 lines (49 loc) · 1.79 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
53
54
55
56
57
58
59
60
61
62
import logging
import os
import sys
# Make all output UTF-8 safe so emojis (used throughout the bot) never crash the
# process on a Windows cp1252 console.
for _stream in (sys.stdout, sys.stderr):
try:
_stream.reconfigure(encoding="utf-8", errors="replace")
except Exception:
pass
from telegram.ext import ApplicationBuilder
from bot.handlers import register_handlers
from scheduler.jobs import start_scheduler
from config import config
os.makedirs("./data/logs", exist_ok=True)
os.makedirs("./data/chroma", exist_ok=True)
os.makedirs("./data/context", exist_ok=True)
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
handlers=[
logging.StreamHandler(),
logging.FileHandler("./data/logs/founder_os.log", encoding="utf-8"),
]
)
logger = logging.getLogger(__name__)
def main():
logger.info(f"Starting Founder OS for {config.my_name} @ {config.company_name}")
app = ApplicationBuilder().token(config.telegram_bot_token).build()
register_handlers(app)
async def _post_init(application):
from agent.cognition.loop import start_cognitive_loop
start_cognitive_loop(application)
async def _post_shutdown(application):
from agent.cognition.loop import stop_cognitive_loop
stop_cognitive_loop()
app.post_init = _post_init
app.post_shutdown = _post_shutdown
start_scheduler(app)
if config.dashboard_enabled:
try:
from api.server import start_in_thread
start_in_thread()
except Exception as e:
logger.warning(f"Dashboard API failed to start: {e}")
logger.info("Bot is running. Send a message on Telegram to start.")
app.run_polling(drop_pending_updates=True)
if __name__ == "__main__":
main()