-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
41 lines (33 loc) · 1.34 KB
/
bot.py
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
from telegram.ext import ApplicationBuilder, CommandHandler, CallbackQueryHandler
from http.server import BaseHTTPRequestHandler, HTTPServer
import threading
import db
import handlers
import config
class HealthHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.end_headers()
def run_health_server():
"""Run health check server"""
server = HTTPServer(('0.0.0.0', 8080), HealthHandler)
server.serve_forever()
def main():
"""Main application setup"""
# Initialize database
db.init_db()
# Start health server
threading.Thread(target=run_health_server, daemon=True).start()
# Create bot
application = ApplicationBuilder().token(config.TOKEN).build()
# Register handlers
application.add_handler(CommandHandler('start', handlers.start))
application.add_handler(CommandHandler('add_reminder', handlers.add_reminder))
application.add_handler(CommandHandler('show_reminders', handlers.show_reminders))
application.add_handler(CommandHandler('remove_reminder', handlers.remove_reminder))
application.add_handler(CallbackQueryHandler(handlers.mark_done, pattern='^mark_'))
application.add_handler(CallbackQueryHandler(handlers.show_history, pattern='^history_'))
# Run bot
application.run_polling()
if __name__ == '__main__':
main()