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,37 @@
use crate::{Context, Error};
use serde::{Deserialize, Serialize};
use crate::{
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> {
sqlx::query!(
"
INSERT INTO todos (user_id, value)
VALUES (
(SELECT id FROM users WHERE user = ?),
?
)
",
ctx.author().id.get(),
self.task
)
.execute(&ctx.data().database)
.await
.unwrap();
ctx.say("Item added to todo list").await?;
Ok(())
}
}
/// Add an item to your personal todo list
#[poise::command(slash_command, rename = "add", identifying_name = "todo_user_add")]
@ -6,22 +39,5 @@ pub async fn add(
ctx: Context<'_>,
#[description = "The task to add to the todo list"] task: String,
) -> Result<(), Error> {
sqlx::query!(
"
INSERT INTO todos (user_id, value)
VALUES (
(SELECT id FROM users WHERE user = ?),
?
)
",
ctx.author().id.get(),
task
)
.execute(&ctx.data().database)
.await
.unwrap();
ctx.say("Item added to todo list").await?;
Ok(())
(Options { task }).run(ctx).await
}