use chrono_tz::Tz; use poise::serenity_prelude::model::id::GuildId; use serde::{Deserialize, Serialize}; use crate::{ApplicationContext, Context}; #[derive(Serialize, Deserialize)] #[serde(tag = "command_name")] pub enum RecordedCommand { Remind(RemindOptions), } impl RecordedCommand { pub fn from_context(ctx: ApplicationContext) -> Option { match ctx.command().identifying_name.as_str() { "remind" => Some(Self::Remind(RemindOptions { time: "10 seconds".to_string(), content: "message".to_string(), channels: None, interval: None, expires: None, tts: None, timezone: None, })), _ => None, } } pub async fn execute(&self, ctx: ApplicationContext<'_>) { match self { RecordedCommand::Remind(_) => {} } } } #[derive(Serialize, Deserialize, Default)] pub struct RemindOptions { time: String, content: String, channels: Option, interval: Option, expires: Option, tts: Option, timezone: Option, } pub struct CommandMacro { pub guild_id: GuildId, pub name: String, pub description: Option, pub commands: Vec, } pub async fn guild_command_macro(ctx: &Context<'_>, name: &str) -> Option { let row = sqlx::query!( " SELECT m.id, m.name, m.description, m.commands FROM macro m INNER JOIN guilds g ON g.id = m.guild_id WHERE guild = ? AND m.name = ? ", ctx.guild_id().unwrap().get(), name ) .fetch_one(&ctx.data().database) .await .ok()?; let commands: Vec = serde_json::from_str(&row.commands).unwrap(); let command_macro = CommandMacro { guild_id: ctx.guild_id().unwrap(), name: row.name, description: row.description, commands, }; Some(command_macro) }