removed different language logs & updated language key names
This commit is contained in:
+18
-15
@@ -6,7 +6,7 @@ use crate::data::{dc_add_server, get_mutex_data, read_cfg_data};
|
||||
use crate::re_cmds::generic_fns::to_shorturl;
|
||||
use crate::websocket::send_cmd_json;
|
||||
use crate::{data, lang, Context, Data, Error};
|
||||
use crate::messages::{edit_reply, send_embed, send_msg, Author, EmbedOptions, MANDATORY_MSG};
|
||||
use crate::messages::{edit_reply, send_embed, send_msg, Author, EmbedOptions};
|
||||
|
||||
use poise::serenity_prelude::{OnlineStatus, Timestamp};
|
||||
use poise::Command;
|
||||
@@ -15,6 +15,9 @@ use serde_json::json;
|
||||
use tokio::fs;
|
||||
|
||||
|
||||
// TODO: separate to multiple files
|
||||
|
||||
|
||||
#[derive(poise::ChoiceParameter, PartialEq)]
|
||||
enum HelpOptions {
|
||||
Admin,
|
||||
@@ -63,19 +66,19 @@ pub async fn stop(
|
||||
|| confirmation.unwrap_or_default().to_lowercase() == "i want to stop the bot now";
|
||||
|
||||
if should_stop {
|
||||
let msg = send_msg(ctx, lang!("data_save_progress"), true, true).await.unwrap();
|
||||
let msg = send_msg(ctx, lang!("dc_msg_owner_data_save"), true, true).await.unwrap();
|
||||
data::write_dc_data(ctx.data()).await;
|
||||
data::write_re_data().await;
|
||||
send_cmd_json("stop_praw", None).await;
|
||||
|
||||
edit_reply(ctx, msg, lang!("data_save_complete")).await;
|
||||
edit_reply(ctx, msg, lang!("dc_msg_owner_data_save_complete")).await;
|
||||
ctx.serenity_context().set_presence(None, OnlineStatus::Invisible);
|
||||
ctx.framework().shard_manager.shutdown_all().await;
|
||||
|
||||
process::exit(0);
|
||||
}
|
||||
else {
|
||||
send_msg(ctx, lang!("invalid_confirm_shutdown"), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_owner_shutdown_failed_confirmation"), true, true).await;
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
@@ -124,7 +127,7 @@ pub async fn embed(
|
||||
).await;
|
||||
|
||||
if !reply_unwrap {
|
||||
send_msg(ctx, MANDATORY_MSG.to_string(), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_mandatory_response"), true, true).await;
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
@@ -146,7 +149,7 @@ pub async fn send(
|
||||
) -> Result<(), Error>
|
||||
{
|
||||
send_msg(ctx, msg.replace("\\n", "\n"), false, false).await;
|
||||
send_msg(ctx, MANDATORY_MSG.to_string(), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_mandatory_response"), true, true).await;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -171,7 +174,7 @@ pub async fn eight_ball(
|
||||
|
||||
send_msg(
|
||||
ctx,
|
||||
lang!("8-ball_answer", question, rand_item.unwrap()),
|
||||
lang!("dc_msg_8-ball_answer", question, rand_item.unwrap()),
|
||||
true,
|
||||
true
|
||||
).await;
|
||||
@@ -194,10 +197,10 @@ pub async fn re_shorturl(
|
||||
let shorturl = to_shorturl(&url);
|
||||
|
||||
if shorturl.is_ok() {
|
||||
send_msg(ctx, lang!("shorturl", shorturl.unwrap()), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_shorturl", shorturl.unwrap()), true, true).await;
|
||||
}
|
||||
else {
|
||||
send_msg(ctx, lang!("couldnt_shorturl"), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_failed_shorturl_conversion"), true, true).await;
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
@@ -220,10 +223,10 @@ pub async fn add_server(
|
||||
let r = dc_add_server(ctx.data(), ctx.guild_id().unwrap().into()).await;
|
||||
|
||||
if r.is_ok() {
|
||||
send_msg(ctx, lang!("add_to_data"), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_added_to_data"), true, true).await;
|
||||
}
|
||||
else {
|
||||
send_msg(ctx, lang!("corrupted_data"), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_corrupted_data"), true, true).await;
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
@@ -250,14 +253,14 @@ pub async fn reload_cfg(
|
||||
if r.is_some() && r.unwrap()["value"].as_bool().unwrap() {
|
||||
send_msg(
|
||||
ctx,
|
||||
lang!("reload_config_success", serde_json::to_string_pretty(&d).unwrap()),
|
||||
lang!("dc_msg_reload_cfg_success", serde_json::to_string_pretty(&d).unwrap()),
|
||||
true,
|
||||
true
|
||||
).await;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
send_msg(ctx, lang!("reload_config_python_fail"), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_reload_cfg_python_fail"), true, true).await;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -329,7 +332,7 @@ async fn send_single_help(ctx: Context<'_>, mut cmd_name: String) {
|
||||
if cmd.is_none() {
|
||||
send_msg(
|
||||
ctx,
|
||||
lang!("cmd_404", cmd_name),
|
||||
lang!("dc_msg_cmd_404", cmd_name),
|
||||
true,
|
||||
true
|
||||
).await;
|
||||
@@ -355,7 +358,7 @@ async fn send_category_help(ctx: Context<'_>, category: HelpOptions) {
|
||||
|
||||
async fn send_bk_week_help_re(ctx: Context<'_>) {
|
||||
let t: String = fs::read_to_string("./bk_week_help_re.md").await
|
||||
.unwrap_or(lang!("help_text_removed"));
|
||||
.unwrap_or(lang!("dc_msg_re_help_removed"));
|
||||
|
||||
send_msg(ctx, t, true, true).await;
|
||||
}
|
||||
|
||||
+10
-11
@@ -4,7 +4,7 @@ use std::path::Path;
|
||||
use serde_json::{self, Value, json};
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use crate::{lang, rs_println, Data, Error, BK_WEEK, LANG};
|
||||
use crate::{errln, rs_println, Data, Error, BK_WEEK, LANG};
|
||||
use crate::websocket::send_cmd_json;
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ static DATA_PATH_LANG: &str = "./data/lang/";
|
||||
pub async fn read_dc_data(data: &Data, wipe: bool) {
|
||||
if !Path::new(DATA_PATH_DC).exists() || wipe {
|
||||
rs_println!(
|
||||
"{}",
|
||||
lang!("creating_data_file", if !wipe { lang!("dc_data_404") } else { lang!("dc_data_wipe") })
|
||||
"{} creating new from preset...",
|
||||
if !wipe { "discord_data.json not found," } else { "[WIPE] (discord_data.json)" }
|
||||
);
|
||||
generate_dc_data();
|
||||
}
|
||||
@@ -71,8 +71,8 @@ pub async fn write_dc_data(data: &Data) {
|
||||
pub async fn read_re_data(data: &Data, wipe: bool) {
|
||||
if !Path::new(DATA_PATH_RE).exists() || wipe {
|
||||
rs_println!(
|
||||
"{}",
|
||||
lang!("creating_data_file", if !wipe { lang!("re_data_404") } else { lang!("re_data_wipe") })
|
||||
"{} creating new from preset...",
|
||||
if !wipe { "reddit_data.json not found," } else { "[WIPE] (reddit_data.json)" }
|
||||
);
|
||||
generate_re_data();
|
||||
}
|
||||
@@ -114,8 +114,8 @@ pub async fn write_re_data() {
|
||||
pub async fn read_cfg_data(data: &Data, wipe: bool) {
|
||||
if !Path::new(DATA_PATH_CFG).exists() || wipe {
|
||||
rs_println!(
|
||||
"{}",
|
||||
lang!("creating_data_file", if !wipe { lang!("cfg_data_404") } else { lang!("cfg_data_wipe") })
|
||||
"{} creating new from preset...",
|
||||
if !wipe { "cfg.json not found," } else { "[WIPE] (cfg.json)" }
|
||||
);
|
||||
generate_cfg_data();
|
||||
}
|
||||
@@ -202,11 +202,10 @@ pub fn load_lang_data(lang: String) {
|
||||
let full_path = format!("{}{}.json", DATA_PATH_LANG, lang);
|
||||
|
||||
if !Path::new(&full_path).exists() {
|
||||
rs_println!(
|
||||
"{}",
|
||||
lang!("creating_data_file", lang!("cfg_data_404", lang))
|
||||
errln!(
|
||||
"File for language \"{0}\" ({0}.json) not found!\n Hint: You can download official language files at https://github.com/ByteDice/ByteDiceAssistant in the data/langs/... folder",
|
||||
lang
|
||||
);
|
||||
generate_cfg_data();
|
||||
}
|
||||
|
||||
let str_data = fs::read_to_string(full_path).unwrap();
|
||||
|
||||
+4
-7
@@ -1,4 +1,4 @@
|
||||
use crate::{lang, rs_println, Data, Error};
|
||||
use crate::{rs_println, Data, Error};
|
||||
|
||||
use poise::serenity_prelude::{self as serenity, ActivityData};
|
||||
|
||||
@@ -14,12 +14,9 @@ pub fn event_handler<'a>(
|
||||
Box::pin(async move {
|
||||
if let serenity::FullEvent::Ready { data_about_bot } = event {
|
||||
rs_println!(
|
||||
"{}",
|
||||
lang!(
|
||||
"dc_bot_started",
|
||||
data_about_bot.user.name.clone(),
|
||||
data_about_bot.user.id
|
||||
)
|
||||
"Bot started as user \"{}\" with id {}",
|
||||
data_about_bot.user.name,
|
||||
data_about_bot.user.id
|
||||
);
|
||||
|
||||
let file_text = std::fs::read_to_string("./data/status.txt").unwrap();
|
||||
|
||||
+2
-3
@@ -40,7 +40,6 @@ use websocket::send_cmd_json;
|
||||
|
||||
use crate::schedule::Schedule;
|
||||
|
||||
// TODO: convert to lang!
|
||||
|
||||
#[derive(Parser, Serialize, Clone)]
|
||||
struct Args {
|
||||
@@ -92,7 +91,7 @@ async fn main() {
|
||||
|
||||
rs_println!("Fetching language file...");
|
||||
data::load_lang_data(args.clone().lang);
|
||||
rs_println!("{}", lang!("lang_load_success"));
|
||||
rs_println!("[IMPORTANT] The below message is a test message, it should be written in the language you've selected\n{}", lang!("log_lang_load_success"));
|
||||
|
||||
let own_env = std::env::var("ASSISTANT_OWNERS").unwrap_or("0".to_string());
|
||||
let own_vec_str: Vec<String> = own_env.split(",").map(String::from).collect();
|
||||
@@ -156,7 +155,7 @@ async fn start(args: Args, owners: Vec<u64>) {
|
||||
let data = gen_data(args.clone(), owners).await;
|
||||
let mut bot = gen_bot(data, args).await;
|
||||
|
||||
rs_println!("{}", lang!("dc_bot_starting"));
|
||||
rs_println!("Starting Discord bot...");
|
||||
bot.start().await.unwrap();
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -29,7 +29,7 @@ pub struct EmbedOptions {
|
||||
impl Default for EmbedOptions {
|
||||
fn default() -> Self {
|
||||
return EmbedOptions {
|
||||
desc: lang!("default_embed_desc"),
|
||||
desc: lang!("dc_msg_embed_default_embed_desc"),
|
||||
title: None,
|
||||
col: None,
|
||||
url: None,
|
||||
@@ -45,7 +45,6 @@ impl Default for EmbedOptions {
|
||||
|
||||
static DEFAULT_DC_COL: u32 = 5793266;
|
||||
static REMOVED_DC_COL: u32 = 16716032;
|
||||
pub static MANDATORY_MSG: &str = "Mandatory response, please ignore.";
|
||||
|
||||
|
||||
fn none_to_empty(string: Option<String>) -> String {
|
||||
@@ -198,7 +197,7 @@ pub fn make_post_embed(post_data: &Value, url: &str, ephemeral: bool) -> EmbedOp
|
||||
let media_type = &post_data["post_data"]["media_type"];
|
||||
|
||||
let desc_str = lang!(
|
||||
"data_post_embed",
|
||||
"dc_msg_embed_re_post",
|
||||
post_data["post_data"]["upvotes"].as_i64().unwrap(),
|
||||
post_data["votes"]["mod_voters"].as_array().unwrap().len(),
|
||||
if !media_type.is_null() { media_type.as_str().unwrap() } else { "None" },
|
||||
@@ -242,7 +241,7 @@ pub fn make_removed_embed(post_data: &Value, url: &str, ephemeral: bool) -> Embe
|
||||
return EmbedOptions {
|
||||
title: Some("REMOVED!".to_string()),
|
||||
desc: lang!(
|
||||
"data_post_removed_embed",
|
||||
"dc_msg_embed_re_removed",
|
||||
post_data["removed_by"].as_str().unwrap(),
|
||||
if !post_data["remove_reason"].is_null() { post_data["remove_reason"].as_str().unwrap() }
|
||||
else { "None" },
|
||||
|
||||
+3
-3
@@ -10,12 +10,12 @@ use pyo3::types::PyList;
|
||||
|
||||
|
||||
pub async fn start(args: Args) -> PyResult<()> {
|
||||
rs_println!("{}", lang!("starting_python_program"));
|
||||
rs_println!("Running Python program...");
|
||||
|
||||
let args_str = serde_json::to_string(&args).expect("Error serializing args to JSON");
|
||||
|
||||
let slash = if cfg!(windows) { "\\" } else if cfg!(unix) { "/" } else { "" };
|
||||
if slash.is_empty() { errln!("{}", lang!("invalid_os")); }
|
||||
if slash.is_empty() { errln!("Man what kinda OS do you have? Neither unix or windows, what the hell!? I can't process this anymore, you're too weird!"); }
|
||||
|
||||
let path = format!("{0}{1}src{1}python", env!("CARGO_MANIFEST_DIR"), slash);
|
||||
|
||||
@@ -43,7 +43,7 @@ pub async fn start(args: Args) -> PyResult<()> {
|
||||
.map(|s| s.parse::<u64>().expect("Failed to parse ASSISTANT_OWNERS. Invalid syntax."))
|
||||
.collect();
|
||||
|
||||
send_dm(lang!("python_err", format!("{:?}", from_python)), args, own_vec_u64).await;
|
||||
send_dm(lang!("dc_msg_dm_python_err", format!("{:?}", from_python)), args, own_vec_u64).await;
|
||||
errln!("pyO3: {:?}", from_python);
|
||||
}
|
||||
return Ok(());
|
||||
|
||||
+5
-5
@@ -21,7 +21,7 @@ pub async fn cmd(
|
||||
) -> Result<(), Error>
|
||||
{
|
||||
if !is_bk_mod(ctx.data().bk_mods.clone(), ctx.author().id.get()) {
|
||||
send_msg(ctx, lang!("re_permdeny_bk_mod"), false, false).await;
|
||||
send_msg(ctx, lang!("dc_msg_re_permdeny_not_re_mod"), false, false).await; // TODO: add subreddit arg to lang
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -49,18 +49,18 @@ pub async fn cmd(
|
||||
|
||||
if let Some(post) = bk_week.get(shorturl) {
|
||||
if post.get("removed").is_some() {
|
||||
send_msg(ctx, lang!("re_unremove_post_success", url), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_re_post_unremove_success", url), true, true).await;
|
||||
}
|
||||
else {
|
||||
send_msg(ctx, lang!("re_update_post_success", url), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_re_post_update_success", url), true, true).await;
|
||||
}
|
||||
}
|
||||
else {
|
||||
send_msg(ctx, lang!("re_add_post_success", &shorturl), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_re_post_add_success", &shorturl), true, true).await;
|
||||
}
|
||||
|
||||
if a {
|
||||
send_msg(ctx, lang!("re_also_approved"), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_re_also_approved"), true, true).await;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,10 +18,10 @@ pub async fn cmd(
|
||||
let r = dc_bind_bk(ctx.data(), ctx.guild_id().unwrap().into(), c_id).await;
|
||||
|
||||
if r.is_ok() {
|
||||
send_msg(ctx, lang!("bound_dc_channel", c_id), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_bound_channel", c_id), true, true).await;
|
||||
}
|
||||
else {
|
||||
send_msg(ctx, lang!("dc_404"), false, false).await;
|
||||
send_msg(ctx, lang!("dc_msg_server_data_404"), false, false).await;
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
|
||||
@@ -19,7 +19,7 @@ pub async fn cmd(
|
||||
) -> Result<(), Error>
|
||||
{
|
||||
if !is_bk_mod(ctx.data().bk_mods.clone(), ctx.author().id.get()) {
|
||||
send_msg(ctx, lang!("re_permdeny_bk_mod"), false, false).await;
|
||||
send_msg(ctx, lang!("dc_msg_re_permdeny_not_re_mod"), false, false).await;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -42,17 +42,17 @@ 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]))).await.unwrap();
|
||||
if r.get("value").is_some() {
|
||||
if approve {
|
||||
send_msg(ctx, lang!("re_approve_post_success"), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_re_post_approve_success"), true, true).await;
|
||||
}
|
||||
else {
|
||||
send_msg(ctx, lang!("re_disapprove_post_success"), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_re_post_disapprove_success"), true, true).await;
|
||||
}
|
||||
}
|
||||
else {
|
||||
send_msg(ctx, lang!("re_err_trace", "`re_cmds -> approve.rs -> cmd() -> unwrap websocket result error`"), true, true).await;
|
||||
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!("re_404"), false, false).await;
|
||||
send_msg(ctx, lang!("dc_msg_re_post_404"), false, false).await;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -39,11 +39,11 @@ async fn get_post_from_data(ctx: Context<'_>, reddit_data: &Value, url: &str) ->
|
||||
return Ok(Some(post.clone()));
|
||||
}
|
||||
else {
|
||||
send_msg(ctx, lang!("re_404", url), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_re_post_404", url), true, true).await;
|
||||
}
|
||||
}
|
||||
else {
|
||||
send_msg(ctx, lang!("re_data_corrupted", url), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_re_data_corrupted", url), true, true).await;
|
||||
rs_println!("{}", serde_json::to_string_pretty(reddit_data)?);
|
||||
}
|
||||
return Ok(None);
|
||||
|
||||
@@ -17,7 +17,7 @@ pub async fn cmd(
|
||||
) -> Result<(), Error>
|
||||
{
|
||||
if !is_bk_mod(ctx.data().bk_mods.clone(), ctx.author().id.get()) {
|
||||
send_msg(ctx, lang!("re_permdeny_bk_mod"), false, false).await;
|
||||
send_msg(ctx, lang!("dc_msg_re_permdeny_not_re_mod"), false, false).await;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -27,13 +27,13 @@ pub async fn cmd(
|
||||
if r["value"].as_bool().unwrap() {
|
||||
send_msg(
|
||||
ctx,
|
||||
lang!("re_remove_post_success"),
|
||||
lang!("dc_msg_re_post_remove_success"),
|
||||
true,
|
||||
true
|
||||
).await;
|
||||
}
|
||||
else {
|
||||
send_msg(ctx, lang!("re_404"), false, false).await;
|
||||
send_msg(ctx, lang!("dc_msg_re_post_404"), false, false).await;
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
|
||||
@@ -105,7 +105,7 @@ async fn update_progress(ctx: Context<'_>, p: ReplyHandle<'_>, t: String, added_
|
||||
|
||||
async fn get_c_id(ctx: Context<'_>) -> Option<ChannelId> {
|
||||
if !data::dc_contains_server(ctx.data(), ctx.guild_id().unwrap().into()).await {
|
||||
send_msg(ctx, lang!("dc_404"), false, false).await;
|
||||
send_msg(ctx, lang!("dc_msg_server_data_404"), false, false).await;
|
||||
return None;
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -23,7 +23,7 @@ pub async fn cmd(
|
||||
let unw_vote = un_vote.unwrap_or(false);
|
||||
|
||||
if post_data.get(&url).is_none() {
|
||||
send_msg(ctx, lang!("re_404"), false, false).await;
|
||||
send_msg(ctx, lang!("dc_msg_re_post_404"), false, false).await;
|
||||
return Ok(());
|
||||
}
|
||||
if post_data[&url].get("removed").is_some() {
|
||||
@@ -39,11 +39,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!("re_already_voted"), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_re_already_voted"), true, true).await;
|
||||
return Ok(());
|
||||
}
|
||||
else if !voters.contains(&json!(uid)) && unw_vote {
|
||||
send_msg(ctx, lang!("re_havent_voted_remove_vote"), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_re_vote_remove_havent"), true, true).await;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -51,16 +51,16 @@ pub async fn cmd(
|
||||
let unw_r = r["value"].as_bool().unwrap();
|
||||
|
||||
if unw_r && !unw_vote && is_mod {
|
||||
send_msg(ctx, lang!("re_vote_success_mod"), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_re_vote_mod_success"), true, true).await;
|
||||
}
|
||||
else if unw_r && !unw_vote && !is_mod {
|
||||
send_msg(ctx, lang!("re_vote_success"), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_re_vote_success"), true, true).await;
|
||||
}
|
||||
else if unw_r && unw_vote {
|
||||
send_msg(ctx, lang!("re_vote_remove_success"), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_re_vote_remove_success"), true, true).await;
|
||||
}
|
||||
else {
|
||||
send_msg(ctx, lang!("re_vote_err"), true, true).await;
|
||||
send_msg(ctx, lang!("dc_msg_re_vote_err"), true, true).await;
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ pub async fn run_schedule<F: Fn() -> Pin<Box<dyn Future<Output = ()> + Send>>>(d
|
||||
pub async fn run_schedules(schedules: Vec<Schedule>) {
|
||||
let mut handles: Vec<JoinHandle<()>> = vec![];
|
||||
|
||||
rs_println!("{}", lang!("starting_schedules"));
|
||||
rs_println!("Starting schedules...");
|
||||
for (d, f) in schedules {
|
||||
let handle = tokio::spawn(run_schedule(d, f));
|
||||
handles.push(handle);
|
||||
|
||||
+9
-9
@@ -66,11 +66,11 @@ pub async fn send_cmd_json(func_name: &str, func_args: Option<Value>) -> Option<
|
||||
|
||||
let r = receive_response().await;
|
||||
if !["respond_mentions"].contains(&func_name) || <Args as clap::Parser>::parse().dev {
|
||||
rs_println!("{}", lang!("python_socket_response", format!("{:?}", r)));
|
||||
rs_println!("Received from Python: [RESPONSE] {:?}", r);
|
||||
}
|
||||
|
||||
if r.is_none() {
|
||||
rs_println!("{}", lang!("python_socket_null"));
|
||||
rs_println!("[IMPORTANT] Response from Python is None!");
|
||||
}
|
||||
|
||||
return r;
|
||||
@@ -99,10 +99,10 @@ async fn receive_response() -> Option<Value> {
|
||||
|
||||
|
||||
pub async fn start(args: Args, owners: Vec<u64>) {
|
||||
rs_println!("{}", lang!("starting_socket"));
|
||||
rs_println!("Running local websocket...");
|
||||
let ip = format!("127.0.0.1:{}", args.port);
|
||||
let listener = TcpListener::bind(&ip).await.unwrap();
|
||||
rs_println!("{}", lang!("started_socket", ip));
|
||||
rs_println!("WebSocket server running on ws://{}", ip);
|
||||
|
||||
tokio::spawn(handle_connections(listener, args, owners));
|
||||
}
|
||||
@@ -129,18 +129,18 @@ async fn handle_connections(listener: TcpListener, args: Args, owners: Vec<u64>)
|
||||
async fn handle_message(msg: tungstenite::protocol::Message, args: Args, owners: Vec<u64>) {
|
||||
match msg {
|
||||
tungstenite::Message::Text(text) => {
|
||||
rs_println!("{}", lang!("socket_received_python", text.clone()));
|
||||
rs_println!("Received from Python: {}", text);
|
||||
|
||||
if let Some(stripped) = text.strip_prefix("json:") {
|
||||
let t_json: Value = serde_json::from_str(stripped).unwrap();
|
||||
if t_json.get("error").is_some() {
|
||||
send_dm(lang!("python_socket_err"), args, owners).await;
|
||||
send_dm(lang!("dc_msg_dm_python_err_socket"), args, owners).await;
|
||||
}
|
||||
}
|
||||
|
||||
unsafe {
|
||||
if !REPLY_HELLO {
|
||||
send_msg(&lang!("socket_rust_connection_test")).await;
|
||||
send_msg("[Connection test] Hello from Rust!").await;
|
||||
REPLY_HELLO = true;
|
||||
HAS_CONNECTED = true;
|
||||
}
|
||||
@@ -148,12 +148,12 @@ async fn handle_message(msg: tungstenite::protocol::Message, args: Args, owners:
|
||||
}
|
||||
tungstenite::Message::Binary(bytes) => {
|
||||
if args.dev && !args.noping {
|
||||
rs_println!("{}", lang!("python_socket_binary_response", format!("{:?}", bytes)));
|
||||
rs_println!("[Binary] from Python: {:?}", bytes);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if args.dev && !args.noping {
|
||||
rs_println!("{}", lang!("python_socket_unknown_response"));
|
||||
rs_println!("Received from Python: [UNKNOWN / OTHER]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user