Amend save_weather_location to consume the entire string when passed as prefix command
This commit is contained in:
parent
8a02ee7666
commit
363b4f7860
|
|
@ -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<ManifoldData, ManifoldError>; 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::<Tz>().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<ManifoldData, ManifoldError>; 5] {
|
||||
[help(), ping(), version(), set_timezone(), time()]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue