summaryrefslogtreecommitdiff
path: root/commands/users.py
diff options
context:
space:
mode:
authorMikhail Kirillov <w96k@runbox.com>2024-10-11 01:53:24 +0400
committerMikhail Kirillov <w96k@runbox.com>2024-10-11 01:53:24 +0400
commit69dd60cc024063daf1591168a64a32e771bd7f1b (patch)
tree9af211858513072175e5611a15e47012b34f349c /commands/users.py
parent694d823d4d46ec2914f6e210f8903887e4a72d79 (diff)
Task #30. Allow anyone create or edit upcoming event
Diffstat (limited to 'commands/users.py')
-rw-r--r--commands/users.py34
1 files changed, 18 insertions, 16 deletions
diff --git a/commands/users.py b/commands/users.py
index 4134a21..1d0714f 100644
--- a/commands/users.py
+++ b/commands/users.py
@@ -16,9 +16,10 @@ from collections import deque
from strings import USER_NOT_PROVIDED, USERS_ADDED, USERS_REMOVED, \
EXPECTED_ONE_USER, USER_SET, USER_REMOVE, ADD_MORE_USERS, \
NEXT_MOVIE_USER, USER_NOT_FOUND, USER_CHOOSE, NO_USERS, \
- EVENT_USER_HAD_EVENT, NEXT_MOVIE
-from utils import context_init, create_users_string, choose_next_user
-from predicates import has_finished_event
+ NEXT_MOVIE
+from utils import context_init, create_users_string, choose_next_user, \
+ normalize_username
+from predicates import has_finished_movie, has_event_without_movie
async def set_users(
@@ -60,11 +61,12 @@ async def list_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)
+ return
- await update.message.reply_markdown(create_users_string(users))
+ if has_finished_movie(context):
+ users = context.chat_data["users"] = choose_next_user(context)
+
+ await update.message.reply_markdown(create_users_string(users))
async def who_is_next(
@@ -82,15 +84,15 @@ async def who_is_next(
if users == []:
raise error.TelegramError(ADD_MORE_USERS)
- if has_finished_event(context, users[0]):
- users = context.chat_data["users"] = choose_next_user(users)
+ if has_finished_movie(context):
+ users = context.chat_data["users"] = choose_next_user(context)
next_user_string = NEXT_MOVIE_USER.format(user=users[0])
- last_movie = context.chat_data["movies"][0] \
+ last_movie = context.chat_data["movies"][-1] \
if context.chat_data["movies"] != [] else None
- if last_movie and last_movie["user"] == users[0]:
+ if last_movie and last_movie["user"] == normalize_username(users[0]):
next_user_string += NEXT_MOVIE.format(movie=last_movie["title"])
await update.message.reply_text(next_user_string)
@@ -141,11 +143,11 @@ 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)
+ if has_finished_movie(context):
+ users = context.chat_data["users"] = choose_next_user(context)
+
+ if has_event_without_movie(context):
+ context.chat_data["events"][-1]["user"] = users[0]
await update.message.reply_text(USER_CHOOSE.format(user=users[0]))