[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 |
|
---|
[5179f7b] | 12 | from telegram import Update, error
|
---|
| 13 | from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes, \
|
---|
| 14 | MessageHandler, filters
|
---|
[ca5a97e] | 15 | from dotenv import load_dotenv
|
---|
[5179f7b] | 16 | from rich import inspect
|
---|
[ca5a97e] | 17 | import os
|
---|
[50e04dd] | 18 | import logging
|
---|
[71efb80] | 19 | from .strings import INVALID_COMMAND
|
---|
[ca5a97e] | 20 |
|
---|
| 21 | load_dotenv()
|
---|
| 22 |
|
---|
[50e04dd] | 23 | logging.basicConfig(
|
---|
| 24 | level=logging.INFO,
|
---|
| 25 | format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
---|
| 26 | )
|
---|
| 27 |
|
---|
[71efb80] | 28 |
|
---|
[5179f7b] | 29 | async def about(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
---|
| 30 | await update.message.reply_text('''
|
---|
| 31 | Version 0.0
|
---|
[71efb80] | 32 |
|
---|
[5179f7b] | 33 | python-cinema-club-bot is a bot for Telegram specialized for managing cinema club activities. This software is released as Public Domain using CC0 license.
|
---|
[ca5a97e] | 34 |
|
---|
[5179f7b] | 35 | Project information: http://57.129.46.169/trac/wiki/python-cinema-club-bot
|
---|
| 36 | Source code: http://57.129.46.169/cgit/python-cinema-club-bot/
|
---|
| 37 |
|
---|
| 38 | Contributed in 2024 by Mikhail Kirillov (~w96k) <w96k@runbox.com>
|
---|
| 39 |
|
---|
| 40 | To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
|
---|
| 41 |
|
---|
| 42 | You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see:
|
---|
| 43 | <http://creativecommons.org/publicdomain/zero/1.0/>
|
---|
| 44 |
|
---|
| 45 | ''')
|
---|
| 46 |
|
---|
[71efb80] | 47 |
|
---|
[5179f7b] | 48 | async def add_choose_cycle(
|
---|
| 49 | update: Update,
|
---|
| 50 | context: ContextTypes.DEFAULT_TYPE
|
---|
| 51 | ) -> None:
|
---|
| 52 | command = update.message.text
|
---|
| 53 |
|
---|
| 54 | user = command.replace("/add", "")
|
---|
| 55 |
|
---|
| 56 | inspect(user)
|
---|
| 57 |
|
---|
| 58 | try:
|
---|
| 59 | if user == "":
|
---|
| 60 | raise error.TelegramError("User is not provided. Use /add @username")
|
---|
| 61 | except error.TelegramError as err:
|
---|
| 62 | await update.message.reply_text(err.message)
|
---|
| 63 | return
|
---|
| 64 |
|
---|
| 65 | await update.message.reply_text(update.message.text)
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | async def unknown(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
---|
[71efb80] | 69 | await context.bot.send_message(chat_id=update.effective_chat.id, text=INVALID_COMMAND)
|
---|
[ca5a97e] | 70 |
|
---|
| 71 | app = ApplicationBuilder().token(
|
---|
| 72 | os.environ.get('TELEGRAM_TOKEN')
|
---|
| 73 | ).build()
|
---|
| 74 |
|
---|
[5179f7b] | 75 | app.add_handler(CommandHandler("about", about))
|
---|
| 76 | app.add_handler(CommandHandler("add", add_choose_cycle))
|
---|
| 77 |
|
---|
| 78 | app.add_handler(MessageHandler(filters.COMMAND, unknown))
|
---|
[ca5a97e] | 79 |
|
---|
| 80 | app.run_polling()
|
---|