Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b0ea33cfff |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,3 @@
|
|||||||
config/*
|
config/*
|
||||||
modules/irc-bridge/error.log
|
modules/irc-bridge/error.log
|
||||||
__pycache__/
|
__pycache__/
|
||||||
modules/auto-schedule-pro-v2/preference-db
|
|
||||||
|
|||||||
8
main.py
8
main.py
@@ -98,7 +98,7 @@ class ModuleControlUnit:
|
|||||||
print(f"[WARN] module_loader: no meta.json found in module folder \"{folder}\"")
|
print(f"[WARN] module_loader: no meta.json found in module folder \"{folder}\"")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
meta = json.loads( meta_raw )
|
meta = json.loads(meta_raw)
|
||||||
if "version" in meta:
|
if "version" in meta:
|
||||||
if meta["version"] == 1:
|
if meta["version"] == 1:
|
||||||
if "index_file" in meta:
|
if "index_file" in meta:
|
||||||
@@ -106,7 +106,7 @@ class ModuleControlUnit:
|
|||||||
else:
|
else:
|
||||||
index_file = "index.py"
|
index_file = "index.py"
|
||||||
|
|
||||||
code = readfile( "modules/{}/{}".format(folder, index_file) )
|
code = readfile("modules/{}/{}".format(folder, index_file))
|
||||||
if not code: # False both when readfile() returns False and when the code string is empty
|
if not code: # False both when readfile() returns False and when the code string is empty
|
||||||
print("[WARN] reload_modules: module {} does not have any code, skipping...".format(folder))
|
print("[WARN] reload_modules: module {} does not have any code, skipping...".format(folder))
|
||||||
continue
|
continue
|
||||||
@@ -205,7 +205,8 @@ def queue_processor():
|
|||||||
updater.bot.send_message(chat_id=msg.chat.id, text=response,
|
updater.bot.send_message(chat_id=msg.chat.id, text=response,
|
||||||
disable_web_page_preview=True,
|
disable_web_page_preview=True,
|
||||||
parse_mode=formatting)
|
parse_mode=formatting)
|
||||||
print(f"Responded using module {mod.path} ({mod.alias}) with text (using {formatting}): {response}")
|
print(
|
||||||
|
f"Responded using module {mod.path} ({mod.alias}) with text (using {formatting}): {response}")
|
||||||
break
|
break
|
||||||
|
|
||||||
del message_queue[0]
|
del message_queue[0]
|
||||||
@@ -247,7 +248,6 @@ mcu = ModuleControlUnit()
|
|||||||
processor_thread = threading.Thread(target=queue_processor, args=[])
|
processor_thread = threading.Thread(target=queue_processor, args=[])
|
||||||
processor_thread.start()
|
processor_thread.start()
|
||||||
|
|
||||||
|
|
||||||
# connecting to Telegram servers and listening for messages
|
# connecting to Telegram servers and listening for messages
|
||||||
|
|
||||||
TOKEN = readfile("config/token")
|
TOKEN = readfile("config/token")
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ class ModuleV1:
|
|||||||
return self.RESPONSE, self.FORMAT
|
return self.RESPONSE, self.FORMAT
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[ERROR] module v1: module \"{self.path}\" ({self.alias}) raised exception \"{e}\"")
|
print(f"[ERROR] module v1: module \"{self.path}\" ({self.alias}) raised exception \"{e}\"")
|
||||||
print(f"[ERROR] module v1: traceback:\n{traceback.format_exc()}")
|
print(f"[ERROR] module v1: traceback:\ntraceback.format_exc()")
|
||||||
return "", None
|
return "", None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
|
|
||||||
def readfile(filename):
|
def readfile(filename):
|
||||||
with open(module_path + filename) as f:
|
with open(module_path + filename) as f:
|
||||||
return f.read()
|
return f.read()
|
||||||
|
|
||||||
def writefile(filename, data):
|
|
||||||
with open(module_path + filename, 'w') as f:
|
|
||||||
f.write(data)
|
|
||||||
|
|
||||||
# global constants
|
# global constants
|
||||||
# Accusative - znahidnyj
|
# Accusative - znahidnyj
|
||||||
@@ -27,91 +24,9 @@ lesson_types_to_strings = {
|
|||||||
"lab": "лабораторна"
|
"lab": "лабораторна"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# global variables
|
# global variables
|
||||||
module_path = ""
|
module_path = ""
|
||||||
|
|
||||||
def get_preference_by_id(user_id, name):
|
|
||||||
if not os.path.exists(module_path + f"preference-db/{user_id}.json"):
|
|
||||||
return None
|
|
||||||
|
|
||||||
raw_prefs = readfile(f"preference-db/{user_id}.json")
|
|
||||||
try:
|
|
||||||
preferences = json.loads(raw_prefs)
|
|
||||||
except Exception as e:
|
|
||||||
return None
|
|
||||||
|
|
||||||
if not name in preferences:
|
|
||||||
return None
|
|
||||||
|
|
||||||
return preferences[name]
|
|
||||||
|
|
||||||
|
|
||||||
def get_all_preferences_by_id(user_id):
|
|
||||||
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>"
|
|
||||||
|
|
||||||
for i in user_preferences:
|
|
||||||
override = get_preference_by_id(user_id, i)
|
|
||||||
if override != None:
|
|
||||||
user_preferences[i] = override
|
|
||||||
|
|
||||||
return user_preferences
|
|
||||||
|
|
||||||
|
|
||||||
def set_preference_by_id(user_id, name, value):
|
|
||||||
if not os.path.exists(module_path + "preference-db/"):
|
|
||||||
os.mkdir(module_path + "preference-db/")
|
|
||||||
|
|
||||||
preferences = {}
|
|
||||||
|
|
||||||
if os.path.exists(module_path + f"preference-db/{user_id}.json"):
|
|
||||||
try:
|
|
||||||
raw_prefs = readfile(f"preference-db/{user_id}.json")
|
|
||||||
preferences = json.loads(raw_prefs)
|
|
||||||
except Exception as e:
|
|
||||||
preferences = {}
|
|
||||||
else:
|
|
||||||
preferences = {}
|
|
||||||
|
|
||||||
preferences[name] = value
|
|
||||||
|
|
||||||
final_data = json.dumps(preferences)
|
|
||||||
writefile(f"preference-db/{user_id}.json", final_data)
|
|
||||||
|
|
||||||
|
|
||||||
def clear_preference_by_id(user_id, name):
|
|
||||||
if not os.path.exists(module_path + "preference-db/"):
|
|
||||||
os.mkdir(module_path + "preference-db/")
|
|
||||||
|
|
||||||
preferences = {}
|
|
||||||
|
|
||||||
if os.path.exists(module_path + f"preference-db/{user_id}.json"):
|
|
||||||
try:
|
|
||||||
raw_prefs = readfile(f"preference-db/{user_id}.json")
|
|
||||||
preferences = json.loads(raw_prefs)
|
|
||||||
except Exception as e:
|
|
||||||
preferences = {}
|
|
||||||
else:
|
|
||||||
preferences = {}
|
|
||||||
|
|
||||||
if name in preferences:
|
|
||||||
del preferences[name]
|
|
||||||
|
|
||||||
final_data = json.dumps(preferences)
|
|
||||||
writefile(f"preference-db/{user_id}.json", final_data)
|
|
||||||
|
|
||||||
|
|
||||||
def load_template(template, part):
|
|
||||||
return readfile(f"templates/{template}/{part}.msg")
|
|
||||||
|
|
||||||
|
|
||||||
def escaped_string_markdownV2(input_string):
|
def escaped_string_markdownV2(input_string):
|
||||||
result_string = input_string
|
result_string = input_string
|
||||||
@@ -163,63 +78,30 @@ def get_name_of_lesson_type(lesson_type):
|
|||||||
|
|
||||||
|
|
||||||
def generate_lesson_description(lesson, start_datetime, end_datetime, current_day, current_week, overrides={},
|
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):
|
custom_name_prefix="<b>Назва</b>"):
|
||||||
# temporarily not supported
|
output_settings = {"name": True, "date": True, "teacher": True, "link": True, "comment": True}
|
||||||
#output_settings = {"name": True, "date": True, "teacher": True, "link": True, "comment": True}
|
output_settings.update(overrides)
|
||||||
#output_settings.update(overrides)
|
|
||||||
|
|
||||||
if lesson.__class__ == dict:
|
result = ""
|
||||||
if force_date_at_top:
|
|
||||||
total_result = load_template(template, "date")
|
if output_settings['name']:
|
||||||
|
result += f"<b>{escaped_string_html(lesson['name'])}<b> ({escaped_string_html(get_name_of_lesson_type(lesson['type']))})\n"
|
||||||
|
|
||||||
|
if output_settings['date']:
|
||||||
human_readable_date = get_human_readable_date(start_datetime, end_datetime,
|
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)
|
result += f"<i>Дата</ii>: {escaped_string_html(human_readable_date)}\n"
|
||||||
|
|
||||||
total_result += load_template(template, "multiple")
|
if output_settings['teacher']:
|
||||||
for i in ['name', 'teacher', 'link']:
|
result += f"<i>Викладач</i>: {escaped_string_html(lesson['teacher'])}\n"
|
||||||
total_result = total_result.replace(f"%{i.upper()}%", lesson[i])
|
|
||||||
|
|
||||||
total_result = total_result.replace("%DATE%", human_readable_date)
|
if output_settings['link']:
|
||||||
total_result = total_result.replace("%TYPE%", get_name_of_lesson_type(lesson['type']))
|
result += f"<i>Посилання</i>: {escaped_string_html(lesson['link'])}\n"
|
||||||
total_result = total_result.replace("%NAME_PREFIX%", custom_name_prefix)
|
|
||||||
|
|
||||||
return total_result + "\n"
|
if output_settings['comment'] and 'comment' in lesson:
|
||||||
|
result += f"<i>Примітка</i>: {escaped_string_html(lesson['comment'])}\n"
|
||||||
|
|
||||||
else:
|
return result
|
||||||
active_template = load_template(template, "single")
|
|
||||||
|
|
||||||
for i in ['name', 'teacher', 'link']:
|
|
||||||
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)
|
|
||||||
|
|
||||||
return active_template
|
|
||||||
|
|
||||||
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)
|
|
||||||
total_result = total_result.replace("%DATE%", human_readable_date)
|
|
||||||
|
|
||||||
for l in lesson:
|
|
||||||
active_template = load_template(template, "multiple")
|
|
||||||
|
|
||||||
for i in ['name', 'teacher', 'link']:
|
|
||||||
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)
|
|
||||||
|
|
||||||
total_result += active_template + "\n"
|
|
||||||
|
|
||||||
return total_result
|
|
||||||
|
|
||||||
|
|
||||||
def get_schedule_data_from(filename):
|
def get_schedule_data_from(filename):
|
||||||
@@ -269,15 +151,47 @@ def process_arguments(args, base_day):
|
|||||||
|
|
||||||
|
|
||||||
def get_lesson_description(schedule, reference_time, lesson_time, current_day, current_week, overrides={},
|
def get_lesson_description(schedule, reference_time, lesson_time, current_day, current_week, overrides={},
|
||||||
custom_name_prefix="Назва", template="legacy-vibrant", force_date_at_top=False):
|
custom_name_prefix="<b>Назва</b>", force_date_at_top=False):
|
||||||
lesson_record = schedule[lesson_time]
|
lesson_record = schedule[lesson_time]
|
||||||
|
|
||||||
lesson_start_datetime = datetime.fromtimestamp(reference_time + lesson_time)
|
lesson_start_datetime = datetime.fromtimestamp(reference_time + lesson_time)
|
||||||
lesson_end_datetime = datetime.fromtimestamp(reference_time + lesson_time + 5400)
|
lesson_end_datetime = datetime.fromtimestamp(reference_time + lesson_time + 5400)
|
||||||
|
|
||||||
|
if lesson_record.__class__ == dict:
|
||||||
|
if force_date_at_top:
|
||||||
|
user_defined_overrides = dict(overrides)
|
||||||
|
internal_overrides = dict(overrides)
|
||||||
|
internal_overrides['date'] = False
|
||||||
|
|
||||||
|
description = generate_lesson_description(lesson_record, lesson_start_datetime, lesson_end_datetime,
|
||||||
|
current_day,
|
||||||
|
current_week, overrides=internal_overrides)
|
||||||
|
|
||||||
|
if 'date' in user_defined_overrides and not user_defined_overrides['date']:
|
||||||
|
return description
|
||||||
|
else:
|
||||||
|
human_readable_date = get_human_readable_date(lesson_start_datetime, lesson_end_datetime,
|
||||||
|
current_day, current_week)
|
||||||
|
return f"<b><u>{human_readable_date.capitalize()}</u></b>:\n" + description
|
||||||
|
else:
|
||||||
return generate_lesson_description(lesson_record, lesson_start_datetime, lesson_end_datetime, current_day,
|
return generate_lesson_description(lesson_record, lesson_start_datetime, lesson_end_datetime, current_day,
|
||||||
current_week, overrides=overrides, custom_name_prefix=custom_name_prefix, template=template,
|
current_week, overrides=overrides)
|
||||||
force_date_at_top=force_date_at_top)
|
|
||||||
|
elif lesson_record.__class__ == list:
|
||||||
|
user_defined_overrides = dict(overrides)
|
||||||
|
internal_overrides = dict(overrides)
|
||||||
|
internal_overrides['date'] = False
|
||||||
|
|
||||||
|
descriptions = [generate_lesson_description(i, lesson_start_datetime, lesson_end_datetime, current_day,
|
||||||
|
current_week, overrides=internal_overrides,
|
||||||
|
custom_name_prefix=custom_name_prefix) for i in lesson_record]
|
||||||
|
|
||||||
|
if 'date' in user_defined_overrides and not user_defined_overrides['date']:
|
||||||
|
return "\n".join(descriptions)
|
||||||
|
else:
|
||||||
|
human_readable_date = get_human_readable_date(lesson_start_datetime, lesson_end_datetime,
|
||||||
|
current_day, current_week)
|
||||||
|
return f"<b><u>{human_readable_date.capitalize()}</u></b>:\n" + "\n".join(descriptions)
|
||||||
|
|
||||||
|
|
||||||
def process(message, path):
|
def process(message, path):
|
||||||
@@ -289,7 +203,7 @@ def process(message, path):
|
|||||||
# one printable symbol, so this is already protected
|
# one printable symbol, so this is already protected
|
||||||
base_command = full_command[0].lower()
|
base_command = full_command[0].lower()
|
||||||
|
|
||||||
if base_command not in ["!пара", "!пари", "!schedule-ctl"]:
|
if base_command not in ["!пара", "!пари"]:
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
global module_path
|
global module_path
|
||||||
@@ -309,18 +223,16 @@ def process(message, path):
|
|||||||
reference_time = int(current_time.strftime("%s")) - current_seconds
|
reference_time = int(current_time.strftime("%s")) - current_seconds
|
||||||
|
|
||||||
if base_command == "!пара":
|
if base_command == "!пара":
|
||||||
# easter egg
|
|
||||||
study_begin_ts = int(datetime(year=2023, month=9, day=4).strftime("%s"))
|
study_begin_ts = int(datetime(year=2023, month=9, day=4).strftime("%s"))
|
||||||
current_ts = int(datetime.now().strftime("%s"))
|
current_ts = int(datetime.now().strftime("%s"))
|
||||||
|
|
||||||
if -3600*4 < study_begin_ts - current_ts < 0:
|
if -3600 * 4 < study_begin_ts - current_ts < 0:
|
||||||
return "Навчання от-от розпочнеться!", None
|
return "Навчання незабаром розпочнеться!", None
|
||||||
elif 0 <= study_begin_ts - current_ts < 1209600:
|
elif 0 <= study_begin_ts - current_ts < 1209600:
|
||||||
return f"До навчання залишилося {study_begin_ts - current_ts} секунд...", None
|
return f"До навчання залишилося {study_begin_ts - current_ts} секунд...", None
|
||||||
elif study_begin_ts - current_ts >= 1209600:
|
elif study_begin_ts - current_ts >= 1209600:
|
||||||
return "Ви маєте законне право відпочити, пари почнуться не скоро", None
|
return "Ви маєте законне право відпочити, пари почнуться не скоро", None
|
||||||
|
|
||||||
# actual lesson finding code
|
|
||||||
upcoming_lessons = [timestamp for timestamp in schedule if timestamp > current_seconds - 5400]
|
upcoming_lessons = [timestamp for timestamp in schedule if timestamp > current_seconds - 5400]
|
||||||
|
|
||||||
if len(upcoming_lessons) > 0:
|
if len(upcoming_lessons) > 0:
|
||||||
@@ -328,34 +240,8 @@ def process(message, path):
|
|||||||
else:
|
else:
|
||||||
closest_lesson_time = min(schedule)
|
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,
|
return get_lesson_description(schedule, reference_time, closest_lesson_time, current_day,
|
||||||
current_week, custom_name_prefix="Актуальна пара", template=output_style_preference), "HTML"
|
current_week, custom_name_prefix="<b>Актуальна пара</b>"), "HTML"
|
||||||
|
|
||||||
elif base_command == "!пари":
|
elif base_command == "!пари":
|
||||||
base_day = current_week * 7 + current_day
|
base_day = current_week * 7 + current_day
|
||||||
@@ -369,52 +255,10 @@ def process(message, path):
|
|||||||
|
|
||||||
lesson_list = [i for i in schedule if selected_day * 86400 <= i < (selected_day + 1) * 86400]
|
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,
|
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)
|
current_week, overrides=preferences,
|
||||||
|
custom_name_prefix="<b>Назва</b>", force_date_at_top=True)
|
||||||
for lesson_time in lesson_list]
|
for lesson_time in lesson_list]
|
||||||
|
|
||||||
return f"<b><u>Пари у {WEEKDAYS_ACCUSATIVE[selected_day % 7]}</u></b>:\n\n\n" + "\n".join(lesson_descriptions_list), "HTML"
|
return f"<b><u>Пари у {WEEKDAYS_ACCUSATIVE[selected_day % 7]}</u></b>:\n\n\n" + "\n\n".join(
|
||||||
|
lesson_descriptions_list), "HTML"
|
||||||
elif base_command == "!schedule-ctl" and len(full_command) >= 2:
|
|
||||||
if full_command[1] == "list":
|
|
||||||
prefs = get_all_preferences_by_id(message.from_user.id)
|
|
||||||
return "Ваші персональні налаштування:\n" + '\n'.join([f"- {k} = {v}" for k, v in prefs.items()]), "HTML"
|
|
||||||
|
|
||||||
elif full_command[1] == "set" and len(full_command) == 4:
|
|
||||||
prefs = get_all_preferences_by_id(message.from_user.id)
|
|
||||||
|
|
||||||
if full_command[2] in prefs:
|
|
||||||
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"
|
|
||||||
|
|
||||||
previous_value = prefs[full_command[2]]
|
|
||||||
prefs[full_command[2]] = full_command[3]
|
|
||||||
|
|
||||||
set_preference_by_id(message.from_user.id, full_command[2], full_command[3])
|
|
||||||
|
|
||||||
return f"Змінено значення {full_command[2]}: {previous_value} -> {full_command[3]}", "HTML"
|
|
||||||
else:
|
|
||||||
return f"Такого налаштування не існує; переглянути наявні налаштування можна за допомогою команди <u>!schedule-ctl list</u>", "HTML"
|
|
||||||
|
|
||||||
elif full_command[1] == "get" and len(full_command) == 3:
|
|
||||||
requested_preference = get_preference_by_id(message.from_user.id, full_command[2])
|
|
||||||
return f"Налаштування {full_command[2]} має значення {requested_preference}", "HTML"
|
|
||||||
|
|
||||||
elif full_command[1] == "clear" and len(full_command) == 3:
|
|
||||||
clear_preference_by_id(message.from_user.id, full_command[2])
|
|
||||||
return f"Очищено значення для налаштування {full_command[2]}, надалі для нього використовуватиметься стандартне значення", "HTML"
|
|
||||||
|
|
||||||
else:
|
|
||||||
return "Такої команди не існує (або був використаний помилковий синтаксис)", "HTML"
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
<b><u>%DATE%</u></b>:
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
<b>%NAME_PREFIX%</b>: %NAME% (%TYPE%)
|
|
||||||
<b>Викладач</b>: %TEACHER%
|
|
||||||
<b>Посилання</b>: %LINK%
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
<b>%NAME_PREFIX%</b>: %NAME% (%TYPE%)
|
|
||||||
<b>Дата</b>: %DATE%
|
|
||||||
<b>Викладач</b>: %TEACHER%
|
|
||||||
<b>Посилання</b>: %LINK%
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<u>%DATE%</u>:
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
%NAME_PREFIX%: %NAME% (%TYPE%)
|
|
||||||
Викладач: %TEACHER%
|
|
||||||
Посилання: %LINK%
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
%NAME_PREFIX%: %NAME% (%TYPE%)
|
|
||||||
Дата: %DATE%
|
|
||||||
Викладач: %TEACHER%
|
|
||||||
Посилання: %LINK%
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<b><u>%DATE%</u></b>:
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
<b>%NAME%</b> (%TYPE%)
|
|
||||||
<i>Викладач</i>: %TEACHER%
|
|
||||||
<i>Посилання</i>: %LINK%
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
<b>%NAME%</b> (%TYPE%)
|
|
||||||
<i>Дата</i>: %DATE%
|
|
||||||
<i>Викладач</i>: %TEACHER%
|
|
||||||
<i>Посилання</i>: %LINK%
|
|
||||||
@@ -4,12 +4,13 @@ command_length = len(command)
|
|||||||
def escaped_string(unescaped_string):
|
def escaped_string(unescaped_string):
|
||||||
result_string = str(unescaped_string)
|
result_string = str(unescaped_string)
|
||||||
|
|
||||||
for i in ["<", ">"]:
|
for i in ["/", "<", ">"]:
|
||||||
result_string = result_string.replace(i, f"\\{i}")
|
result_string = result_string.replace(i, f"\\{i}")
|
||||||
|
|
||||||
return result_string
|
return result_string
|
||||||
|
|
||||||
if (command[0] in self.aliases) and (1 <= command_length <= 3):
|
if (command[0] in self.aliases) and (1 <= command_length <= 3):
|
||||||
|
try:
|
||||||
models = json.loads(readfile(self.path + "translate_models.json"))
|
models = json.loads(readfile(self.path + "translate_models.json"))
|
||||||
|
|
||||||
if command_length == 1:
|
if command_length == 1:
|
||||||
@@ -20,10 +21,7 @@ if (command[0] in self.aliases) and (1 <= command_length <= 3):
|
|||||||
if command_length == 3:
|
if command_length == 3:
|
||||||
text_to_decode = command[2]
|
text_to_decode = command[2]
|
||||||
else:
|
else:
|
||||||
if self.MESSAGE['reply_to_message'].caption:
|
text_to_decode = self.MESSAGE['reply_to_message']['text']
|
||||||
text_to_decode = self.MESSAGE['reply_to_message'].caption
|
|
||||||
elif self.MESSAGE['reply_to_message'].text:
|
|
||||||
text_to_decode = self.MESSAGE['reply_to_message'].text
|
|
||||||
|
|
||||||
decoded_text = text_to_decode
|
decoded_text = text_to_decode
|
||||||
if chosen_model not in models:
|
if chosen_model not in models:
|
||||||
@@ -37,3 +35,6 @@ if (command[0] in self.aliases) and (1 <= command_length <= 3):
|
|||||||
|
|
||||||
self.RESPONSE = f"<b><u>Результат</u></b>\n{escaped_string(decoded_text)}"
|
self.RESPONSE = f"<b><u>Результат</u></b>\n{escaped_string(decoded_text)}"
|
||||||
self.FORMAT = "HTML"
|
self.FORMAT = "HTML"
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[translit-decoder] Got exception: {e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user