Add option types for top-level commands

This commit is contained in:
jude committed 2024-02-18 11:04:43 +00:00
1 parent c1305cfb36
commit 5e39e16060
22 files changed
+395 -268

No files matched your search

+24 -20
View File
@@ -6,6 +6,7 @@ use poise::{
},
CreateReply,
};
use serde::{Deserialize, Serialize};
use crate::{
component_models::{
@@ -14,29 +15,10 @@ use crate::{
},
consts::{EMBED_DESCRIPTION_MAX_LENGTH, SELECT_MAX_ENTRIES, THEME_COLOR},
models::{reminder::Reminder, CtxData},
utils::Extract,
Context, Error,
};
/// Delete reminders
#[poise::command(
slash_command,
rename = "del",
identifying_name = "delete",
default_member_permissions = "MANAGE_GUILD"
)]
pub async fn delete(ctx: Context<'_>) -> Result<(), Error> {
let timezone = ctx.timezone().await;
let reminders =
Reminder::from_guild(&ctx, &ctx.data().database, ctx.guild_id(), ctx.author().id).await;
let resp = show_delete_page(&reminders, 0, timezone);
ctx.send(resp).await?;
Ok(())
}
pub fn max_delete_page(reminders: &[Reminder], timezone: &Tz) -> usize {
let mut rows = 0;
let mut char_count = 0;
@@ -154,3 +136,25 @@ pub fn show_delete_page(reminders: &[Reminder], page: usize, timezone: Tz) -> Cr
.embed(embed)
.components(vec![pager.create_button_row(pages), CreateActionRow::SelectMenu(select_menu)])
}
#[derive(Serialize, Deserialize, Extract)]
pub struct Options;
pub async fn delete(ctx: Context<'_>, _options: Options) -> Result<(), Error> {
let timezone = ctx.timezone().await;
let reminders =
Reminder::from_guild(&ctx, &ctx.data().database, ctx.guild_id(), ctx.author().id).await;
let resp = show_delete_page(&reminders, 0, timezone);
ctx.send(resp).await?;
Ok(())
}
/// Delete reminders
#[poise::command(slash_command, rename = "del", default_member_permissions = "MANAGE_GUILD")]
pub async fn command(ctx: Context<'_>) -> Result<(), Error> {
delete(ctx, Options {}).await
}