source: python-cinema-club-bot/app.py@ 5179f7b

Last change on this file since 5179f7b was 5179f7b, checked in by Mikhail Kirillov <w96k@…>, on Oct 8, 2024 at 1:48:33 AM

Add about command

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