Changeset 0d48ea2 in python-cinema-club-bot for commands/users.py


Ignore:
Timestamp:
Oct 9, 2024, 3:40:27 AM (5 weeks ago)
Author:
Mikhail Kirillov <w96k@…>
Branches:
master
Children:
6623428
Parents:
cc34991
Message:

Add /set command; Add error_handler;

File:
1 edited

Legend:

Unmodified
Added
Removed
  • commands/users.py

    rcc34991 r0d48ea2  
    1414from collections import deque
    1515
    16 from strings import USER_NOT_PROVIDED, USER_ADDED, USER_REMOVED, EXPECTED_ONE_USER
     16from strings import USER_NOT_PROVIDED, USERS_ADDED, USERS_REMOVED, \
     17    EXPECTED_ONE_USER, USER_SET, USER_ADD, USER_REMOVE
    1718from utils import context_init
    1819
    19 from rich import inspect
    2020
     21async def set_users(
     22        update: Update,
     23        context: ContextTypes.DEFAULT_TYPE
     24) -> None:
     25    context_init(context)
     26
     27    if context.args == []:
     28        raise error.TelegramError(USER_NOT_PROVIDED)
     29
     30    context.chat_data["users"] = context.args
     31
     32    await update.message.reply_text(USER_SET)
    2133
    2234async def add_users(
     
    2739
    2840    if context.args == []:
    29         await update.message.reply_text(USER_NOT_PROVIDED)
    3041        raise error.TelegramError(USER_NOT_PROVIDED)
    3142
    3243    for user in context.args:
    3344        context.chat_data["users"].append(user)
    34         await update.message.reply_text(USER_ADDED.format(user=user))
     45        await update.message.reply_text(USER_ADD.format(user=user))
    3546
    36     await update.message.reply_text(context.chat_data["users"])
     47    await update.message.reply_text(USERS_ADDED)
    3748
    3849
     
    5364
    5465    if context.args == []:
    55         await update.message.reply_text(USER_NOT_PROVIDED)
    5666        raise error.TelegramError(USER_NOT_PROVIDED)
    5767
     
    6272
    6373        context.chat_data["users"].remove(user)
    64         await update.message.reply_text(USER_REMOVED.format(user=user))
     74        await update.message.reply_text(USER_REMOVE.format(user=user))
    6575
    66     await update.message.reply_text(context.chat_data["users"])
     76    await update.message.reply_text(USERS_REMOVED)
    6777
    6878
     
    7484
    7585    if context.args == []:
    76         await update.message.reply_text(USER_NOT_PROVIDED)
    7786        raise error.TelegramError(USER_NOT_PROVIDED)
    7887
    7988    if len(context.args) > 1:
    80         await update.message.reply_text(EXPECTED_ONE_USER)
    8189        raise error.TelegramError(EXPECTED_ONE_USER)
    8290
     
    8997    context.chat_data["users"] = list(users)
    9098
    91     await update.message.reply_text(context.chat_data)
     99    await update.message.reply_text(context.chat_data["users"])
Note: See TracChangeset for help on using the changeset viewer.