Refactor macros
This commit is contained in:
31
src/hooks.rs
31
src/hooks.rs
@ -6,24 +6,31 @@ async fn macro_check(ctx: Context<'_>) -> bool {
|
||||
if let Context::Application(app_ctx) = ctx {
|
||||
if let Some(guild_id) = ctx.guild_id() {
|
||||
if ctx.command().identifying_name != "finish_macro" {
|
||||
if ctx.command().identifying_name != "remind" {
|
||||
let _ = ctx
|
||||
.send(
|
||||
CreateReply::default()
|
||||
.ephemeral(true)
|
||||
.content("Macro recording only supports `/remind`. Please stop recording with `/macro finish` before using other commands.")
|
||||
)
|
||||
.await;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
let mut lock = ctx.data().recording_macros.write().await;
|
||||
|
||||
if let Some(command_macro) = lock.get_mut(&(guild_id, ctx.author().id)) {
|
||||
if command_macro.commands.len() >= MACRO_MAX_COMMANDS {
|
||||
let _ = ctx
|
||||
.send(
|
||||
CreateReply::default()
|
||||
.ephemeral(true)
|
||||
.content(format!("{} commands already recorded. Please use `/macro finish` to end recording.", MACRO_MAX_COMMANDS))
|
||||
)
|
||||
.await;
|
||||
.send(
|
||||
CreateReply::default()
|
||||
.ephemeral(true)
|
||||
.content(format!("{} commands already recorded. Please use `/macro finish` to end recording.", MACRO_MAX_COMMANDS))
|
||||
)
|
||||
.await;
|
||||
} else {
|
||||
let recorded = RecordedCommand {
|
||||
action: None,
|
||||
command_name: ctx.command().identifying_name.clone(),
|
||||
options: app_ctx.interaction.data.options.clone(),
|
||||
};
|
||||
|
||||
let recorded = RecordedCommand::from_context(app_ctx).unwrap();
|
||||
command_macro.commands.push(recorded);
|
||||
|
||||
let _ = ctx
|
||||
|
Reference in New Issue
Block a user