Merge updates from dev branch to master #10

Merged
dymik739 merged 12 commits from dev into master 2023-09-12 12:32:45 +03:00
1 changed files with 43 additions and 6 deletions
Showing only changes of commit 604054af9e - Show all commits

View File

@ -48,8 +48,13 @@ def get_preference_by_id(user_id, name):
def get_all_preferences_by_id(user_id):
user_preferences = {"output-style": "legacy-vibrant"}
user_preferences = {
"output-style": "legacy-vibrant",
"output-style-lesson": "None",
"output-style-lookup": "None"
}
# label defaults as defaults and let custom settings override these labels
for i in user_preferences:
user_preferences[i] += " <i>(default)</i>"
@ -303,10 +308,6 @@ def process(message, path):
reference_time = int(current_time.strftime("%s")) - current_seconds
output_style_preference = get_preference_by_id(message.from_user.id, "output-style")
if output_style_preference == None:
output_style_preference = "legacy-vibrant"
if base_command == "!пара":
# easter egg
study_begin_ts = int(datetime(year=2023, month=9, day=4).strftime("%s"))
@ -327,6 +328,32 @@ def process(message, path):
else:
closest_lesson_time = min(schedule)
# shifting lesson pointer if requested to do so
if len(full_command) >= 2:
possible_times = list(schedule.keys())
current_pointer_position = possible_times.index(closest_lesson_time)
total_list_length = len(possible_times)
if len(full_command[1]) > 1 and full_command[1][1:].isdigit():
if full_command[1][0] == "+":
current_pointer_position = (current_pointer_position + int(full_command[1][1:])) % total_list_length
else:
current_pointer_position = (current_pointer_position - int(full_command[1][1:])) % total_list_length
closest_lesson_time = possible_times[current_pointer_position]
# getting corrent style
output_style_preference = "legacy-vibrant"
general_output_style_preference = get_preference_by_id(message.from_user.id, "output-style")
if general_output_style_preference != None:
output_style_preference = general_output_style_preference
specific_output_style_preference = get_preference_by_id(message.from_user.id, "output-style-lesson")
if specific_output_style_preference != None:
output_style_preference = specific_output_style_preference
# returning generated pair description
return get_lesson_description(schedule, reference_time, closest_lesson_time, current_day,
current_week, custom_name_prefix="Актуальна пара", template=output_style_preference), "HTML"
@ -342,6 +369,16 @@ def process(message, path):
lesson_list = [i for i in schedule if selected_day * 86400 <= i < (selected_day + 1) * 86400]
output_style_preference = "legacy-vibrant"
general_output_style_preference = get_preference_by_id(message.from_user.id, "output-style")
if general_output_style_preference != None:
output_style_preference = general_output_style_preference
specific_output_style_preference = get_preference_by_id(message.from_user.id, "output-style-lookup")
if specific_output_style_preference != None:
output_style_preference = specific_output_style_preference
lesson_descriptions_list = [get_lesson_description(schedule, reference_time, lesson_time, current_day,
current_week, overrides=preferences, custom_name_prefix="Назва", template=output_style_preference, force_date_at_top=True)
for lesson_time in lesson_list]
@ -357,7 +394,7 @@ def process(message, path):
prefs = get_all_preferences_by_id(message.from_user.id)
if full_command[2] in prefs:
if full_command[2] == "output-style":
if full_command[2] in ["output-style", "output-style-lesson", "output-style-lookup"]:
if full_command[3] not in os.listdir(module_path + "templates/"):
return f"Стилю {full_command[3]} не існує; доступні варіанти: " \
+ ', '.join(os.listdir(module_path + "templates/")), "HTML"