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

Last change on this file was 1f94544, checked in by Mikhail Kirillov <w96k@…>, on Oct 10, 2024 at 6:53:36 AM

Remove /movies_remove command.

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[ca5a97e]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:
[71efb80]10# <http://creativecommons.org/publicdomain/zero/1.0/>
[ca5a97e]11
[cc34991]12from telegram import Update
[5179f7b]13from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes, \
14 MessageHandler, filters
[ca5a97e]15from dotenv import load_dotenv
16import os
[50e04dd]17import logging
[0d67456]18
[6623428]19from strings import INVALID_COMMAND, UNDEFINED_ERROR
[0d67456]20from persistence import Persistence
[cc34991]21import commands
[0d67456]22
[ca5a97e]23
24load_dotenv()
25
[50e04dd]26logging.basicConfig(
27 level=logging.INFO,
28 format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
29)
30
[71efb80]31
[5179f7b]32async def unknown(update: Update, context: ContextTypes.DEFAULT_TYPE):
[0d67456]33 await context.bot.send_message(
34 chat_id=update.effective_chat.id,
35 text=INVALID_COMMAND
36 )
37
[9be02d9]38
[0d48ea2]39async def error_handler(update: object, context: ContextTypes.DEFAULT_TYPE) -> None:
40 logging.error("Exception:", exc_info=context.error)
41
[6623428]42 error_message = context.error.message \
43 if hasattr(context.error, "message") else UNDEFINED_ERROR
44
[0d48ea2]45 await context.bot.send_message(
46 chat_id=update.effective_chat.id,
[6623428]47 text=error_message
[0d48ea2]48 )
[0d67456]49
[cc34991]50if __name__ == "__main__":
[0d67456]51 app = ApplicationBuilder().token(
52 os.environ.get("TELEGRAM_TOKEN")
53 ).persistence(Persistence).build()
[ca5a97e]54
[0d48ea2]55 # Meta commands
[cc34991]56 app.add_handler(CommandHandler("about", commands.about))
[0d48ea2]57
[9be02d9]58 # Event commands
59 app.add_handler(CommandHandler("event", commands.create_event))
60 app.add_handler(CommandHandler("events", commands.list_events))
[23bddf3]61 app.add_handler(CommandHandler("announce", commands.create_announcement))
[9be02d9]62
[0d48ea2]63 # Movie commands
[6623428]64 app.add_handler(CommandHandler("movie", commands.movie))
65 app.add_handler(CommandHandler("movies", commands.movies))
[9be02d9]66
[6623428]67 # Users commands
[0d48ea2]68 app.add_handler(CommandHandler("set", commands.set_users))
[cc34991]69 app.add_handler(CommandHandler("add", commands.add_users))
70 app.add_handler(CommandHandler("list", commands.list_users))
[9be02d9]71 app.add_handler(CommandHandler("users", commands.list_users))
[23bddf3]72 app.add_handler(CommandHandler("queue", commands.list_users))
[cc34991]73 app.add_handler(CommandHandler("remove", commands.remove_users))
74 app.add_handler(CommandHandler("chooser", commands.chooser_user))
[6623428]75 app.add_handler(CommandHandler("next", commands.who_is_next))
[ca5a97e]76
[0d67456]77 app.add_handler(MessageHandler(filters.COMMAND, unknown))
[0d48ea2]78 app.add_error_handler(error_handler)
79
[ca5a97e]80
[0d67456]81 app.run_polling()
[0d48ea2]82
Note: See TracBrowser for help on using the repository browser.