Changeset 69dd60c in python-cinema-club-bot for utils.py


Ignore:
Timestamp:
Oct 11, 2024, 1:53:24 AM (5 weeks ago)
Author:
Mikhail Kirillov <w96k@…>
Branches:
master
Children:
ac7b16a
Parents:
694d823
Message:

Task #30. Allow anyone create or edit upcoming event

File:
1 edited

Legend:

Unmodified
Added
Removed
  • utils.py

    r694d823 r69dd60c  
    1212from telegram.ext import ContextTypes
    1313from collections import deque
     14from typing import Optional
    1415
    1516def context_init(context: ContextTypes.DEFAULT_TYPE):
     
    3839
    3940
    40 def choose_next_user(users: list[dict]) -> list[dict]:
    41     users = deque(users)
     41def choose_next_user(context: ContextTypes.DEFAULT_TYPE) -> list[dict]:
     42    users = deque(context.chat_data["users"])
    4243    users.rotate(-1)  # -1 moves list to left by 1 element
    4344
     45    init_new_event(context, users[0])
     46
    4447    return list(users)
     48
     49
     50def init_new_event(context: ContextTypes.DEFAULT_TYPE, user: dict, movie: Optional[str] = None):
     51    events = context.chat_data["events"]
     52
     53    last_event = events[-1] if events != [] else None
     54
     55    init_event = dict(
     56        when=None,
     57        where=None,
     58        movie=movie,
     59        user=user
     60    )
     61
     62    if last_event and last_event["movie"] is None:
     63        events[-1] = init_event
     64    else:
     65        events.append(init_event)
Note: See TracChangeset for help on using the changeset viewer.