macro stuff
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
use serenity::model::id::GuildId;
|
||||
use serenity::{client::Context, model::id::GuildId};
|
||||
|
||||
use crate::framework::CommandOptions;
|
||||
use crate::{framework::CommandOptions, SQLPool};
|
||||
|
||||
pub struct CommandMacro {
|
||||
pub guild_id: GuildId,
|
||||
@ -8,3 +8,23 @@ pub struct CommandMacro {
|
||||
pub description: Option<String>,
|
||||
pub commands: Vec<CommandOptions>,
|
||||
}
|
||||
|
||||
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>>()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user