source: python-cinema-club-bot/main.py@ 6623428

Last change on this file since 6623428 was 6623428, checked in by Mikhail Kirillov <w96k@…>, on Oct 9, 2024 at 10:46:19 PM

Add movies commands

  • Property mode set to 100644
File size: 2.4 KB
Line 
1# This file is part of python-cinema-club-bot
2# contributed in 2024 by Mikhail Kirillov (~w96k) <w96k@runbox.com>
3
4# To the extent possible under law, the author(s) have dedicated all copyright
5# and related and neighboring rights to this software to the public domain
6# worldwide. This software is distributed without any warranty.
7
8# You should have received a copy of the CC0 Public Domain Dedication along
9# with this software. If not, see:
10# <http://creativecommons.org/publicdomain/zero/1.0/>
11
12from telegram import Update
13from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes, \
14 MessageHandler, filters
15from dotenv import load_dotenv
16import os
17import logging
18
19from strings import INVALID_COMMAND, UNDEFINED_ERROR
20from persistence import Persistence
21import commands
22
23
24load_dotenv()
25
26logging.basicConfig(
27 level=logging.INFO,
28 format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
29)
30
31
32async def unknown(update: Update, context: ContextTypes.DEFAULT_TYPE):
33 await context.bot.send_message(
34 chat_id=update.effective_chat.id,
35 text=INVALID_COMMAND
36 )
37
38async def error_handler(update: object, context: ContextTypes.DEFAULT_TYPE) -> None:
39 logging.error("Exception:", exc_info=context.error)
40
41 error_message = context.error.message \
42 if hasattr(context.error, "message") else UNDEFINED_ERROR
43
44 await context.bot.send_message(
45 chat_id=update.effective_chat.id,
46 text=error_message
47 )
48
49if __name__ == "__main__":
50 app = ApplicationBuilder().token(
51 os.environ.get("TELEGRAM_TOKEN")
52 ).persistence(Persistence).build()
53
54 # Meta commands
55 app.add_handler(CommandHandler("about", commands.about))
56
57 # Movie commands
58 app.add_handler(CommandHandler("movie", commands.movie))
59 app.add_handler(CommandHandler("movies", commands.movies))
60 app.add_handler(CommandHandler("movies_remove", commands.remove_movies))
61
62 # Users commands
63 app.add_handler(CommandHandler("set", commands.set_users))
64 app.add_handler(CommandHandler("add", commands.add_users))
65 app.add_handler(CommandHandler("list", commands.list_users))
66 app.add_handler(CommandHandler("remove", commands.remove_users))
67 app.add_handler(CommandHandler("chooser", commands.chooser_user))
68 app.add_handler(CommandHandler("next", commands.who_is_next))
69
70 app.add_handler(MessageHandler(filters.COMMAND, unknown))
71 app.add_error_handler(error_handler)
72
73
74 app.run_polling()
75
Note: See TracBrowser for help on using the repository browser.