diff --git a/src/autocomplete_helpers/mod.rs b/src/autocomplete_helpers/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/commands/core.rs b/src/commands/core.rs index b3d1e47..77f0a36 100644 --- a/src/commands/core.rs +++ b/src/commands/core.rs @@ -1,3 +1,4 @@ +use chrono::TimeZone; use poise::serenity_prelude::*; use crate::{ManifoldContext, ManifoldData}; @@ -78,6 +79,27 @@ async fn set_timezone(ctx: ManifoldContext<'_>, input_timezone: String) -> Manif Ok(()) } -pub fn commands() -> [poise::Command; 4] { - [help(), ping(), version(), set_timezone()] +#[poise::command(slash_command, prefix_command, aliases("t"))] +pub async fn time(ctx: ManifoldContext<'_>, target: u64) -> ManifoldResult<()> { + let userinfo = ctx.data().user_info.lock().await; + + let user = match userinfo.get(&target) { + Some(u) => match u.timezone.to_owned() { + Some(t) => u, + None => {ctx.send(|f| f.content(format!("This user hasn't given me their timezone yet. Shame on them!")).reply(true)).await?; Err("NoTZ")?} + }, + None => { ctx.send(|f| f.content(format!("Who's that? I don't know them.")).reply(true)).await?; Err("User not found")?} + }; + + let current_time_utc = chrono::Utc::now(); + let user_timezone: Tz = user.timezone.as_ref().unwrap().parse::().unwrap(); + let adjusted_time = user_timezone.from_utc_datetime(¤t_time_utc.naive_utc()); + + ctx.send(|f| f.content(format!("Time in {}'s current timezone of {} is {}", user.username, user_timezone.name().to_string(), adjusted_time.time().to_string())).reply(true)).await?; + + Ok(()) +} + +pub fn commands() -> [poise::Command; 5] { + [help(), ping(), version(), set_timezone(), time()] } diff --git a/src/commands/weather.rs b/src/commands/weather.rs index 91b9371..8ab54ba 100644 --- a/src/commands/weather.rs +++ b/src/commands/weather.rs @@ -95,7 +95,7 @@ pub async fn weather_forecast(ctx: &Context, msg: &Message, args: Args) -> Comma */ #[poise::command(slash_command, prefix_command, aliases("wl"))] -pub async fn save_weather_location(ctx: ManifoldContext<'_>, #[description="Your default weather location"] location: String) -> ManifoldResult<()> { +pub async fn save_weather_location(ctx: ManifoldContext<'_>, #[rest] #[description="Your default weather location"] location: String) -> ManifoldResult<()> { let userinfo = &mut ctx.data().user_info.lock().await; let db = &ctx.data().database; diff --git a/src/lib.rs b/src/lib.rs index 61fdb6f..ca68fa7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,6 +20,7 @@ use crate::events::Handler; use crate::models::user::{ManifoldUserInfo, UserInfo}; use crate::responses::Responses; +pub mod autocomplete_helpers; pub mod config; pub mod error; pub mod events;