Changeset cc34991
- Timestamp:
- Oct 9, 2024, 3:09:50 AM (5 weeks ago)
- Branches:
- master
- Children:
- 0d48ea2
- Parents:
- 0d67456
- git-author:
- Mikhail Kirillov <w96k@…> (10/09/24 03:05:41)
- git-committer:
- Mikhail Kirillov <w96k@…> (10/09/24 03:09:50)
- Files:
-
- 3 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main.py
r0d67456 rcc34991 10 10 # <http://creativecommons.org/publicdomain/zero/1.0/> 11 11 12 from telegram import Update , error12 from telegram import Update 13 13 from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes, \ 14 14 MessageHandler, filters … … 16 16 import os 17 17 import logging 18 from rich import inspect19 18 20 from strings import INVALID_COMMAND, USER_NOT_PROVIDED, USER_ADDED, \ 21 USER_REMOVED 22 from utils import context_init 19 from strings import INVALID_COMMAND 23 20 from persistence import Persistence 21 import commands 24 22 25 23 … … 32 30 33 31 34 async def about(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:35 await update.message.reply_text('''36 Version 0.037 38 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.39 40 Project information: http://57.129.46.169/trac/wiki/python-cinema-club-bot41 Source code: http://57.129.46.169/cgit/python-cinema-club-bot/42 43 Contributed in 2024 by Mikhail Kirillov (~w96k) <w96k@runbox.com>44 45 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.46 47 You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see:48 <http://creativecommons.org/publicdomain/zero/1.0/>49 50 ''')51 52 53 async def add(54 update: Update,55 context: ContextTypes.DEFAULT_TYPE56 ) -> None:57 context_init(context)58 59 if context.args == []:60 await update.message.reply_text(USER_NOT_PROVIDED)61 raise error.TelegramError(USER_NOT_PROVIDED)62 63 for user in context.args:64 context.chat_data["users"].append(user)65 await update.message.reply_text(USER_ADDED.format(user=user))66 67 await update.message.reply_text(context.chat_data)68 69 70 async def list(71 update: Update,72 context: ContextTypes.DEFAULT_TYPE73 ) -> None:74 context_init(context)75 76 await update.message.reply_text(context.chat_data)77 78 79 async def remove(80 update: Update,81 context: ContextTypes.DEFAULT_TYPE82 ) -> None:83 context_init(context)84 85 if context.args == []:86 await update.message.reply_text(USER_NOT_PROVIDED)87 raise error.TelegramError(USER_NOT_PROVIDED)88 89 for user in context.args:90 if user == "*":91 context.chat_data["users"] = []92 break93 94 context.chat_data["users"].remove(user)95 await update.message.reply_text(USER_REMOVED.format(user=user))96 97 await update.message.reply_text(context.chat_data)98 99 100 32 async def unknown(update: Update, context: ContextTypes.DEFAULT_TYPE): 101 33 await context.bot.send_message( … … 105 37 106 38 107 if __name__ == "__main__": 39 if __name__ == "__main__": 108 40 app = ApplicationBuilder().token( 109 41 os.environ.get("TELEGRAM_TOKEN") 110 42 ).persistence(Persistence).build() 111 43 112 app.add_handler(CommandHandler("about", about)) 113 app.add_handler(CommandHandler("add", add)) 114 app.add_handler(CommandHandler("list", list)) 115 app.add_handler(CommandHandler("remove", remove)) 44 app.add_handler(CommandHandler("about", commands.about)) 45 app.add_handler(CommandHandler("add", commands.add_users)) 46 app.add_handler(CommandHandler("list", commands.list_users)) 47 app.add_handler(CommandHandler("remove", commands.remove_users)) 48 app.add_handler(CommandHandler("chooser", commands.chooser_user)) 116 49 117 50 -
strings.py
r0d67456 rcc34991 12 12 INVALID_COMMAND = "Invalid command. Available commands: /add" 13 13 USER_NOT_PROVIDED = "User(s) is not provided" 14 EXPECTED_ONE_USER = "Expected only one user" 14 15 USER_ADDED = "User {user} has been added" 15 16 USER_REMOVED = "User {user} has been removed"
Note:
See TracChangeset
for help on using the changeset viewer.