Link all top-level commands with macro recording/replaying logic
This commit is contained in:
@ -2,29 +2,64 @@ use poise::serenity_prelude::model::id::GuildId;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::{commands::remind, utils::Extract, ApplicationContext, Context, Error};
|
||||
use crate::{
|
||||
utils::{Extract, Recordable},
|
||||
ApplicationContext, Context,
|
||||
};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, Recordable)]
|
||||
#[serde(tag = "command_name")]
|
||||
pub enum RecordedCommand {
|
||||
Remind(remind::Options),
|
||||
#[serde(rename = "clock")]
|
||||
Clock(crate::commands::clock::Options),
|
||||
#[serde(rename = "dashboard")]
|
||||
Dashboard(crate::commands::dashboard::Options),
|
||||
#[serde(rename = "delete")]
|
||||
Delete(crate::commands::delete::Options),
|
||||
#[serde(rename = "donate")]
|
||||
Donate(crate::commands::donate::Options),
|
||||
#[serde(rename = "help")]
|
||||
Help(crate::commands::help::Options),
|
||||
#[serde(rename = "info")]
|
||||
Info(crate::commands::info::Options),
|
||||
#[serde(rename = "look")]
|
||||
Look(crate::commands::look::Options),
|
||||
#[serde(rename = "multiline")]
|
||||
Multiline(crate::commands::multiline::Options),
|
||||
#[serde(rename = "nudge")]
|
||||
Nudge(crate::commands::nudge::Options),
|
||||
#[serde(rename = "offset")]
|
||||
Offset(crate::commands::offset::Options),
|
||||
#[serde(rename = "pause")]
|
||||
Pause(crate::commands::pause::Options),
|
||||
#[serde(rename = "remind")]
|
||||
Remind(crate::commands::remind::Options),
|
||||
#[serde(rename = "timezone")]
|
||||
Timezone(crate::commands::timezone::Options),
|
||||
#[serde(rename = "webhook")]
|
||||
Webhook(crate::commands::webhook::Options),
|
||||
}
|
||||
|
||||
impl RecordedCommand {
|
||||
pub fn from_context(ctx: ApplicationContext) -> Option<Self> {
|
||||
match ctx.command().identifying_name.as_str() {
|
||||
"remind" => Some(Self::Remind(remind::Options::extract(ctx))),
|
||||
"clock" => Some(Self::Clock(crate::commands::clock::Options::extract(ctx))),
|
||||
"dashboard" => Some(Self::Dashboard(crate::commands::dashboard::Options::extract(ctx))),
|
||||
"delete" => Some(Self::Delete(crate::commands::delete::Options::extract(ctx))),
|
||||
"donate" => Some(Self::Donate(crate::commands::donate::Options::extract(ctx))),
|
||||
"help" => Some(Self::Help(crate::commands::help::Options::extract(ctx))),
|
||||
"info" => Some(Self::Info(crate::commands::info::Options::extract(ctx))),
|
||||
"look" => Some(Self::Look(crate::commands::look::Options::extract(ctx))),
|
||||
"multiline" => Some(Self::Multiline(crate::commands::multiline::Options::extract(ctx))),
|
||||
"nudge" => Some(Self::Nudge(crate::commands::nudge::Options::extract(ctx))),
|
||||
"offset" => Some(Self::Offset(crate::commands::offset::Options::extract(ctx))),
|
||||
"pause" => Some(Self::Pause(crate::commands::pause::Options::extract(ctx))),
|
||||
"remind" => Some(Self::Remind(crate::commands::remind::Options::extract(ctx))),
|
||||
"timezone" => Some(Self::Timezone(crate::commands::timezone::Options::extract(ctx))),
|
||||
"webhook" => Some(Self::Webhook(crate::commands::webhook::Options::extract(ctx))),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn execute(self, ctx: ApplicationContext<'_>) -> Result<(), Error> {
|
||||
match self {
|
||||
RecordedCommand::Remind(options) => {
|
||||
remind::remind(Context::Application(ctx), options).await
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CommandMacro {
|
||||
|
Reference in New Issue
Block a user