use poise::serenity_prelude::*; use crate::{ManifoldContext, ManifoldData}; use chrono_tz::Tz; use crate::error::{ManifoldError, ManifoldResult}; use crate::models::user::UserInfo; #[poise::command(prefix_command, track_edits, slash_command)] async fn help( ctx: ManifoldContext<'_>, #[description = "Help about a specific command"] command: Option ) -> ManifoldResult<()> { let responses = &ctx.data().responses; let config = poise::builtins::HelpConfiguration { extra_text_at_bottom: &*format!("{}", responses.get_response(&"help footer".to_string()).unwrap_or(&"".to_string())), ..Default::default() }; poise::builtins::help(ctx, command.as_deref(), config).await?; Ok(()) } #[poise::command(slash_command, prefix_command)] async fn ping(ctx: ManifoldContext<'_>,) -> ManifoldResult<()> { let requestor = { let calling_user = ctx.author(); calling_user.mention().to_string() }; ctx.say(format!("{}: Ping? Pong!", requestor)).await?; Ok(()) } #[poise::command(slash_command, prefix_command)] async fn version(ctx: ManifoldContext<'_>) -> ManifoldResult<()> { let version_string = &ctx.data().version_string; ctx.send(|f| f .reply(true) .content(version_string)).await?; Ok(()) } #[poise::command(slash_command, prefix_command, aliases("st"))] async fn set_timezone(ctx: ManifoldContext<'_>, input_timezone: String) -> ManifoldResult<()> { let mut userinfo = ctx.data().user_info.lock().await; let validated_timezone: Tz = match input_timezone.parse() { Ok(r) => r, Err(e) => { error!("Problem parsing timezone input: {:?}", e); ctx.send(|f| f.content(format!("Are you having a laugh? What kind of timezone is that? {:?}", e)).reply(true)).await?; Err(e)? } }; if let Some(user) = userinfo.get_mut(ctx.author().id.as_u64()) { user.timezone = Some(validated_timezone.to_string()); ctx.send(|f| f.content(format!("I have set your timezone to {}, but we all know that UTC is the One True Timezone.", validated_timezone.to_string())).reply(true)).await?; } else { let new_user = UserInfo { user_id: ctx.author().id.as_u64().to_owned() as i64, username: ctx.author().name.to_owned(), weather_location: None, weather_units: None, timezone: Some(validated_timezone.to_string()), last_seen: Some(chrono::Utc::now().timestamp()) }; userinfo.insert(ctx.author().id.as_u64().clone(), new_user); ctx.send(|f| f.content(format!("I have set your timezone to {}, but we all know that UTC is the One True Timezone.", validated_timezone.to_string())).reply(true)).await?; } Ok(()) } pub fn commands() -> [poise::Command; 4] { [help(), ping(), version(), set_timezone()] }