Add remaining commands

This commit is contained in:
jude
2024-02-18 14:32:58 +00:00
parent 76a286076b
commit d8f266852a
25 changed files with 655 additions and 367 deletions

View File

@ -1,4 +1,43 @@
use crate::{models::CtxData, Context, Error};
use serde::{Deserialize, Serialize};
use crate::{
models::CtxData,
utils::{Extract, Recordable},
Context, Error,
};
#[derive(Serialize, Deserialize, Extract)]
pub struct Options {
task: String,
}
impl Recordable for Options {
async fn run(self, ctx: Context<'_>) -> Result<(), Error> {
// ensure channel is cached
ctx.channel_data().await?;
sqlx::query!(
"
INSERT INTO todos (guild_id, channel_id, value)
VALUES (
(SELECT id FROM guilds WHERE guild = ?),
(SELECT id FROM channels WHERE channel = ?),
?
)
",
ctx.guild_id().unwrap().get(),
ctx.channel_id().get(),
self.task
)
.execute(&ctx.data().database)
.await
.unwrap();
ctx.say("Item added to todo list").await?;
Ok(())
}
}
/// Add an item to the channel todo list
#[poise::command(
@ -12,27 +51,5 @@ pub async fn add(
ctx: Context<'_>,
#[description = "The task to add to the todo list"] task: String,
) -> Result<(), Error> {
// ensure channel is cached
let _ = ctx.channel_data().await;
sqlx::query!(
"
INSERT INTO todos (guild_id, channel_id, value)
VALUES (
(SELECT id FROM guilds WHERE guild = ?),
(SELECT id FROM channels WHERE channel = ?),
?
)
",
ctx.guild_id().unwrap().get(),
ctx.channel_id().get(),
task
)
.execute(&ctx.data().database)
.await
.unwrap();
ctx.say("Item added to todo list").await?;
Ok(())
(Options { task }).run(ctx).await
}