summaryrefslogtreecommitdiff
path: root/commands
diff options
context:
space:
mode:
authorMikhail Kirillov <w96k@runbox.com>2024-10-09 03:40:27 +0400
committerMikhail Kirillov <w96k@runbox.com>2024-10-09 03:40:27 +0400
commit0d48ea28aeb8a6290d2aeab202efa9c8d6e30fe3 (patch)
tree8b83495d3eb235194b9d736bf0713ff362e27f2b /commands
parentcc34991f2098692a2cb2a9e913bd6667d38fdab5 (diff)
Add /set command; Add error_handler;
Diffstat (limited to 'commands')
-rw-r--r--commands/__init__.py2
-rw-r--r--commands/users.py30
2 files changed, 20 insertions, 12 deletions
diff --git a/commands/__init__.py b/commands/__init__.py
index e2fd670..b494867 100644
--- a/commands/__init__.py
+++ b/commands/__init__.py
@@ -10,4 +10,4 @@
# <http://creativecommons.org/publicdomain/zero/1.0/>
from .meta import about
-from .users import add_users, list_users, remove_users, chooser_user
+from .users import set_users, add_users, list_users, remove_users, chooser_user
diff --git a/commands/users.py b/commands/users.py
index affdb53..413b681 100644
--- a/commands/users.py
+++ b/commands/users.py
@@ -13,11 +13,23 @@ from telegram import Update, error
from telegram.ext import ContextTypes
from collections import deque
-from strings import USER_NOT_PROVIDED, USER_ADDED, USER_REMOVED, EXPECTED_ONE_USER
+from strings import USER_NOT_PROVIDED, USERS_ADDED, USERS_REMOVED, \
+ EXPECTED_ONE_USER, USER_SET, USER_ADD, USER_REMOVE
from utils import context_init
-from rich import inspect
+async def set_users(
+ update: Update,
+ context: ContextTypes.DEFAULT_TYPE
+) -> None:
+ context_init(context)
+
+ if context.args == []:
+ raise error.TelegramError(USER_NOT_PROVIDED)
+
+ context.chat_data["users"] = context.args
+
+ await update.message.reply_text(USER_SET)
async def add_users(
update: Update,
@@ -26,14 +38,13 @@ async def add_users(
context_init(context)
if context.args == []:
- await update.message.reply_text(USER_NOT_PROVIDED)
raise error.TelegramError(USER_NOT_PROVIDED)
for user in context.args:
context.chat_data["users"].append(user)
- await update.message.reply_text(USER_ADDED.format(user=user))
+ await update.message.reply_text(USER_ADD.format(user=user))
- await update.message.reply_text(context.chat_data["users"])
+ await update.message.reply_text(USERS_ADDED)
async def list_users(
@@ -52,7 +63,6 @@ async def remove_users(
context_init(context)
if context.args == []:
- await update.message.reply_text(USER_NOT_PROVIDED)
raise error.TelegramError(USER_NOT_PROVIDED)
for user in context.args:
@@ -61,9 +71,9 @@ async def remove_users(
break
context.chat_data["users"].remove(user)
- await update.message.reply_text(USER_REMOVED.format(user=user))
+ await update.message.reply_text(USER_REMOVE.format(user=user))
- await update.message.reply_text(context.chat_data["users"])
+ await update.message.reply_text(USERS_REMOVED)
async def chooser_user(
@@ -73,11 +83,9 @@ async def chooser_user(
context_init(context)
if context.args == []:
- await update.message.reply_text(USER_NOT_PROVIDED)
raise error.TelegramError(USER_NOT_PROVIDED)
if len(context.args) > 1:
- await update.message.reply_text(EXPECTED_ONE_USER)
raise error.TelegramError(EXPECTED_ONE_USER)
chooser = context.args[0]
@@ -88,4 +96,4 @@ async def chooser_user(
context.chat_data["users"] = list(users)
- await update.message.reply_text(context.chat_data)
+ await update.message.reply_text(context.chat_data["users"])