timezone_of method for more lazy-storage. fix for del command raising issues if 0 is written. fix for get_language not recognising
This commit is contained in:
parent
d8bf0240e4
commit
012d90e832
@ -169,11 +169,13 @@ async fn clock(ctx: &Context, msg: &Message, args: String) {
|
|||||||
.expect("Could not get SQLPool from data");
|
.expect("Could not get SQLPool from data");
|
||||||
|
|
||||||
let lm = data.get::<LanguageManager>().unwrap();
|
let lm = data.get::<LanguageManager>().unwrap();
|
||||||
let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap();
|
|
||||||
|
|
||||||
let now = Utc::now().with_timezone(&user_data.timezone());
|
let language = UserData::language_of(&msg.author, &pool).await;
|
||||||
|
let timezone = UserData::timezone_of(&msg.author, &pool).await;
|
||||||
|
|
||||||
let clock_display = lm.get(&user_data.language, "clock/time");
|
let now = Utc::now().with_timezone(&timezone);
|
||||||
|
|
||||||
|
let clock_display = lm.get(&language, "clock/time");
|
||||||
|
|
||||||
if args == "12" {
|
if args == "12" {
|
||||||
let _ = msg
|
let _ = msg
|
||||||
|
@ -42,7 +42,7 @@ async fn blacklist(ctx: &Context, msg: &Message, args: String) {
|
|||||||
lm = data.get::<LanguageManager>().cloned().unwrap();
|
lm = data.get::<LanguageManager>().cloned().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap();
|
let language = UserData::language_of(&msg.author, &pool).await;
|
||||||
|
|
||||||
let capture_opt = REGEX_CHANNEL
|
let capture_opt = REGEX_CHANNEL
|
||||||
.captures(&args)
|
.captures(&args)
|
||||||
@ -71,24 +71,24 @@ async fn blacklist(ctx: &Context, msg: &Message, args: String) {
|
|||||||
if local {
|
if local {
|
||||||
let _ = msg
|
let _ = msg
|
||||||
.channel_id
|
.channel_id
|
||||||
.say(&ctx, lm.get(&user_data.language, "blacklist/added"))
|
.say(&ctx, lm.get(&language, "blacklist/added"))
|
||||||
.await;
|
.await;
|
||||||
} else {
|
} else {
|
||||||
let _ = msg
|
let _ = msg
|
||||||
.channel_id
|
.channel_id
|
||||||
.say(&ctx, lm.get(&user_data.language, "blacklist/added_from"))
|
.say(&ctx, lm.get(&language, "blacklist/added_from"))
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if local {
|
if local {
|
||||||
let _ = msg
|
let _ = msg
|
||||||
.channel_id
|
.channel_id
|
||||||
.say(&ctx, lm.get(&user_data.language, "blacklist/removed"))
|
.say(&ctx, lm.get(&language, "blacklist/removed"))
|
||||||
.await;
|
.await;
|
||||||
} else {
|
} else {
|
||||||
let _ = msg
|
let _ = msg
|
||||||
.channel_id
|
.channel_id
|
||||||
.say(&ctx, lm.get(&user_data.language, "blacklist/removed_from"))
|
.say(&ctx, lm.get(&language, "blacklist/removed_from"))
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -215,27 +215,25 @@ async fn prefix(ctx: &Context, msg: &Message, args: String) {
|
|||||||
let mut guild_data = GuildData::from_guild(msg.guild(&ctx).await.unwrap(), &pool)
|
let mut guild_data = GuildData::from_guild(msg.guild(&ctx).await.unwrap(), &pool)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap();
|
let language = UserData::language_of(&msg.author, &pool).await;
|
||||||
|
|
||||||
if args.len() > 5 {
|
if args.len() > 5 {
|
||||||
let _ = msg
|
let _ = msg
|
||||||
.channel_id
|
.channel_id
|
||||||
.say(&ctx, lm.get(&user_data.language, "prefix/too_long"))
|
.say(&ctx, lm.get(&language, "prefix/too_long"))
|
||||||
.await;
|
.await;
|
||||||
} else if args.is_empty() {
|
} else if args.is_empty() {
|
||||||
let _ = msg
|
let _ = msg
|
||||||
.channel_id
|
.channel_id
|
||||||
.say(&ctx, lm.get(&user_data.language, "prefix/no_argument"))
|
.say(&ctx, lm.get(&language, "prefix/no_argument"))
|
||||||
.await;
|
.await;
|
||||||
} else {
|
} else {
|
||||||
guild_data.prefix = args;
|
guild_data.prefix = args;
|
||||||
guild_data.commit_changes(&pool).await;
|
guild_data.commit_changes(&pool).await;
|
||||||
|
|
||||||
let content = lm.get(&user_data.language, "prefix/success").replacen(
|
let content =
|
||||||
"{prefix}",
|
lm.get(&language, "prefix/success")
|
||||||
&guild_data.prefix,
|
.replacen("{prefix}", &guild_data.prefix, 1);
|
||||||
1,
|
|
||||||
);
|
|
||||||
|
|
||||||
let _ = msg.channel_id.say(&ctx, content).await;
|
let _ = msg.channel_id.say(&ctx, content).await;
|
||||||
}
|
}
|
||||||
@ -259,7 +257,7 @@ async fn restrict(ctx: &Context, msg: &Message, args: String) {
|
|||||||
lm = data.get::<LanguageManager>().cloned().unwrap();
|
lm = data.get::<LanguageManager>().cloned().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap();
|
let language = UserData::language_of(&msg.author, &pool).await;
|
||||||
let guild_data = GuildData::from_guild(msg.guild(&ctx).await.unwrap(), &pool)
|
let guild_data = GuildData::from_guild(msg.guild(&ctx).await.unwrap(), &pool)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -292,7 +290,7 @@ DELETE FROM command_restrictions WHERE role_id = (SELECT id FROM roles WHERE rol
|
|||||||
if commands.is_empty() {
|
if commands.is_empty() {
|
||||||
let _ = msg
|
let _ = msg
|
||||||
.channel_id
|
.channel_id
|
||||||
.say(&ctx, lm.get(&user_data.language, "restrict/disabled"))
|
.say(&ctx, lm.get(&language, "restrict/disabled"))
|
||||||
.await;
|
.await;
|
||||||
} else {
|
} else {
|
||||||
let _ = sqlx::query!(
|
let _ = sqlx::query!(
|
||||||
@ -317,7 +315,7 @@ INSERT INTO command_restrictions (role_id, command) VALUES ((SELECT id FROM role
|
|||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
println!("{:?}", res);
|
println!("{:?}", res);
|
||||||
|
|
||||||
let content = lm.get(&user_data.language, "restrict/failure").replacen(
|
let content = lm.get(&language, "restrict/failure").replacen(
|
||||||
"{command}",
|
"{command}",
|
||||||
&command,
|
&command,
|
||||||
1,
|
1,
|
||||||
@ -329,7 +327,7 @@ INSERT INTO command_restrictions (role_id, command) VALUES ((SELECT id FROM role
|
|||||||
|
|
||||||
let _ = msg
|
let _ = msg
|
||||||
.channel_id
|
.channel_id
|
||||||
.say(&ctx, lm.get(&user_data.language, "restrict/enabled"))
|
.say(&ctx, lm.get(&language, "restrict/enabled"))
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -360,15 +358,15 @@ WHERE
|
|||||||
.map(|row| format!("<@&{}> can use {}", row.role, row.command))
|
.map(|row| format!("<@&{}> can use {}", row.role, row.command))
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
let display =
|
let display = lm
|
||||||
lm.get(&user_data.language, "restrict/allowed")
|
.get(&language, "restrict/allowed")
|
||||||
.replacen("{}", &display_inner, 1);
|
.replacen("{}", &display_inner, 1);
|
||||||
|
|
||||||
let _ = msg.channel_id.say(&ctx, display).await;
|
let _ = msg.channel_id.say(&ctx, display).await;
|
||||||
} else {
|
} else {
|
||||||
let _ = msg
|
let _ = msg
|
||||||
.channel_id
|
.channel_id
|
||||||
.say(&ctx, lm.get(&user_data.language, "restrict/help"))
|
.say(&ctx, lm.get(&language, "restrict/help"))
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -391,7 +389,7 @@ async fn alias(ctx: &Context, msg: &Message, args: String) {
|
|||||||
lm = data.get::<LanguageManager>().cloned().unwrap();
|
lm = data.get::<LanguageManager>().cloned().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap();
|
let language = UserData::language_of(&msg.author, &pool).await;
|
||||||
|
|
||||||
let guild_id = msg.guild_id.unwrap().as_u64().to_owned();
|
let guild_id = msg.guild_id.unwrap().as_u64().to_owned();
|
||||||
|
|
||||||
@ -444,14 +442,14 @@ DELETE FROM command_aliases WHERE name = ? AND guild_id = (SELECT id FROM guilds
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let content = lm
|
let content = lm
|
||||||
.get(&user_data.language, "alias/removed")
|
.get(&language, "alias/removed")
|
||||||
.replace("{count}", &deleted_count.count.to_string());
|
.replace("{count}", &deleted_count.count.to_string());
|
||||||
|
|
||||||
let _ = msg.channel_id.say(&ctx, content).await;
|
let _ = msg.channel_id.say(&ctx, content).await;
|
||||||
} else {
|
} else {
|
||||||
let _ = msg
|
let _ = msg
|
||||||
.channel_id
|
.channel_id
|
||||||
.say(&ctx, lm.get(&user_data.language, "alias/help"))
|
.say(&ctx, lm.get(&language, "alias/help"))
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -475,9 +473,7 @@ UPDATE command_aliases SET command = ? WHERE guild_id = (SELECT id FROM guilds W
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let content = lm
|
let content = lm.get(&language, "alias/created").replace("{name}", name);
|
||||||
.get(&user_data.language, "alias/created")
|
|
||||||
.replace("{name}", name);
|
|
||||||
|
|
||||||
let _ = msg.channel_id.say(&ctx, content).await;
|
let _ = msg.channel_id.say(&ctx, content).await;
|
||||||
} else {
|
} else {
|
||||||
@ -499,7 +495,7 @@ SELECT command FROM command_aliases WHERE guild_id = (SELECT id FROM guilds WHER
|
|||||||
},
|
},
|
||||||
|
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let content = lm.get(&user_data.language, "alias/not_found").replace("{name}", name);
|
let content = lm.get(&language, "alias/not_found").replace("{name}", name);
|
||||||
|
|
||||||
let _ = msg.channel_id.say(&ctx, content).await;
|
let _ = msg.channel_id.say(&ctx, content).await;
|
||||||
},
|
},
|
||||||
@ -509,9 +505,7 @@ SELECT command FROM command_aliases WHERE guild_id = (SELECT id FROM guilds WHER
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await;
|
let prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await;
|
||||||
let content = lm
|
let content = lm.get(&language, "alias/help").replace("{prefix}", &prefix);
|
||||||
.get(&user_data.language, "alias/help")
|
|
||||||
.replace("{prefix}", &prefix);
|
|
||||||
|
|
||||||
let _ = msg.channel_id.say(&ctx, content).await;
|
let _ = msg.channel_id.say(&ctx, content).await;
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,9 @@ async fn pause(ctx: &Context, msg: &Message, args: String) {
|
|||||||
lm = data.get::<LanguageManager>().cloned().unwrap();
|
lm = data.get::<LanguageManager>().cloned().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap();
|
let language = UserData::language_of(&msg.author, &pool).await;
|
||||||
|
let timezone = UserData::timezone_of(&msg.author, &pool).await;
|
||||||
|
|
||||||
let mut channel = ChannelData::from_channel(msg.channel(&ctx).await.unwrap(), &pool)
|
let mut channel = ChannelData::from_channel(msg.channel(&ctx).await.unwrap(), &pool)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -142,16 +144,16 @@ async fn pause(ctx: &Context, msg: &Message, args: String) {
|
|||||||
if channel.paused {
|
if channel.paused {
|
||||||
let _ = msg
|
let _ = msg
|
||||||
.channel_id
|
.channel_id
|
||||||
.say(&ctx, lm.get(&user_data.language, "pause/paused_indefinite"))
|
.say(&ctx, lm.get(&language, "pause/paused_indefinite"))
|
||||||
.await;
|
.await;
|
||||||
} else {
|
} else {
|
||||||
let _ = msg
|
let _ = msg
|
||||||
.channel_id
|
.channel_id
|
||||||
.say(&ctx, lm.get(&user_data.language, "pause/unpaused"))
|
.say(&ctx, lm.get(&language, "pause/unpaused"))
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let parser = TimeParser::new(args, user_data.timezone());
|
let parser = TimeParser::new(args, timezone);
|
||||||
let pause_until = parser.timestamp();
|
let pause_until = parser.timestamp();
|
||||||
|
|
||||||
match pause_until {
|
match pause_until {
|
||||||
@ -163,10 +165,9 @@ async fn pause(ctx: &Context, msg: &Message, args: String) {
|
|||||||
|
|
||||||
channel.commit_changes(&pool).await;
|
channel.commit_changes(&pool).await;
|
||||||
|
|
||||||
let content = lm.get(&user_data.language, "pause/paused_until").replace(
|
let content = lm.get(&language, "pause/paused_until").replace(
|
||||||
"{}",
|
"{}",
|
||||||
&user_data
|
&timezone
|
||||||
.timezone()
|
|
||||||
.timestamp(timestamp, 0)
|
.timestamp(timestamp, 0)
|
||||||
.format("%Y-%m-%d %H:%M:%S")
|
.format("%Y-%m-%d %H:%M:%S")
|
||||||
.to_string(),
|
.to_string(),
|
||||||
@ -178,7 +179,7 @@ async fn pause(ctx: &Context, msg: &Message, args: String) {
|
|||||||
Err(_) => {
|
Err(_) => {
|
||||||
let _ = msg
|
let _ = msg
|
||||||
.channel_id
|
.channel_id
|
||||||
.say(&ctx, lm.get(&user_data.language, "pause/invalid_time"))
|
.say(&ctx, lm.get(&language, "pause/invalid_time"))
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -277,19 +278,21 @@ async fn nudge(ctx: &Context, msg: &Message, args: String) {
|
|||||||
lm = data.get::<LanguageManager>().cloned().unwrap();
|
lm = data.get::<LanguageManager>().cloned().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap();
|
let language = UserData::language_of(&msg.author, &pool).await;
|
||||||
|
let timezone = UserData::timezone_of(&msg.author, &pool).await;
|
||||||
|
|
||||||
let mut channel = ChannelData::from_channel(msg.channel(&ctx).await.unwrap(), &pool)
|
let mut channel = ChannelData::from_channel(msg.channel(&ctx).await.unwrap(), &pool)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
let content = lm
|
let content = lm
|
||||||
.get(&user_data.language, "nudge/no_argument")
|
.get(&language, "nudge/no_argument")
|
||||||
.replace("{nudge}", &format!("{}s", &channel.nudge.to_string()));
|
.replace("{nudge}", &format!("{}s", &channel.nudge.to_string()));
|
||||||
|
|
||||||
let _ = msg.channel_id.say(&ctx, content).await;
|
let _ = msg.channel_id.say(&ctx, content).await;
|
||||||
} else {
|
} else {
|
||||||
let parser = TimeParser::new(args, user_data.timezone.parse().unwrap());
|
let parser = TimeParser::new(args, timezone);
|
||||||
let nudge_time = parser.displacement();
|
let nudge_time = parser.displacement();
|
||||||
|
|
||||||
match nudge_time {
|
match nudge_time {
|
||||||
@ -297,14 +300,14 @@ async fn nudge(ctx: &Context, msg: &Message, args: String) {
|
|||||||
if displacement < i16::MIN as i64 || displacement > i16::MAX as i64 {
|
if displacement < i16::MIN as i64 || displacement > i16::MAX as i64 {
|
||||||
let _ = msg
|
let _ = msg
|
||||||
.channel_id
|
.channel_id
|
||||||
.say(&ctx, lm.get(&user_data.language, "nudge/invalid_time"))
|
.say(&ctx, lm.get(&language, "nudge/invalid_time"))
|
||||||
.await;
|
.await;
|
||||||
} else {
|
} else {
|
||||||
channel.nudge = displacement as i16;
|
channel.nudge = displacement as i16;
|
||||||
|
|
||||||
channel.commit_changes(&pool).await;
|
channel.commit_changes(&pool).await;
|
||||||
|
|
||||||
let response = lm.get(&user_data.language, "nudge/success").replacen(
|
let response = lm.get(&language, "nudge/success").replacen(
|
||||||
"{}",
|
"{}",
|
||||||
&displacement.to_string(),
|
&displacement.to_string(),
|
||||||
1,
|
1,
|
||||||
@ -317,7 +320,7 @@ async fn nudge(ctx: &Context, msg: &Message, args: String) {
|
|||||||
Err(_) => {
|
Err(_) => {
|
||||||
let _ = msg
|
let _ = msg
|
||||||
.channel_id
|
.channel_id
|
||||||
.say(&ctx, lm.get(&user_data.language, "nudge/invalid_time"))
|
.say(&ctx, lm.get(&language, "nudge/invalid_time"))
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -425,7 +428,8 @@ async fn look(ctx: &Context, msg: &Message, args: String) {
|
|||||||
lm = data.get::<LanguageManager>().cloned().unwrap();
|
lm = data.get::<LanguageManager>().cloned().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap();
|
let language = UserData::language_of(&msg.author, &pool).await;
|
||||||
|
let timezone = UserData::timezone_of(&msg.author, &pool).await;
|
||||||
|
|
||||||
let flags = LookFlags::from_string(&args);
|
let flags = LookFlags::from_string(&args);
|
||||||
|
|
||||||
@ -549,15 +553,14 @@ LIMIT
|
|||||||
if reminders.is_empty() {
|
if reminders.is_empty() {
|
||||||
let _ = msg
|
let _ = msg
|
||||||
.channel_id
|
.channel_id
|
||||||
.say(&ctx, lm.get(&user_data.language, "look/no_reminders"))
|
.say(&ctx, lm.get(&language, "look/no_reminders"))
|
||||||
.await;
|
.await;
|
||||||
} else {
|
} else {
|
||||||
let inter = lm.get(&user_data.language, "look/inter");
|
let inter = lm.get(&language, "look/inter");
|
||||||
|
|
||||||
let display = reminders.iter().map(|reminder| {
|
let display = reminders.iter().map(|reminder| {
|
||||||
let time_display = match flags.time_display {
|
let time_display = match flags.time_display {
|
||||||
TimeDisplayType::Absolute => user_data
|
TimeDisplayType::Absolute => timezone
|
||||||
.timezone()
|
|
||||||
.timestamp(reminder.time as i64, 0)
|
.timestamp(reminder.time as i64, 0)
|
||||||
.format("%Y-%m-%d %H:%M:%S")
|
.format("%Y-%m-%d %H:%M:%S")
|
||||||
.to_string(),
|
.to_string(),
|
||||||
@ -703,6 +706,7 @@ WHERE
|
|||||||
.filter_map(|i| {
|
.filter_map(|i| {
|
||||||
i.parse::<usize>()
|
i.parse::<usize>()
|
||||||
.ok()
|
.ok()
|
||||||
|
.filter(|val| val > &0)
|
||||||
.map(|val| reminder_ids.get(val - 1))
|
.map(|val| reminder_ids.get(val - 1))
|
||||||
.flatten()
|
.flatten()
|
||||||
})
|
})
|
||||||
|
@ -36,9 +36,13 @@ impl LanguageManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_language(&self, language: &str) -> Option<&str> {
|
pub fn get_language(&self, language: &str) -> Option<&str> {
|
||||||
|
let language_normal = language.to_lowercase();
|
||||||
|
|
||||||
self.languages
|
self.languages
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(k, v)| k.to_lowercase() == language || v.to_lowercase() == language)
|
.filter(|(k, v)| {
|
||||||
|
k.to_lowercase() == language_normal || v.to_lowercase() == language_normal
|
||||||
|
})
|
||||||
.map(|(k, _)| k.as_str())
|
.map(|(k, _)| k.as_str())
|
||||||
.next()
|
.next()
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
use serenity::{
|
use serenity::{
|
||||||
http::CacheHttp,
|
http::CacheHttp,
|
||||||
model::{channel::Channel, guild::Guild, id::GuildId, user::User},
|
model::{
|
||||||
|
channel::Channel,
|
||||||
|
guild::Guild,
|
||||||
|
id::{GuildId, UserId},
|
||||||
|
user::User,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use sqlx::MySqlPool;
|
use sqlx::MySqlPool;
|
||||||
@ -178,25 +183,50 @@ pub struct UserData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl UserData {
|
impl UserData {
|
||||||
pub async fn language_of(user: &User, pool: &MySqlPool) -> String {
|
pub async fn language_of<U>(user: U, pool: &MySqlPool) -> String
|
||||||
let user_id = user.id.as_u64().to_owned();
|
where
|
||||||
|
U: Into<UserId>,
|
||||||
|
{
|
||||||
|
let user_id = user.into().as_u64().to_owned();
|
||||||
|
|
||||||
match sqlx::query!(
|
match sqlx::query!(
|
||||||
"
|
"
|
||||||
SELECT IF(language IS NULL, ?, language) AS language FROM users WHERE user = ?
|
SELECT language FROM users WHERE user = ?
|
||||||
",
|
",
|
||||||
*LOCAL_LANGUAGE,
|
|
||||||
user_id
|
user_id
|
||||||
)
|
)
|
||||||
.fetch_one(pool)
|
.fetch_one(pool)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(r) => r.language.unwrap(),
|
Ok(r) => r.language,
|
||||||
|
|
||||||
Err(_) => LOCAL_LANGUAGE.clone(),
|
Err(_) => LOCAL_LANGUAGE.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn timezone_of<U>(user: U, pool: &MySqlPool) -> Tz
|
||||||
|
where
|
||||||
|
U: Into<UserId>,
|
||||||
|
{
|
||||||
|
let user_id = user.into().as_u64().to_owned();
|
||||||
|
|
||||||
|
match sqlx::query!(
|
||||||
|
"
|
||||||
|
SELECT timezone FROM users WHERE user = ?
|
||||||
|
",
|
||||||
|
user_id
|
||||||
|
)
|
||||||
|
.fetch_one(pool)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(r) => r.timezone,
|
||||||
|
|
||||||
|
Err(_) => LOCAL_TIMEZONE.clone(),
|
||||||
|
}
|
||||||
|
.parse()
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn from_user(
|
pub async fn from_user(
|
||||||
user: &User,
|
user: &User,
|
||||||
ctx: impl CacheHttp,
|
ctx: impl CacheHttp,
|
||||||
|
Loading…
Reference in New Issue
Block a user