Add option types for top-level commands

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

View File

@ -1,5 +1,5 @@
use poise::{
serenity_prelude::{model::id::ChannelId, Channel, CreateEmbed, CreateEmbedFooter},
serenity_prelude::{model::id::ChannelId, CreateEmbed, CreateEmbedFooter, PartialChannel},
CreateReply,
};
use serde::{Deserialize, Serialize};
@ -9,17 +9,18 @@ use crate::{
component_models::pager::{LookPager, Pager},
consts::{EMBED_DESCRIPTION_MAX_LENGTH, THEME_COLOR},
models::{reminder::Reminder, CtxData},
utils::Extract,
Context, Error,
};
#[derive(Serialize_repr, Deserialize_repr, Copy, Clone, Debug)]
#[derive(Serialize_repr, Deserialize_repr, Copy, Clone)]
#[repr(u8)]
pub enum TimeDisplayType {
Absolute = 0,
Relative = 1,
}
#[derive(Serialize, Deserialize, Copy, Clone, Debug)]
#[derive(Serialize, Deserialize, Copy, Clone)]
pub struct LookFlags {
pub show_disabled: bool,
pub channel_id: Option<ChannelId>,
@ -32,24 +33,20 @@ impl Default for LookFlags {
}
}
/// View reminders on a specific channel
#[poise::command(
slash_command,
identifying_name = "look",
default_member_permissions = "MANAGE_GUILD"
)]
pub async fn look(
ctx: Context<'_>,
#[description = "Channel to view reminders on"] channel: Option<Channel>,
#[description = "Whether to show disabled reminders or not"] disabled: Option<bool>,
#[description = "Whether to display times as relative or exact times"] relative: Option<bool>,
) -> Result<(), Error> {
#[derive(Serialize, Deserialize, Extract)]
pub struct Options {
channel: Option<PartialChannel>,
disabled: Option<bool>,
relative: Option<bool>,
}
pub async fn look(ctx: Context<'_>, options: Options) -> Result<(), Error> {
let timezone = ctx.timezone().await;
let flags = LookFlags {
show_disabled: disabled.unwrap_or(true),
channel_id: channel.map(|c| c.id()),
time_display: relative.map_or(TimeDisplayType::Relative, |b| {
show_disabled: options.disabled.unwrap_or(true),
channel_id: options.channel.map(|c| c.id),
time_display: options.relative.map_or(TimeDisplayType::Relative, |b| {
if b {
TimeDisplayType::Relative
} else {
@ -117,3 +114,14 @@ pub async fn look(
Ok(())
}
/// View reminders on a specific channel
#[poise::command(slash_command, rename = "look", default_member_permissions = "MANAGE_GUILD")]
pub async fn command(
ctx: Context<'_>,
#[description = "Channel to view reminders on"] channel: Option<PartialChannel>,
#[description = "Whether to show disabled reminders or not"] disabled: Option<bool>,
#[description = "Whether to display times as relative or exact times"] relative: Option<bool>,
) -> Result<(), Error> {
look(ctx, Options { channel, disabled, relative }).await
}