* Made todo added responses ephemeral if /settings ephemeral is on * Enabled systemd watchdog * Move metrics to rocket
52 lines
1.3 KiB
Rust
52 lines
1.3 KiB
Rust
use poise::CreateReply;
|
|
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> {
|
|
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();
|
|
|
|
let ephemeral = ctx
|
|
.guild_data()
|
|
.await
|
|
.map_or(false, |gr| gr.map_or(false, |g| g.ephemeral_confirmations));
|
|
|
|
ctx.send(CreateReply::default().content("Item added to todo list").ephemeral(ephemeral))
|
|
.await?;
|
|
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
/// Add an item to your personal todo list
|
|
#[poise::command(slash_command, rename = "add", identifying_name = "todo_user_add")]
|
|
pub async fn add(
|
|
ctx: Context<'_>,
|
|
#[description = "The task to add to the todo list"] task: String,
|
|
) -> Result<(), Error> {
|
|
(Options { task }).run(ctx).await
|
|
}
|