Changeset cc34991 in python-cinema-club-bot


Ignore:
Timestamp:
Oct 9, 2024, 3:09:50 AM (5 weeks ago)
Author:
Mikhail Kirillov <w96k@…>
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)
Message:

Add commands modules; Added /chooser command

Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • main.py

    r0d67456 rcc34991  
    1010# <http://creativecommons.org/publicdomain/zero/1.0/>
    1111
    12 from telegram import Update, error
     12from telegram import Update
    1313from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes, \
    1414    MessageHandler, filters
     
    1616import os
    1717import logging
    18 from rich import inspect
    1918
    20 from strings import INVALID_COMMAND, USER_NOT_PROVIDED, USER_ADDED, \
    21     USER_REMOVED
    22 from utils import context_init
     19from strings import INVALID_COMMAND
    2320from persistence import Persistence
     21import commands
    2422
    2523
     
    3230
    3331
    34 async def about(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
    35     await update.message.reply_text('''
    36 Version 0.0
    37 
    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-bot
    41 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_TYPE
    56 ) -> 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_TYPE
    73 ) -> 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_TYPE
    82 ) -> 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             break
    93        
    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 
    10032async def unknown(update: Update, context: ContextTypes.DEFAULT_TYPE):
    10133    await context.bot.send_message(
     
    10537
    10638
    107 if __name__ == "__main__":   
     39if __name__ == "__main__":
    10840    app = ApplicationBuilder().token(
    10941        os.environ.get("TELEGRAM_TOKEN")
    11042    ).persistence(Persistence).build()
    11143
    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))
    11649
    11750
  • strings.py

    r0d67456 rcc34991  
    1212INVALID_COMMAND = "Invalid command. Available commands: /add"
    1313USER_NOT_PROVIDED = "User(s) is not provided"
     14EXPECTED_ONE_USER = "Expected only one user"
    1415USER_ADDED = "User {user} has been added"
    1516USER_REMOVED = "User {user} has been removed"
Note: See TracChangeset for help on using the changeset viewer.