diff --git a/modules/auto-schedule-pro-v2/main.py b/modules/auto-schedule-pro-v2/main.py index 672b5e5..b77484f 100644 --- a/modules/auto-schedule-pro-v2/main.py +++ b/modules/auto-schedule-pro-v2/main.py @@ -28,6 +28,13 @@ lesson_types_to_strings = { "con": "консультація" } +color_code_mapping = { + "lec": "🔵", + "prac": "🟡", + "lab": "🔴", + "con": "🟢" +} + # global variables module_path = "" @@ -114,6 +121,10 @@ def load_template(template, part): return readfile(f"templates/{template}/{part}.msg") +def get_color_code(lesson_type): + return color_code_mapping[lesson_type] + + def escaped_string_markdownV2(input_string): result_string = input_string @@ -165,9 +176,6 @@ def get_name_of_lesson_type(lesson_type): def generate_lesson_description(lesson, start_datetime, end_datetime, current_day, current_week, overrides={}, custom_name_prefix="Назва", template="legacy-vibrant", force_date_at_top=False): - # temporarily not supported - #output_settings = {"name": True, "date": True, "teacher": True, "link": True, "comment": True} - #output_settings.update(overrides) if lesson.__class__ == dict: if force_date_at_top: @@ -176,33 +184,51 @@ def generate_lesson_description(lesson, start_datetime, end_datetime, current_da current_day, current_week) total_result = total_result.replace("%DATE%", human_readable_date) - total_result += load_template(template, "multiple") - for i in ['name', 'teacher', 'link']: + if "full" in overrides and overrides["full"]: + total_result += load_template(template, "multiple") + else: + total_result += load_template(template, "multiple-short") + + for i in ['name', 'teacher']: total_result = total_result.replace(f"%{i.upper()}%", lesson[i]) total_result = total_result.replace("%DATE%", human_readable_date) total_result = total_result.replace("%TYPE%", get_name_of_lesson_type(lesson['type'])) total_result = total_result.replace("%NAME_PREFIX%", custom_name_prefix) + total_result = total_result.replace("%COLOR_CODE%", get_color_code(lesson['type'])) + + if ('nolink' not in lesson) or (not lesson['nolink']): + total_result = total_result.replace("%LINK%", lesson['link']) + else: + total_result = total_result.replace("%LINK%", "#") if 'comment' in lesson: total_result += load_template(template, "comment") total_result = total_result.replace("%COMMENT%", lesson["comment"]) - return total_result + "\n" + if "full" in overrides and overrides["full"]: + total_result += "\n" + + return total_result else: active_template = load_template(template, "single") - for i in ['name', 'teacher', 'link']: + for i in ['name', 'teacher']: active_template = active_template.replace(f"%{i.upper()}%", lesson[i]) - human_readable_date = get_human_readable_date(start_datetime, end_datetime, current_day, current_week) active_template = active_template.replace("%DATE%", human_readable_date) active_template = active_template.replace("%TYPE%", get_name_of_lesson_type(lesson['type'])) active_template = active_template.replace("%NAME_PREFIX%", custom_name_prefix) + active_template = active_template.replace("%COLOR_CODE%", get_color_code(lesson['type'])) + + if ('nolink' not in lesson) or (not lesson['nolink']): + active_template = active_template.replace("%LINK%", lesson['link']) + else: + active_template = active_template.replace("%LINK%", "#") if 'comment' in lesson: active_template += load_template(template, "comment") @@ -213,24 +239,36 @@ def generate_lesson_description(lesson, start_datetime, end_datetime, current_da elif lesson.__class__ == list: total_result = load_template(template, "date") human_readable_date = get_human_readable_date(start_datetime, end_datetime, - current_day, current_week) + current_day, current_week) total_result = total_result.replace("%DATE%", human_readable_date) for l in lesson: - active_template = load_template(template, "multiple") + if "full" in overrides and overrides["full"]: + active_template = load_template(template, "multiple") + else: + active_template = load_template(template, "multiple-short") - for i in ['name', 'teacher', 'link']: + for i in ['name', 'teacher']: active_template = active_template.replace(f"%{i.upper()}%", l[i]) active_template = active_template.replace("%DATE%", human_readable_date) active_template = active_template.replace("%TYPE%", get_name_of_lesson_type(l['type'])) active_template = active_template.replace("%NAME_PREFIX%", custom_name_prefix) + active_template = active_template.replace("%COLOR_CODE%", get_color_code(l['type'])) + + if ('nolink' not in lesson) or (not lesson['nolink']): + active_template = active_template.replace("%LINK%", l['link']) + else: + active_template = active_template.replace("%LINK%", "#") if 'comment' in lesson: - total_result += load_template(template, "comment") - total_result = total_result.replace("%COMMENT%", lesson["comment"]) + active_template += load_template(template, "comment") + active_template = active_template.replace("%COMMENT%", lesson["comment"]) - total_result += active_template + "\n" + if "full" in overrides and overrides["full"]: + active_template += "\n" + + total_result += active_template return total_result @@ -324,19 +362,20 @@ def process(message, path): if base_command in ["!пара", "!para"]: # easter egg - study_begin_ts = int(datetime(year=2024, month=2, day=5).strftime("%s")) + study_begin_ts = int(datetime(year=2024, month=9, day=2).strftime("%s")) current_ts = int(datetime.now().strftime("%s")) until_study_day = study_begin_ts - current_ts if -3600*4 < until_study_day < 0: return "Навчання от-от розпочнеться!", None - elif 0 <= until_study_day < 3600*24*14: + elif 0 <= until_study_day < 3600*24*28: return f"До навчання залишилося {until_study_day} секунд..." \ f" ({round(until_study_day/3600, 4)} годин," \ f" {round(until_study_day/3600/24, 4)} діб)", None elif until_study_day >= 3600*24*14: return "Ви маєте законне право відпочити, пари почнуться не скоро", None + # actual lesson finding code upcoming_lessons = [timestamp for timestamp in schedule if timestamp > current_seconds - 5400] diff --git a/modules/auto-schedule-pro-v2/templates/legacy-vibrant/multiple-short.msg b/modules/auto-schedule-pro-v2/templates/legacy-vibrant/multiple-short.msg new file mode 100644 index 0000000..a7c5ead --- /dev/null +++ b/modules/auto-schedule-pro-v2/templates/legacy-vibrant/multiple-short.msg @@ -0,0 +1 @@ +%COLOR_CODE% %NAME% diff --git a/modules/auto-schedule-pro-v2/templates/legacy/multiple-short.msg b/modules/auto-schedule-pro-v2/templates/legacy/multiple-short.msg new file mode 100644 index 0000000..55bc177 --- /dev/null +++ b/modules/auto-schedule-pro-v2/templates/legacy/multiple-short.msg @@ -0,0 +1 @@ +%COLOR_CODE% %NAME% diff --git a/modules/auto-schedule-pro-v2/templates/modern/multiple-short.msg b/modules/auto-schedule-pro-v2/templates/modern/multiple-short.msg new file mode 100644 index 0000000..a7c5ead --- /dev/null +++ b/modules/auto-schedule-pro-v2/templates/modern/multiple-short.msg @@ -0,0 +1 @@ +%COLOR_CODE% %NAME%