39 lines
942 B
Rust
39 lines
942 B
Rust
use crate::{commands::todo::show_todo_page, Context, Error};
|
|
|
|
/// View and remove from the channel todo list
|
|
#[poise::command(
|
|
slash_command,
|
|
rename = "view",
|
|
guild_only = true,
|
|
identifying_name = "todo_channel_view",
|
|
default_member_permissions = "MANAGE_GUILD"
|
|
)]
|
|
pub async fn view(ctx: Context<'_>) -> Result<(), Error> {
|
|
let values = sqlx::query!(
|
|
"
|
|
SELECT todos.id, value FROM todos
|
|
INNER JOIN channels ON todos.channel_id = channels.id
|
|
WHERE channels.channel = ?
|
|
",
|
|
ctx.channel_id().get(),
|
|
)
|
|
.fetch_all(&ctx.data().database)
|
|
.await
|
|
.unwrap()
|
|
.iter()
|
|
.map(|row| (row.id as usize, row.value.clone()))
|
|
.collect::<Vec<(usize, String)>>();
|
|
|
|
let resp = show_todo_page(
|
|
&values,
|
|
0,
|
|
None,
|
|
Some(ctx.channel_id().get()),
|
|
ctx.guild_id().map(|g| g.get()),
|
|
);
|
|
|
|
ctx.send(resp).await?;
|
|
|
|
Ok(())
|
|
}
|