From 84aa7c327831e7893d2e4e2b9f837d635725fcca Mon Sep 17 00:00:00 2001 From: jude Date: Mon, 12 Oct 2020 22:43:02 +0100 Subject: [PATCH] readded local_language config option --- README.md | 1 + src/consts.rs | 2 ++ src/models.rs | 6 +++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3f47301..df924df 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,4 @@ __Other Variables__ * `CNC_GUILD` - default `None`, accepts a single Discord guild ID for the server that the subscription roles belong to * `IGNORE_BOTS` - default `1`, if `1`, Reminder Bot will ignore all other bots * `PYTHON_LOCATION` - default `venv/bin/python3`. Can be changed if your Python executable is located somewhere else +* `LOCAL_LANGUAGE` - default `EN`. Specifies the string set to fall back to if a string cannot be found (and to be used with new users) diff --git a/src/consts.rs b/src/consts.rs index 6ebdadc..2591c76 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -41,6 +41,8 @@ lazy_static! { .unwrap_or(60 * 60 * 24 * 365 * 50); pub static ref LOCAL_TIMEZONE: String = env::var("LOCAL_TIMEZONE").unwrap_or_else(|_| "UTC".to_string()); + pub static ref LOCAL_LANGUAGE: String = + env::var("LOCAL_LANGUAGE").unwrap_or_else(|_| "EN".to_string()); pub static ref PYTHON_LOCATION: String = env::var("PYTHON_LOCATION").unwrap_or_else(|_| "venv/bin/python3".to_string()); } diff --git a/src/models.rs b/src/models.rs index f935ee2..488bd4a 100644 --- a/src/models.rs +++ b/src/models.rs @@ -10,7 +10,7 @@ use sqlx::MySqlPool; use chrono::NaiveDateTime; use chrono_tz::Tz; -use crate::consts::PREFIX; +use crate::consts::{LOCAL_LANGUAGE, PREFIX}; pub struct GuildData { pub id: u32, @@ -251,8 +251,8 @@ UPDATE users SET name = ?, language = ?, timezone = ? WHERE id = ? pub async fn response(&self, pool: &MySqlPool, name: &str) -> String { let row = sqlx::query!( " -SELECT value FROM strings WHERE (language = ? OR language = 'EN') AND name = ? ORDER BY language = 'EN' - ", self.language, name) +SELECT value FROM strings WHERE (language = ? OR language = ?) AND name = ? ORDER BY language = ? + ", self.language, *LOCAL_LANGUAGE, name, *LOCAL_LANGUAGE) .fetch_one(pool) .await .unwrap_or_else(|_| panic!("No string with that name: {}", name));