Add remaining commands
This commit is contained in:
@ -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
|
||||
}
|
||||
|
@ -1,4 +1,44 @@
|
||||
use crate::{commands::todo::show_todo_page, Context, Error};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::todo::show_todo_page,
|
||||
utils::{Extract, Recordable},
|
||||
Context, Error,
|
||||
};
|
||||
|
||||
#[derive(Serialize, Deserialize, Extract)]
|
||||
pub struct Options;
|
||||
|
||||
impl Recordable for Options {
|
||||
async fn run(self, 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(())
|
||||
}
|
||||
}
|
||||
|
||||
/// View and remove from the channel todo list
|
||||
#[poise::command(
|
||||
@ -9,30 +49,5 @@ use crate::{commands::todo::show_todo_page, Context, Error};
|
||||
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(())
|
||||
(Options {}).run(ctx).await
|
||||
}
|
||||
|
@ -1,4 +1,36 @@
|
||||
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 (guild_id, value)
|
||||
VALUES (
|
||||
(SELECT id FROM guilds WHERE guild = ?), ?
|
||||
)
|
||||
",
|
||||
ctx.guild_id().unwrap().get(),
|
||||
self.task
|
||||
)
|
||||
.execute(&ctx.data().database)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
ctx.say("Item added to todo list").await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Add an item to the server todo list
|
||||
#[poise::command(
|
||||
@ -12,20 +44,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 (guild_id, value)
|
||||
VALUES (
|
||||
(SELECT id FROM guilds WHERE guild = ?), ?
|
||||
)",
|
||||
ctx.guild_id().unwrap().get(),
|
||||
task
|
||||
)
|
||||
.execute(&ctx.data().database)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
ctx.say("Item added to todo list").await?;
|
||||
|
||||
Ok(())
|
||||
(Options { task }).run(ctx).await
|
||||
}
|
||||
|
@ -1,4 +1,38 @@
|
||||
use crate::{commands::todo::show_todo_page, Context, Error};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::todo::show_todo_page,
|
||||
utils::{Extract, Recordable},
|
||||
Context, Error,
|
||||
};
|
||||
|
||||
#[derive(Serialize, Deserialize, Extract)]
|
||||
pub struct Options;
|
||||
|
||||
impl Recordable for Options {
|
||||
async fn run(self, ctx: Context<'_>) -> Result<(), Error> {
|
||||
let values = sqlx::query!(
|
||||
"
|
||||
SELECT todos.id, value FROM todos
|
||||
INNER JOIN guilds ON todos.guild_id = guilds.id
|
||||
WHERE guilds.guild = ?
|
||||
",
|
||||
ctx.guild_id().unwrap().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, None, ctx.guild_id().map(|g| g.get()));
|
||||
|
||||
ctx.send(resp).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// View and remove from the server todo list
|
||||
#[poise::command(
|
||||
@ -9,24 +43,5 @@ use crate::{commands::todo::show_todo_page, Context, Error};
|
||||
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 guilds ON todos.guild_id = guilds.id
|
||||
WHERE guilds.guild = ?
|
||||
",
|
||||
ctx.guild_id().unwrap().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, None, ctx.guild_id().map(|g| g.get()));
|
||||
|
||||
ctx.send(resp).await?;
|
||||
|
||||
Ok(())
|
||||
(Options {}).run(ctx).await
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -1,26 +1,41 @@
|
||||
use crate::{commands::todo::show_todo_page, Context, Error};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::todo::show_todo_page,
|
||||
utils::{Extract, Recordable},
|
||||
Context, Error,
|
||||
};
|
||||
|
||||
#[derive(Serialize, Deserialize, Extract)]
|
||||
pub struct Options;
|
||||
|
||||
impl Recordable for Options {
|
||||
async fn run(self, ctx: Context<'_>) -> Result<(), Error> {
|
||||
let values = sqlx::query!(
|
||||
"
|
||||
SELECT todos.id, value FROM todos
|
||||
INNER JOIN users ON todos.user_id = users.id
|
||||
WHERE users.user = ?
|
||||
",
|
||||
ctx.author().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, Some(ctx.author().id.get()), None, None);
|
||||
|
||||
ctx.send(resp).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// View and remove from your personal todo list
|
||||
#[poise::command(slash_command, rename = "view", identifying_name = "todo_user_view")]
|
||||
pub async fn view(ctx: Context<'_>) -> Result<(), Error> {
|
||||
let values = sqlx::query!(
|
||||
"
|
||||
SELECT todos.id, value FROM todos
|
||||
INNER JOIN users ON todos.user_id = users.id
|
||||
WHERE users.user = ?
|
||||
",
|
||||
ctx.author().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, Some(ctx.author().id.get()), None, None);
|
||||
|
||||
ctx.send(resp).await?;
|
||||
|
||||
Ok(())
|
||||
(Options {}).run(ctx).await
|
||||
}
|
||||
|
Reference in New Issue
Block a user