journal-bot/bot/main.py
2023-05-04 23:19:29 +02:00

48 lines
1.3 KiB
Python

import os
from telegram.ext import Application
import logging
import models
from commands import journal, status
from commands.list import list
from commands import turtle
from cronjob import chat_photo
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
level=logging.INFO
)
import asyncio
logger = logging.getLogger(__name__)
def main() -> None:
"""Run the bot."""
token = os.getenv("BOT_TOKEN")
db_path = os.getenv("DB_PATH")
models.set_db(db_path)
application = Application.builder().token(token).build()
application.add_handler(journal.JournalHandler("journal", models).handler)
application.add_handler(list.ListHandler("list", models).handler)
application.add_handler(status.StatusHandler("status", models).handler)
application.add_handler(turtle.TurtleHandler().handler)
# application.add_handler(CommandHandler("help", help_command))
# on non command i.e message - echo the message on Telegram
# application.add_handler(InlineQueryHandler(inline_query))
# on every start set a new chat photo
# loop = asyncio.get_event_loop()
asyncio.ensure_future(chat_photo.set_random(application.bot))
# Run the bot until the user presses Ctrl-C
application.run_polling()
if __name__ == "__main__":
main()