From 9e890c9d7ca0a5df385f10b5484f3b5435445d1a Mon Sep 17 00:00:00 2001 From: ByteDice Date: Thu, 5 Mar 2026 15:33:58 +0100 Subject: [PATCH] last Rust LANG files migrations (only python left) --- data/lang/en.json | 31 +++++++++++++++++++--- data/lang/en_deprecated.json | 48 +++++++++++++++++----------------- src/cmds/reddit/add.rs | 10 +++---- src/cmds/reddit/approve.rs | 11 +++----- src/cmds/reddit/generic_fns.rs | 10 +++---- src/cmds/reddit/get.rs | 6 ++--- src/cmds/reddit/remove.rs | 6 ++--- src/cmds/reddit/shorturl.rs | 6 ++--- src/cmds/reddit/update.rs | 46 ++++++++++++++++---------------- src/cmds/reddit/vote.rs | 16 ++++++------ src/lang.rs | 5 ---- src/main.rs | 2 +- src/messages.rs | 18 +++++-------- 13 files changed, 114 insertions(+), 101 deletions(-) diff --git a/data/lang/en.json b/data/lang/en.json index 659abff..6dc31f5 100644 --- a/data/lang/en.json +++ b/data/lang/en.json @@ -13,6 +13,10 @@ "vote": "Vote", "unvote": "Un-vote" }, + "add": { + "success": "Added post with URL \"<{0}>\"!", + "approved": "Also approved it!" + }, "approve": { "success": "Successfully approved the post!", "disapprove": "Successfully disapproved the post!", @@ -27,19 +31,39 @@ "removed": "Successfully removed vote!", "mod": "Successfully voted (as moderator vote)!", "post_removed": "Couldn't [vote / un-vote] the post because the post has been removed!", - "remove_hasnt_voted": "Couldn't remove your vote: You haven't voted on this post yet!" + "remove_hasnt_voted": "Couldn't remove your vote: You haven't voted on this post yet!", + "already": "Couldn't cast a vote: You have already voted on this post!", + "error": "Failed to [vote / un-vote]: Unknown internal error." + }, + "update": { + "fetch": "\nFetching new posts & updating data file...", + "read": "✅\nReading messages in <#{1}>...", + "parse": "✅\nParsing messages to JSON...", + "add": "✅\nAdding new posts...", + "rm_dupe": "✅\nRemoving duplicate posts...", + "rm": "✅\nRemoving removed posts...", + "rm_old": "✅\nRemoving old posts (threshold: {1}d)...", + "editing": "✅\nEditing updated posts...", + "done": "✅\n## Done!" }, "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}" }, - "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." + "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.", + "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.", + "not_mod": "Permission denied: You are not a moderator of the subreddit(s) {0}", + "post_corrupted": "Post URL \"<{0}>\" not found: Post data is corrupted!\n-# Full details: Could not find key \"posts\" in data file \"re_data.json\"", + "shorturl": "ShortURL: <{0}>", + "shorturl_fail": "Couldn't convert to shortURL: Invalid Reddit URL format." }, "db": { "added_server": "Added your server to my database. Thanks for letting me steal it! (/s)", "corrupted_data": "Couldn't add your server to the database! The database is corrupted!", "server_404": "This server is not in the data!\n-# Hint: Run the command `/database AddServer` inside of a Discord server (requires administrator permission).", "wwrps_404": "Could not find `wwrps_channel` in data!\n-# Hint: Run `/database WWRPSChannel` in a channel (requires administrator permission).", + "bk_404": "Could not find `re_posts_channel` in data!\n-# Hint: Run `/database RedditChannel` in a (preferably read-only) channel (requires administrator permission).", "channel_bind": "Successfully added channel ID `{0}` to the database!", "not_in_guild": "I am not a part of that guild.", "saving_progress": "Saving data...", @@ -61,5 +85,6 @@ "whoami": "**Bot \"owner\":** {0}\n**BK moderator:** {1}", "mandatory_response": "Mandatory response message, please ignore.", "cmd_404": "No command \"{0}\" found!\nHint: Try `/help` without any arguments or `/help `" - } + }, + "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 index aedd63f..e84f7c5 100644 --- a/data/lang/en_deprecated.json +++ b/data/lang/en_deprecated.json @@ -16,31 +16,31 @@ //"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_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_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_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_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_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!", @@ -48,16 +48,16 @@ "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_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]", @@ -67,7 +67,7 @@ //"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!", + //"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!", diff --git a/src/cmds/reddit/add.rs b/src/cmds/reddit/add.rs index cc8e04c..4fb2317 100644 --- a/src/cmds/reddit/add.rs +++ b/src/cmds/reddit/add.rs @@ -5,7 +5,6 @@ use crate::messages::send_msg; use crate::cmds::reddit::get::get_post_from_data; use crate::{websocket::send_cmd_json, Context, Error}; use crate::cmds::reddit::generic_fns::{is_bk_mod_msg, send_embed_for_post, to_shorturl}; -use crate::lang; #[poise::command( slash_command, @@ -25,6 +24,7 @@ pub async fn cmd( let shorturl_u = to_shorturl(&url); let shorturl = &shorturl_u.unwrap_or(url.clone()); + let short_s = shorturl.to_string(); let a = approve.unwrap_or(false); let r = send_cmd_json("add_post_url", Some(json!([&shorturl, a, true])), true).await.unwrap(); @@ -47,12 +47,12 @@ pub async fn cmd( if let Some(bk_week) = reddit_data.get(POSTS_KEY) { if let Some(post) = bk_week.get(shorturl) { if post["removed"]["removed"].as_bool().unwrap() - { send_msg(ctx, lang!("dc_msg_re_post_unremove_success", &shorturl), true, true).await; } - else { send_msg(ctx, lang!("dc_msg_re_post_update_success", &shorturl), true, true).await; } + { send_msg(ctx, ctx.data().lang.get("dc.re.remove.unremove", &[short_s]), true, true).await; } + else { send_msg(ctx, ctx.data().lang.get("dc.re.update_post", &[short_s]), true, true).await; } } - else { send_msg(ctx, lang!("dc_msg_re_post_add_success", &shorturl), true, true).await; } + else { send_msg(ctx, ctx.data().lang.get("dc.re.add.success", &[short_s]), true, true).await; } - if a { send_msg(ctx, lang!("dc_msg_re_also_approved"), true, true).await; } + if a { send_msg(ctx, ctx.data().lang.get("dc.re.add.approved", &[]), true, true).await; } } if let Some(post) = get_post_from_data(ctx, &reddit_data, shorturl).await? { diff --git a/src/cmds/reddit/approve.rs b/src/cmds/reddit/approve.rs index 1f4c76e..3c8e6be 100644 --- a/src/cmds/reddit/approve.rs +++ b/src/cmds/reddit/approve.rs @@ -1,6 +1,6 @@ use serde_json::{json, Value}; -use crate::{Context, Error, db::{reddit::POSTS_KEY}, lang, messages::send_msg, cmds::reddit::generic_fns::{is_bk_mod_msg, to_shorturl}, websocket}; +use crate::{Context, Error, db::{reddit::POSTS_KEY}, messages::send_msg, cmds::reddit::generic_fns::{is_bk_mod_msg, to_shorturl}, websocket}; use super::generic_fns::send_embed_for_removed; @@ -41,17 +41,14 @@ async fn approve_cmd(ctx: Context<'_>, url: &str, reddit_data: &Value, approve: let r = websocket::send_cmd_json("set_approve_post", Some(json!([approve, &url])), true).await.unwrap(); if r["value"].as_bool().unwrap() { if approve { - send_msg(ctx, lang!("dc_msg_re_post_approve_success"), true, true).await; + send_msg(ctx, ctx.data().lang.get("dc.re.approve.success", &[]), true, true).await; } else { - send_msg(ctx, lang!("dc_msg_re_post_disapprove_success"), true, true).await; + send_msg(ctx, ctx.data().lang.get("dc.re.approve.disapprove", &[]), true, true).await; } } - else { - send_msg(ctx, lang!("dc_msg_err_trace", "`re_cmds -> approve.rs -> cmd() -> unwrap websocket result error`"), true, true).await; - } } else { - send_msg(ctx, lang!("dc_msg_re_post_404"), false, false).await; + send_msg(ctx, ctx.data().lang.get("dc.re.post_404", &[]), false, false).await; } } \ No newline at end of file diff --git a/src/cmds/reddit/generic_fns.rs b/src/cmds/reddit/generic_fns.rs index 46860d7..4395167 100644 --- a/src/cmds/reddit/generic_fns.rs +++ b/src/cmds/reddit/generic_fns.rs @@ -2,7 +2,7 @@ use poise::serenity_prelude::{self as serenity, ChannelId, ComponentInteraction, use regex::Regex; use serde_json::Value; -use crate::{Context, Data, Error, lang, messages::{EmbedOptions, JSON_TEXT_END, JSON_TEXT_START, decode_and_decompress_json, embed_from_options, make_post_embed, make_removed_embed, send_embed, send_msg}}; +use crate::{Context, Data, Error, messages::{EmbedOptions, JSON_TEXT_END, JSON_TEXT_START, decode_and_decompress_json, embed_from_options, make_post_embed, make_removed_embed, send_embed, send_msg}}; pub fn is_bk_mod(mod_list: Vec, uid: u64) -> bool { return mod_list.contains(&uid); @@ -13,7 +13,7 @@ pub async fn is_bk_mod_msg(ctx: Context<'_>) -> bool { if is_bk_mod(ctx.data().env_vars.reddit_mod_discord_ids.clone(), ctx.author().id.get()) { return true; } let sr = get_readable_subreddits(ctx.data()).await.unwrap(); - send_msg(ctx, lang!("dc_msg_re_permdeny_not_re_mod", sr), true, true).await; + send_msg(ctx, ctx.data().lang.get("dc.re.not_mod", &[sr]), true, true).await; return false } @@ -22,7 +22,7 @@ pub async fn is_bk_mod_serenity(ctx: &serenity::Context, data: &Data, author: &M if is_bk_mod(data.env_vars.reddit_mod_discord_ids.clone(), author.user.id.get()) { return true; } let sr = get_readable_subreddits(data).await.unwrap(); - serenity_send_msg(ctx, component, lang!("dc_msg_re_permdeny_not_re_mod", sr), true).await; + serenity_send_msg(ctx, component, data.lang.get("dc.re.not_mod", &[sr]), true).await; return true } @@ -55,7 +55,7 @@ pub fn to_shorturl(url: &str) -> Result { pub async fn send_embed_for_post(ctx: Context<'_>, post: Value, url: &str) -> Result<(), Error> { - send_embed(ctx, make_post_embed(&post, url, true), true).await; + send_embed(ctx, make_post_embed(&ctx.data().lang, &post, url, true), true).await; return Ok(()); } @@ -63,7 +63,7 @@ pub async fn send_embed_for_post(ctx: Context<'_>, post: Value, url: &str) -> Re pub async fn send_embed_for_removed(ctx: Context<'_>, url: &str, post: &Value) { send_embed( ctx, - make_removed_embed(post, url, true), + make_removed_embed(&ctx.data().lang, post, url, true), true ).await; } diff --git a/src/cmds/reddit/get.rs b/src/cmds/reddit/get.rs index 6112869..5103921 100644 --- a/src/cmds/reddit/get.rs +++ b/src/cmds/reddit/get.rs @@ -1,6 +1,6 @@ use serde_json::Value; -use crate::{Context, Error, db::{reddit::{self, POSTS_KEY}}, lang, messages::send_msg, cmds::reddit::generic_fns::{send_embed_for_post, to_shorturl}, rs_println}; +use crate::{Context, Error, db::{reddit::{self, POSTS_KEY}}, messages::send_msg, cmds::reddit::generic_fns::{send_embed_for_post, to_shorturl}, rs_println}; use super::generic_fns::send_embed_for_removed; @@ -42,11 +42,11 @@ pub async fn get_post_from_data(ctx: Context<'_>, reddit_data: &Value, url: &str return Ok(Some(post.clone())); } else { - send_msg(ctx, lang!("dc_msg_re_post_404", url), true, true).await; + send_msg(ctx, ctx.data().lang.get("dc.re.post_404", &[url.to_string()]), true, true).await; } } else { - send_msg(ctx, lang!("dc_msg_re_data_corrupted", url), true, true).await; + send_msg(ctx, ctx.data().lang.get("cd.re.post_corrupted", &[url.to_string()]), true, true).await; rs_println!("{}", serde_json::to_string_pretty(reddit_data)?); } return Ok(None); diff --git a/src/cmds/reddit/remove.rs b/src/cmds/reddit/remove.rs index 7e1f89e..5221f57 100644 --- a/src/cmds/reddit/remove.rs +++ b/src/cmds/reddit/remove.rs @@ -1,6 +1,6 @@ use serde_json::json; -use crate::{Context, Error, db::reddit, lang, messages::send_msg, cmds::reddit::{generic_fns::{is_bk_mod_msg, send_embed_for_removed, to_shorturl}, get::get_post_from_data}, websocket::send_cmd_json}; +use crate::{Context, Error, db::reddit, messages::send_msg, cmds::reddit::{generic_fns::{is_bk_mod_msg, send_embed_for_removed, to_shorturl}, get::get_post_from_data}, websocket::send_cmd_json}; #[poise::command( slash_command, @@ -27,13 +27,13 @@ pub async fn cmd( if r["value"].as_bool().unwrap() { send_msg( ctx, - lang!("dc_msg_re_post_remove_success", &shorturl), + ctx.data().lang.get("dc.re.remove.success", &[shorturl.to_string()]), true, true ).await; } else { - send_msg(ctx, lang!("dc_msg_re_post_404"), true, true).await; + send_msg(ctx, ctx.data().lang.get("dc.re.post_404", &[]), true, true).await; } reddit::update_data().await; diff --git a/src/cmds/reddit/shorturl.rs b/src/cmds/reddit/shorturl.rs index 4593f76..c52fac1 100644 --- a/src/cmds/reddit/shorturl.rs +++ b/src/cmds/reddit/shorturl.rs @@ -1,4 +1,4 @@ -use crate::{lang, messages::send_msg, cmds::reddit::generic_fns::to_shorturl, Context, Error}; +use crate::{messages::send_msg, cmds::reddit::generic_fns::to_shorturl, Context, Error}; #[poise::command( @@ -17,10 +17,10 @@ pub async fn cmd( let shorturl = to_shorturl(&url); if shorturl.is_ok() { - send_msg(ctx, lang!("dc_msg_shorturl", shorturl.unwrap()), true, true).await; + send_msg(ctx, ctx.data().lang.get("dc.re.shorturl", &[shorturl.unwrap()]), true, true).await; } else { - send_msg(ctx, lang!("dc_msg_failed_shorturl_conversion"), true, true).await; + send_msg(ctx, ctx.data().lang.get("dc.re.shorturl_fail", &[]), true, true).await; } return Ok(()); diff --git a/src/cmds/reddit/update.rs b/src/cmds/reddit/update.rs index 4e79c64..33a923e 100644 --- a/src/cmds/reddit/update.rs +++ b/src/cmds/reddit/update.rs @@ -3,7 +3,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; use poise::{serenity_prelude::{ChannelId, EditMessage, GetMessages, Http, Message, MessageId, UserId}, ReplyHandle}; use serde_json::{json, Map, Value}; -use crate::{Context, Error, db::{discord::contains_server, keys::DC_POSTS_CHANNEL_KEY, reddit::{self, POSTS_KEY}}, lang, messages::{edit_reply, embed_from_options, make_post_embed, make_removed_embed, send_embed, send_msg, trim_post_json}, cmds::reddit::generic_fns::embed_to_json, rs_println, websocket::send_cmd_json}; +use crate::{Context, Error, cmds::reddit::generic_fns::embed_to_json, db::{discord::contains_server, keys::DC_POSTS_CHANNEL_KEY, reddit::{self, POSTS_KEY}}, lang::Lang, messages::{edit_reply, embed_from_options, make_post_embed, make_removed_embed, send_embed, send_msg, trim_post_json}, rs_println, websocket::send_cmd_json}; #[poise::command( slash_command, @@ -34,7 +34,7 @@ pub async fn cmd( let mut p_text = "`/re_updatediscord`:".to_string(); let progress = send_msg(ctx, p_text.clone(), true, true).await.unwrap(); - p_text = update_progress(ctx, progress.clone(), p_text, lang!("dc_msg_update_fetch", "\n")).await; + p_text = update_progress(ctx, progress.clone(), p_text, ctx.data().lang.get("dc.re.update.fetch", &[])).await; let max_age_u = max_age.unwrap_or(8); let max_age_secs = max_age_u as u64 * (60 * 60 * 24); @@ -49,55 +49,55 @@ pub async fn cmd( let c_id_u = get_c_id(ctx).await; if c_id_u.is_none() { - send_msg(ctx, lang!("dc_msg_re_posts_channel_404"), true, true).await; + send_msg(ctx, ctx.data().lang.get("dc.db.bk_404", &[]), true, true).await; return Ok(()); } let c_id = c_id_u.unwrap(); // Reading messages - p_text = update_progress(ctx, progress.clone(), p_text.clone(), lang!("dc_msg_update_read", "✅\n", c_id)).await; + p_text = update_progress(ctx, progress.clone(), p_text.clone(), ctx.data().lang.get("dc.re.update.read", &[c_id.to_string()])).await; let msgs = read_msgs(http, ctx.framework().bot_id, c_id).await; // Parsing messages to JSON - p_text = update_progress(ctx, progress.clone(), p_text.clone(), lang!("dc_msg_update_parse", "✅\n")).await; + p_text = update_progress(ctx, progress.clone(), p_text.clone(), ctx.data().lang.get("dc.re.update.parse", &[])).await; let msgs_json = msgs_to_json(msgs, &r_data, max_age_secs).await; if ctx.data().args.dev { rs_println!("Posts changelog: {}", msgs_json); } // Adding new posts - p_text = update_progress(ctx, progress.clone(), p_text.clone(), lang!("dc_msg_update_add", "✅\n")).await; + p_text = update_progress(ctx, progress.clone(), p_text.clone(), ctx.data().lang.get("dc.re.update.add", &[])).await; let weekly_art = r_data[POSTS_KEY].as_object().unwrap(); add_posts(ctx, weekly_art, &msgs_json, max_age_secs, max_results_final).await; // Stop if only_add if only_add.unwrap_or(false) { - send_msg(ctx, lang!("dc_msg_update_done", "`/bk_week_update`\n## "), true, true).await; - update_progress(ctx, progress.clone(), p_text, lang!("dc_msg_update_done", "✅\n## ")).await; + send_msg(ctx, ctx.data().lang.get("dc.re.update.done", &[]), true, true).await; + update_progress(ctx, progress.clone(), p_text, ctx.data().lang.get("dc.re.update.done", &[])).await; return Ok(()); } // Removing duplicate posts - p_text = update_progress(ctx, progress.clone(), p_text.clone(), lang!("dc_msg_update_removing_dupe", "✅\n")).await; + p_text = update_progress(ctx, progress.clone(), p_text.clone(), ctx.data().lang.get("dc.re.update.rm_dupe", &[])).await; remove_dupes(http, c_id, &msgs_json).await; // Removing removed posts - p_text = update_progress(ctx, progress.clone(), p_text.clone(), lang!("dc_msg_update_removing", "✅\n")).await; - remove_posts(http, c_id, weekly_art, &msgs_json).await; + p_text = update_progress(ctx, progress.clone(), p_text.clone(), ctx.data().lang.get("dc.re.update.rm", &[])).await; + remove_posts(http, &ctx.data().lang, c_id, weekly_art, &msgs_json).await; // Removing old posts if max_age_u > 0 { - p_text = update_progress(ctx, progress.clone(), p_text.clone(), lang!("dc_msg_update_removing_old", "✅\n", max_age_u)).await; + p_text = update_progress(ctx, progress.clone(), p_text.clone(), ctx.data().lang.get("dc.re.update.rm_old", &[max_age_u.to_string()])).await; remove_old(http, c_id, &msgs_json).await; send_cmd_json("remove_old_posts", Some(json!([max_age_secs])), true).await; } // Editing updated posts - p_text = update_progress(ctx, progress.clone(), p_text.clone(), lang!("dc_msg_update_editing", "✅\n")).await; - edit_posts(http, c_id, weekly_art, &msgs_json).await; + p_text = update_progress(ctx, progress.clone(), p_text.clone(), ctx.data().lang.get("dc.re.update.editing", &[])).await; + edit_posts(http, &ctx.data().lang, c_id, weekly_art, &msgs_json).await; // Done - update_progress(ctx, progress.clone(), p_text, lang!("dc_msg_update_done", "✅\n## ")).await; - send_msg(ctx, lang!("dc_msg_update_done", "`/bk_week_update`\n## "), true, true).await; + update_progress(ctx, progress.clone(), p_text, ctx.data().lang.get("dc.re.update.done", &[])).await; + send_msg(ctx, ctx.data().lang.get("dc.re.update.parse", &[]), true, true).await; return Ok(()); } @@ -113,7 +113,7 @@ async fn update_progress(ctx: Context<'_>, p: ReplyHandle<'_>, t: String, added_ async fn get_c_id(ctx: Context<'_>) -> Option { if !contains_server(ctx.data(), ctx.guild_id().unwrap().into()).await { - send_msg(ctx, lang!("dc_msg_data_server_404"), true, true).await; + send_msg(ctx, ctx.data().lang.get("dc.db.server_404", &[]), true, true).await; return None; } @@ -256,31 +256,31 @@ async fn add_posts(ctx: Context<'_>, r_data: &Map, msgs_json: &Va if now - post_date > max_age && max_age > 0 { continue; } if r_data[url]["removed"]["removed"].as_bool().unwrap() { - send_embed(ctx, make_removed_embed(&r_data[url], url, false), false).await; + send_embed(ctx, make_removed_embed(&ctx.data().lang, &r_data[url], url, false), false).await; continue; } - send_embed(ctx, make_post_embed(&r_data[url], url, false), false).await; + send_embed(ctx, make_post_embed(&ctx.data().lang, &r_data[url], url, false), false).await; } } -async fn edit_posts(http: &Http, c_id: ChannelId, r_data: &Map, msgs_json: &Value) { +async fn edit_posts(http: &Http, lang: &Lang, c_id: ChannelId, r_data: &Map, msgs_json: &Value) { for (url, msg_id) in msgs_json["updated"].as_object().unwrap() { let mut msg = http.get_message(c_id, MessageId::new(msg_id.as_u64().unwrap())).await.unwrap(); let r = EditMessage::new() - .embeds(vec![embed_from_options(make_post_embed(&r_data[url], url, false))]); + .embeds(vec![embed_from_options(make_post_embed(lang, &r_data[url], url, false))]); let _ = msg.edit(http, r).await; } } -async fn remove_posts(http: &Http, c_id: ChannelId, r_data: &Map, msgs_json: &Value) { +async fn remove_posts(http: &Http, lang: &Lang, c_id: ChannelId, r_data: &Map, msgs_json: &Value) { for (url, msg_id) in msgs_json["removed"].as_object().unwrap() { let mut msg = http.get_message(c_id, MessageId::new(msg_id.as_u64().unwrap())).await.unwrap(); let r = EditMessage::new() - .embeds(vec![embed_from_options(make_removed_embed(&r_data[url], url, false))]); + .embeds(vec![embed_from_options(make_removed_embed(lang, &r_data[url], url, false))]); let _ = msg.edit(http, r).await; } diff --git a/src/cmds/reddit/vote.rs b/src/cmds/reddit/vote.rs index 9b6d8e5..1ffb937 100644 --- a/src/cmds/reddit/vote.rs +++ b/src/cmds/reddit/vote.rs @@ -1,6 +1,6 @@ use serde_json::json; -use crate::{Context, Error, db::reddit::{self, POSTS_KEY}, lang, messages::send_msg, cmds::reddit::generic_fns::{is_bk_mod, send_embed_for_removed, to_shorturl}, websocket::send_cmd_json}; +use crate::{Context, Error, db::reddit::{self, POSTS_KEY}, messages::send_msg, cmds::reddit::generic_fns::{is_bk_mod, send_embed_for_removed, to_shorturl}, websocket::send_cmd_json}; #[poise::command( slash_command, @@ -26,7 +26,7 @@ pub async fn cmd( let shorturl = &shorturl_u.unwrap_or(url.clone()); if post_data.get(shorturl).is_none() { - send_msg(ctx, lang!("dc_msg_re_post_404"), false, false).await; + send_msg(ctx, ctx.data().lang.get("dc.re.post_404", &[]), false, false).await; return Ok(()); } if post_data[&shorturl]["removed"]["removed"].as_bool().unwrap() { @@ -42,11 +42,11 @@ pub async fn cmd( let voters = if is_mod { mod_voters } else { voters_dc }; if voters.contains(&json!(uid)) && !unw_vote { - send_msg(ctx, lang!("dc_msg_re_already_voted"), true, true).await; + send_msg(ctx, ctx.data().lang.get("dc.re.vote.already", &[]), true, true).await; return Ok(()); } else if !voters.contains(&json!(uid)) && unw_vote { - send_msg(ctx, lang!("dc_msg_re_vote_remove_havent"), true, true).await; + send_msg(ctx, ctx.data().lang.get("dc.re.vote.remove_hasnt_voted", &[]), true, true).await; return Ok(()); } @@ -54,13 +54,13 @@ pub async fn cmd( let unw_r = r["value"].as_bool().unwrap(); if unw_r && !unw_vote && is_mod - { send_msg(ctx, lang!("dc_msg_re_vote_mod_success"), true, true).await; } + { send_msg(ctx, ctx.data().lang.get("dc.re.vote.mod", &[]), true, true).await; } else if unw_r && !unw_vote && !is_mod - { send_msg(ctx, lang!("dc_msg_re_vote_success"), true, true).await; } + { send_msg(ctx, ctx.data().lang.get("dc.re.vote.success", &[]), true, true).await; } else if unw_r && unw_vote - { send_msg(ctx, lang!("dc_msg_re_vote_remove_success"), true, true).await; } + { send_msg(ctx, ctx.data().lang.get("dc.re.vote.remove", &[]), true, true).await; } else - { send_msg(ctx, lang!("dc_msg_re_vote_err"), true, true).await; } + { send_msg(ctx, ctx.data().lang.get("dc.re.vote.error", &[]), true, true).await; } return Ok(()); } \ No newline at end of file diff --git a/src/lang.rs b/src/lang.rs index 346a895..fc6a4a1 100644 --- a/src/lang.rs +++ b/src/lang.rs @@ -19,11 +19,6 @@ impl From for Lang { impl Lang { - pub fn new() -> Self { - return Lang { data: Value::Null }; - } - - pub fn from_file(filepath: PathBuf) -> Result { if !filepath.exists() { return Err(Error::from("LANG filepath not found!")); } diff --git a/src/main.rs b/src/main.rs index 4f8c60e..36aa126 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,7 +48,7 @@ async fn main() { rs_println!("Generating and/or fetching data and config..."); let data = gen_data(args, env_vars).await; - rs_println!("[IMPORTANT] The below message is a test message, it should be written in the language you've selected\nTest message: {}", data.lang.get("log_lang_load_success", &[])); + rs_println!("[IMPORTANT] The below message is a test message, it should be written in the language you've selected\nTest message: {}", data.lang.get("lang_load", &[])); // We start this here cuz we have all the data that we need if data.args.py && !data.args.rs { diff --git a/src/messages.rs b/src/messages.rs index d7c34b6..12b97b4 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -1,6 +1,5 @@ use std::io::{Read, Write}; -use crate::db::bot_data::Data; use crate::Context; use crate::lang::Lang; @@ -11,7 +10,7 @@ use flate2::write::ZlibEncoder; use flate2::Compression; use poise::serenity_prelude::json::Value; use poise::{serenity_prelude::CreateMessage, CreateReply, ReplyHandle}; -use poise::serenity_prelude::{ChannelId, Color, CreateActionRow, CreateButton, CreateEmbed, CreateEmbedAuthor, EditMessage, Http, Message, ReactionType, Timestamp, UserId}; +use poise::serenity_prelude::{ChannelId, Color, CreateActionRow, CreateButton, CreateEmbed, CreateEmbedAuthor, Http, Message, ReactionType, Timestamp, UserId}; use serde_json::json; @@ -88,7 +87,6 @@ pub async fn send_msg( } -#[allow(dead_code)] pub async fn http_send_msg( http: &Http, c_id: ChannelId, @@ -136,8 +134,7 @@ pub async fn send_embed( } -#[allow(dead_code)] -pub async fn http_send_embed( +/* pub async fn http_send_embed( http: &Http, c_id: ChannelId, options: EmbedOptions @@ -153,7 +150,7 @@ pub async fn http_send_embed( let msg = c_id.send_message(http, r).await; return msg.ok(); -} +} */ pub fn embed_from_options(options: EmbedOptions) -> CreateEmbed { @@ -190,17 +187,16 @@ pub async fn edit_reply( } -#[allow(dead_code)] -pub async fn http_edit_msg( +/* pub async fn http_edit_msg( http: &Http, mut msg: Message, new_msg: EditMessage ) { let _ = msg.edit(http, new_msg).await; -} +} */ -pub async fn send_dm(msg: String, data: &Data) { +/*pub async fn send_dm(msg: String, data: &Data) { let http = Http::new(&data.env_vars.token); let c_msg = CreateMessage::new().content(msg); @@ -210,7 +206,7 @@ pub async fn send_dm(msg: String, data: &Data) { let user = UserId::new(uid); let _ = user.dm(http.as_ref(), c_msg.clone()).await; } -} +}*/