summaryrefslogtreecommitdiff
path: root/commands/users.py
diff options
context:
space:
mode:
authorMikhail Kirillov <w96k@runbox.com>2024-10-10 04:12:00 +0400
committerMikhail Kirillov <w96k@runbox.com>2024-10-10 04:12:00 +0400
commit9be02d9141c14a3e3ca28567dbaff671de83200f (patch)
treeecc8c2f7023654179d51e2fdee68b1d688c131d8 /commands/users.py
parent662342863e37e8661f818218df7bb72bc18bf4eb (diff)
Fix #9. Add events commands
Diffstat (limited to 'commands/users.py')
-rw-r--r--commands/users.py38
1 files changed, 30 insertions, 8 deletions
diff --git a/commands/users.py b/commands/users.py
index 497d7dd..9dcc125 100644
--- a/commands/users.py
+++ b/commands/users.py
@@ -15,9 +15,11 @@ from collections import deque
from strings import USER_NOT_PROVIDED, USERS_ADDED, USERS_REMOVED, \
EXPECTED_ONE_USER, USER_SET, USER_ADD, USER_REMOVE, ADD_MORE_USERS, \
- NEXT_MOVIE_USER, USER_NOT_FOUND, USER_CHOOSE
-from utils import context_init, create_users_string
-
+ NEXT_MOVIE_USER, USER_NOT_FOUND, USER_CHOOSE, NO_USERS, \
+ EVENT_USER_HAD_EVENT
+from utils import context_init, create_users_string, normalize_username, \
+ choose_next_user
+from predicates import has_finished_event
async def set_users(
update: Update,
@@ -32,6 +34,7 @@ async def set_users(
await update.message.reply_text(USER_SET)
+
async def add_users(
update: Update,
context: ContextTypes.DEFAULT_TYPE
@@ -56,21 +59,34 @@ async def list_users(
users = context.chat_data["users"]
- await update.message.reply_markdown(create_users_string(users))
+ if users == []:
+ await update.message.reply_text(NO_USERS)
+ else:
+ if has_finished_event(context, users[0]):
+ users = context.chat_data["users"] = choose_next_user(users)
+
+ await update.message.reply_markdown(create_users_string(users))
async def who_is_next(
update: Update,
context: ContextTypes.DEFAULT_TYPE
) -> None:
+ """
+ This commands sets the next chooser if needed and shows current
+ """
+
context_init(context)
users = context.chat_data["users"]
- if len(users) > 0:
- await update.message.reply_text(NEXT_MOVIE_USER.format(user=users[0]))
- else:
- await update.message.reply_text(ADD_MORE_USERS)
+ if users == []:
+ raise error.TelegramError(ADD_MORE_USERS)
+
+ if has_finished_event(context, users[0]):
+ users = context.chat_data["users"] = choose_next_user(users)
+
+ await update.message.reply_text(NEXT_MOVIE_USER.format(user=users[0]))
async def remove_users(
@@ -118,6 +134,12 @@ async def chooser_user(
context.chat_data["users"] = users
+ if has_finished_event(context, users[0]):
+ await update.message.reply_text(
+ EVENT_USER_HAD_EVENT.format(user=users[0])
+ )
+ users = context.chat_data["users"] = choose_next_user(users)
+
await update.message.reply_text(USER_CHOOSE.format(user=users[0]))
await update.message.reply_markdown(create_users_string(users))