2021-10-16 18:18:16 +00:00
|
|
|
use serenity::{client::Context, model::id::GuildId};
|
2021-09-22 20:12:29 +00:00
|
|
|
|
2021-10-16 18:18:16 +00:00
|
|
|
use crate::{framework::CommandOptions, SQLPool};
|
2021-09-22 20:12:29 +00:00
|
|
|
|
|
|
|
pub struct CommandMacro {
|
|
|
|
pub guild_id: GuildId,
|
|
|
|
pub name: String,
|
|
|
|
pub description: Option<String>,
|
|
|
|
pub commands: Vec<CommandOptions>,
|
|
|
|
}
|
2021-10-16 18:18:16 +00:00
|
|
|
|
|
|
|
impl CommandMacro {
|
|
|
|
pub async fn from_guild(ctx: &Context, guild_id: impl Into<GuildId>) -> Vec<Self> {
|
|
|
|
let pool = ctx.data.read().await.get::<SQLPool>().cloned().unwrap();
|
|
|
|
let guild_id = guild_id.into();
|
|
|
|
|
|
|
|
sqlx::query!("SELECT * FROM macro WHERE guild_id = ?", guild_id.0)
|
|
|
|
.fetch_all(&pool)
|
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
.iter()
|
|
|
|
.map(|row| Self {
|
|
|
|
guild_id: GuildId(row.guild_id),
|
|
|
|
name: row.name.clone(),
|
|
|
|
description: row.description.clone(),
|
|
|
|
commands: serde_json::from_str(&row.commands).unwrap(),
|
|
|
|
})
|
|
|
|
.collect::<Vec<Self>>()
|
|
|
|
}
|
|
|
|
}
|