From 9e17b7db7b4295de0fc3dc9562d28930815a9573 Mon Sep 17 00:00:00 2001 From: ByteDice Date: Fri, 6 Mar 2026 12:50:54 +0100 Subject: [PATCH] all lang has been replaced --- data/lang/en.json | 10 ++++- data/lang/en_deprecated.json | 78 ------------------------------------ src/messages.rs | 2 +- src/python/macros.py | 21 +++++++--- src/python/main.py | 2 +- src/python/py_cmds.py | 10 ++--- 6 files changed, 32 insertions(+), 91 deletions(-) delete mode 100644 data/lang/en_deprecated.json diff --git a/data/lang/en.json b/data/lang/en.json index 6dc31f5..b58d534 100644 --- a/data/lang/en.json +++ b/data/lang/en.json @@ -48,7 +48,8 @@ }, "embed": { "post": "Spoilers and vote length anonymizer for fair review!\n## Post Data:\n**Subreddit:** {0}\n**Post upvotes:** ||`{1:>6}`||\n**Moderator votes:** ||`{2:>6}`||\n**Media type:** `{3}`\n## Listing Data:\n**Added by:** human: {4} | bot: {5}\n**Approved:** {6}", - "post_removed": "## Removed by `{0}`\n**Reason:** {1}" + "post_removed": "## Removed by `{0}`\n**Reason:** {1}", + "removed_square_brackets": "[REMOVED] {0}" }, "update_post": "Updated post with URL \"<{0}>\"!", "help_404": "Reddit help file not found, someone likely deleted it.\n-# Hint: You can find the official help text at https://github.com/ByteDice/ByteDiceAssistant in `re_help.md`.\n**CAUTION:** The official help file may contain incorrect information if you're not using the official bot by Byte Dice.", @@ -86,5 +87,12 @@ "mandatory_response": "Mandatory response message, please ignore.", "cmd_404": "No command \"{0}\" found!\nHint: Try `/help` without any arguments or `/help `" }, + "re": { + "suffix": "^(I am not an AI, I am just a bot. This action was performed automatically by the way. You can report bugs and view my source code [here](https://github.com/ByteDice/ByteDiceAssistant)!)", + "add": "Successfully added your post to the weekly art submissions! Thank you for participating!", + "exists": "Couldn't add this post to the submissions! Luckily, it's already there! Thank you for participating!", + "mod_add": "[MOD ACTION] Successfully added this post to the weekly art submissions!", + "mod_unremove": "[MOD ACTION] Successfully un-removed this post from the weekly art submissions!" + }, "lang_load": "Successfully loaded the english language file!" } \ No newline at end of file diff --git a/data/lang/en_deprecated.json b/data/lang/en_deprecated.json deleted file mode 100644 index e84f7c5..0000000 --- a/data/lang/en_deprecated.json +++ /dev/null @@ -1,78 +0,0 @@ -{ - //"dc_btn_approve": "Approve", - //"dc_btn_remove": "Remove", - //"dc_btn_unapprove": "Disapprove", - //"dc_btn_unremove": "Restore", - //"dc_btn_unvote": "Un-vote", - //"dc_btn_vote": "Vote", - //"dc_msg_8-ball_answer": "**8-ball Question:** {0}\n**Answer:** {1}", - //"dc_msg_add_to_data": "Added your server to my data! Thanks for letting me steal it! (/s)", - //"dc_msg_bound_channel": "Successfully added channel ID `{0}` to the database!", - //"dc_msg_cmd_404": "No command \"{0}\" found!\nHint: Try `/help` without any arguments or `/help `", - //"dc_msg_corrupted_data": "Oopsies `(。>\\\\<)`. It looks like my data i-is \\**sob*\\*... c-corrupted!", - //"dc_msg_data_server_404": "This server is not in the data!\n Hint: Run the command `/database AddServer` inside of a Discord server (requires administrator permission).", - //"dc_msg_dm_python_err_socket": "Unknown internal Python error occurred: Websocket response error", - //"dc_msg_dm_python_err": "Unknown internal Python Error:\n```\n{0}\n```", - //"dc_msg_embed_default_embed_desc": "Default english embed description.", - //"dc_msg_embed_re_post": "Spoilers and vote length anonymizer for fair review!\n## Post Data:\n**Subreddit:** {0}\n**Post upvotes:** ||`{1:>6}`||\n**Moderator votes:** ||`{2:>6}`||\n**Media type:** `{3}`\n## Listing Data:\n**Added by:** human: {4} | bot: {5}\n**Approved:** {6}", - //"dc_msg_embed_re_removed": "## Removed by `{0}`\n**Reason:** {1}", - //"dc_msg_err_trace": "Unknown error!\nError trace: {0}", - //"dc_msg_failed_shorturl_conversion": "Couldn't convert to shortURL: Invalid Reddit URL format.", - //"dc_msg_mandatory_response": "Mandatory response message, please ignore.", - //"dc_msg_no_perms": "Missing permission in that server: {0}", - //"dc_msg_not_in_guild": "I am not a part of that guild.", - //"dc_msg_owner_data_save_complete": "Saving data... Done!", - //"dc_msg_owner_data_save": "Saving data...", - //"dc_msg_owner_shutdown": "Shutting down...", - //"dc_msg_owner_shutdown_failed_confirmation": "Failed to shut down: Invalid confirmation.", - //"dc_msg_re_already_voted": "Couldn't cast a vote: You have already voted on this post!", - //"dc_msg_re_also_approved": "Also approved it!", - //"dc_msg_re_data_corrupted": "Post URL \"<{0}>\" not found: Post data is corrupted!\n Full details: Could not find key \"posts\" in data file \"re_data.json\"", - "dc_msg_re_help_removed": "Reddit help file not found, someone likely deleted it.\n Hint: You can find the official help text at https://github.com/ByteDice/ByteDiceAssistant in `re_help.md`.\n**CAUTION:** The official help file may contain incorrect information if you're not using the official bot by Byte Dice.", - //"dc_msg_re_permdeny_not_re_mod": "Permission denied: You are not a moderator of the subreddit(s) {0}", - //"dc_msg_re_post_404": "Post URL \"<{0}>\" not found: Post doesn't exist in the data!\n Hint: Run the command `/re_addpost [URL]` in a Discord channel or `u/ByteDiceAssistant add_post` in a Reddit post.", - //"dc_msg_re_post_add_success": "Added post with URL \"<{0}>\"!", - //"dc_msg_re_post_approve_remove": "Couldn't approve the post because it has been removed!", - //"dc_msg_re_post_approve_success": "Successfully approved the post!", - //"dc_msg_re_post_disapprove_success": "Successfully disapproved the post!", - //"dc_msg_re_post_remove_success": "Successfully removed post with URL \"<{0}>\"!", - //"dc_msg_re_post_unremove_success": "Successfully restored post with URL \"<{0}>\"!", - //"dc_msg_re_post_update_success": "Updated post with URL \"<{0}>\"!", - //"dc_msg_re_post_vote_removed_post": "Couldn't [vote / un-vote] the post because it has been removed!", - "dc_msg_re_posts_channel_404": "Could not find `re_posts_channel` in data!\nHint: Run `/database RedditChannel` in a (preferably read-only) channel (requires administrator permission).", - //"dc_msg_re_vote_err": "Failed to [vote / un-vote]: Unknown internal error.", - //"dc_msg_re_vote_mod_success": "Successfully voted (as moderator vote)!", - //"dc_msg_re_vote_remove_havent": "Couldn't remove your vote: You haven't voted on this post yet!", - //"dc_msg_re_vote_remove_success": "Successfully removed vote!", - //"dc_msg_re_vote_success": "Successfully voted!", - "dc_msg_reload_cfg_python_fail": "Failed to reload configs: Failed-type response from Python.", - "dc_msg_reload_cfg_success": "Successfully reloaded the configs!\nNew configs:\n```\n{0}\n```", - "dc_msg_removed_square_brackets": "[REMOVED] {0}", - //"dc_msg_shorturl": "ShortURL: <{0}>", - //"dc_msg_update_add": "{0}Adding new posts...", - //"dc_msg_update_done": "{0}Done!", - //"dc_msg_update_editing": "{0}Editing updated posts...", - //"dc_msg_update_fetch": "{0}Fetching new posts & updating data file...", - //"dc_msg_update_parse": "{0}Parsing messages to JSON...", - //"dc_msg_update_read": "{0}Reading messages in <#{1}>...", - //"dc_msg_update_removing_dupe": "{0}Removing duplicate posts...", - //"dc_msg_update_removing_old": "{0}Removing old posts (threshold: {1}d)...", - //"dc_msg_update_removing": "{0}Removing removed posts...", - //"dc_msg_whoami": "**Bot \"owner\":** {0}\n**BK moderator:** {1}", - //"dc_msg_wwrps_already_submitted": "You can't compete against yourself! Please wait until another player has submitted their RPS.", - //"dc_msg_wwrps_anon": "[Anonymous]", - //"dc_msg_wwrps_draw": "DRAW", - //"dc_msg_wwrps_fight": "### {0} (P1) vs {1} (P2)...\n## {2}\n**P1:** {3}\n**P2:** {4}", - //"dc_msg_wwrps_not_in_data": "Could not find `wwrps_channel` in data!\nHint: Run `/database WWRPSChannel` in a channel (requires administrator permission).", - //"dc_msg_wwrps_left_win": "P1 WINS", - //"dc_msg_wwrps_right_win": "P2 WINS", - //"dc_msg_wwrps_submitting": "Submitting your RPS... Please wait for another contestant to compete against you.", - //"log_lang_load_success": "Successfully loaded the english language file!", - //"none": "None", - "py_re_response_suffix": "^(I am not an AI, I am just a bot. This action was performed automatically by the way. You can report bugs and view my source code [here](https://github.com/ByteDice/ByteDiceAssistant)!)", - "py_re_response_weekly_add": "Successfully added your post to the weekly art submissions! Thank you for participating!", - "py_re_response_weekly_exists": "Couldn't add this post to the submissions! Luckily, it's already there! Thank you for participating!", - "py_re_response_weekly_mod_add": "[MOD ACTION] Successfully added this post to the weekly art submissions!", - "py_re_response_weekly_mod_unremove": "[MOD ACTION] Successfully un-removed this post from the weekly art submissions!", - //"success": "Success!" -} \ No newline at end of file diff --git a/src/messages.rs b/src/messages.rs index 12b97b4..c2500e9 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -283,7 +283,7 @@ pub fn make_removed_embed(lang: &Lang, post_data: &Value, url: &str, ephemeral: let json_encoded = trim_compress_and_encode_json(post_data); return EmbedOptions { - title: Some(lang.get("dc_msg_removed_square_brackets", &[post_data["post_data"]["title"].clone().to_string()])), + title: Some(lang.get("dc.re.embed.removed_square_brackets", &[post_data["post_data"]["title"].clone().to_string()])), desc: format!("{}\n\n{}{}{}", desc, JSON_TEXT_START, json_encoded, JSON_TEXT_END), col: Some(REMOVED_DC_COL), url: Some(url.to_string()), diff --git a/src/python/macros.py b/src/python/macros.py index 61bc398..911f8ec 100644 --- a/src/python/macros.py +++ b/src/python/macros.py @@ -28,11 +28,22 @@ def py_error(*args: str): def lang(k: str) -> str: - if G_LANG == {}: - py_error("Language must be initialized before use!") - t = G_LANG.get(k) - if t is None: py_error(f"Key not found in language \"{G_LANG_NAME}\": {k}") - return str(t) + return lang_from_arr(k.split(".")) + + +def lang_from_arr(path: list[str]) -> str: + if G_LANG == {}: py_error("Language must be initialized before use!") + + str_path = ".".join(path) + search = G_LANG + + for i in path: + r = search.get(i) # type: ignore + if r is None: return str_path + elif r is str: return str(r) + else: search = r # type: ignore + + return str_path def init_lang(lang_name: str): diff --git a/src/python/main.py b/src/python/main.py index 8a91ec6..6c66b9f 100644 --- a/src/python/main.py +++ b/src/python/main.py @@ -19,7 +19,7 @@ async def main(): await bot.set_args(args) # type: ignore py_print("Fetching language file...") init_lang(lang_name) # type: ignore - py_print(f"[IMPORTANT] The below message is a test message, it should be written in the language you've selected\nTest message: {lang('log_lang_load_success')}") + py_print(f"[IMPORTANT] The below message is a test message, it should be written in the language you've selected\nTest message: {lang('lang_load')}") except NameError: py_print("No command args or language name found from Rust. Don't worry though, we have backup in place.") init_lang("en") diff --git a/src/python/py_cmds.py b/src/python/py_cmds.py index d087396..5331583 100644 --- a/src/python/py_cmds.py +++ b/src/python/py_cmds.py @@ -69,18 +69,18 @@ async def bk_week_add(mention: models.Comment, bot: botPy.Bot): bd = bot.data[botPy.RE_DATA_POSTS] if short_url not in bd: - if not is_mod: r = lang("py_re_response_weekly_add") - if is_mod: r = lang("py_re_response_weekly_mod_add") + if not is_mod: r = lang("re.add") + if is_mod: r = lang("re.mod_add") else: if bd[short_url]["removed"]["removed"] and is_mod: - r = lang("py_re_response_weekly_mod_unremove") + r = lang("re.mod_unremove") elif not bd[short_url]["removed"]["removed"]: - r = lang("py_re_response_weekly_exists") + r = lang("re.exists") await posts.add_post_url(bot, short_url) if r != "": - await mention.reply(r + "\n\n" + lang("py_re_response_suffix")) + await mention.reply(r + "\n\n" + lang("re.suffix")) if bot.args["dev"]: py_print("Responded to mention.") elif bot.args["dev"]: py_print("Response is empty.") await mention.mark_read() \ No newline at end of file