[0d67456] | 1 | # This file is part of python-cinema-club-bot
|
---|
| 2 | # contributed in 2024 by Mikhail Kirillov (~w96k) <w96k@runbox.com>
|
---|
| 3 |
|
---|
| 4 | # To the extent possible under law, the author(s) have dedicated all copyright
|
---|
| 5 | # and related and neighboring rights to this software to the public domain
|
---|
| 6 | # worldwide. This software is distributed without any warranty.
|
---|
| 7 |
|
---|
| 8 | # You should have received a copy of the CC0 Public Domain Dedication along
|
---|
| 9 | # with this software. If not, see:
|
---|
| 10 | # <http://creativecommons.org/publicdomain/zero/1.0/>
|
---|
| 11 |
|
---|
| 12 | from telegram.ext import ContextTypes
|
---|
[9be02d9] | 13 | from collections import deque
|
---|
[0d67456] | 14 |
|
---|
| 15 | def context_init(context: ContextTypes.DEFAULT_TYPE):
|
---|
[6623428] | 16 | """
|
---|
[0d67456] | 17 | Initialize chat context with starting values
|
---|
[6623428] | 18 | """
|
---|
[0d67456] | 19 |
|
---|
| 20 | if "users" not in context.chat_data:
|
---|
| 21 | context.chat_data["users"]: list[str] = []
|
---|
| 22 |
|
---|
[6623428] | 23 | if "movies" not in context.chat_data:
|
---|
| 24 | context.chat_data["movies"]: list[dict] = []
|
---|
| 25 |
|
---|
[9be02d9] | 26 | if "events" not in context.chat_data:
|
---|
| 27 | context.chat_data["events"]: list[dict] = []
|
---|
| 28 |
|
---|
[0d67456] | 29 | return context
|
---|
[6623428] | 30 |
|
---|
| 31 |
|
---|
| 32 | def normalize_username(username: str):
|
---|
| 33 | return username.replace("@", "")
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 | def create_users_string(users: list[str]) -> str:
|
---|
| 37 | return "`" + ", ".join(users) + "`"
|
---|
[9be02d9] | 38 |
|
---|
| 39 |
|
---|
| 40 | def choose_next_user(users: list[dict]) -> list[dict]:
|
---|
| 41 | users = deque(users)
|
---|
| 42 | users.rotate(-1) # -1 moves list to left by 1 element
|
---|
| 43 |
|
---|
| 44 | return list(users)
|
---|