Add macro install command stub
This commit is contained in:
parent
8f8235a86e
commit
e2bf23f194
38
src/commands/command_macro/install.rs
Normal file
38
src/commands/command_macro/install.rs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
use poise::serenity_prelude::CommandType;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
commands::autocomplete::macro_name_autocomplete, models::command_macro::guild_command_macro,
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Add a macro as a slash-command to this server. Enables controlling permissions per-macro.
|
||||||
|
#[poise::command(
|
||||||
|
slash_command,
|
||||||
|
rename = "install",
|
||||||
|
guild_only = true,
|
||||||
|
default_member_permissions = "MANAGE_GUILD",
|
||||||
|
identifying_name = "install_macro"
|
||||||
|
)]
|
||||||
|
pub async fn install_macro(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
#[description = "Name of macro to install"]
|
||||||
|
#[autocomplete = "macro_name_autocomplete"]
|
||||||
|
name: String,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
|
if let Some(command_macro) = guild_command_macro(&ctx, &name).await {
|
||||||
|
guild_id
|
||||||
|
.create_application_command(&ctx.discord(), |a| {
|
||||||
|
a.kind(CommandType::ChatInput)
|
||||||
|
.name(command_macro.name)
|
||||||
|
.description(command_macro.description.unwrap_or_else(|| "".to_string()))
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
ctx.send(|r| r.ephemeral(true).content("Macro installed. Go to Server Settings 🠚 Integrations 🠚 Reminder Bot to configure permissions.")).await?;
|
||||||
|
} else {
|
||||||
|
ctx.send(|r| r.ephemeral(true).content("No macro found with that name")).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
|
|
||||||
pub mod delete;
|
pub mod delete;
|
||||||
|
pub mod install;
|
||||||
pub mod list;
|
pub mod list;
|
||||||
pub mod migrate;
|
pub mod migrate;
|
||||||
pub mod record;
|
pub mod record;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
mod autocomplete;
|
pub mod autocomplete;
|
||||||
pub mod command_macro;
|
pub mod command_macro;
|
||||||
pub mod info_cmds;
|
pub mod info_cmds;
|
||||||
pub mod moderation_cmds;
|
pub mod moderation_cmds;
|
||||||
|
12
src/hooks.rs
12
src/hooks.rs
@ -1,9 +1,14 @@
|
|||||||
use poise::serenity_prelude::model::channel::Channel;
|
use poise::{
|
||||||
|
serenity_prelude::model::channel::Channel, ApplicationCommandOrAutocompleteInteraction,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{consts::MACRO_MAX_COMMANDS, models::command_macro::RecordedCommand, Context, Error};
|
use crate::{consts::MACRO_MAX_COMMANDS, models::command_macro::RecordedCommand, Context, Error};
|
||||||
|
|
||||||
async fn macro_check(ctx: Context<'_>) -> bool {
|
async fn recording_macro_check(ctx: Context<'_>) -> bool {
|
||||||
if let Context::Application(app_ctx) = ctx {
|
if let Context::Application(app_ctx) = ctx {
|
||||||
|
if let ApplicationCommandOrAutocompleteInteraction::ApplicationCommand(_) =
|
||||||
|
app_ctx.interaction
|
||||||
|
{
|
||||||
if let Some(guild_id) = ctx.guild_id() {
|
if let Some(guild_id) = ctx.guild_id() {
|
||||||
if ctx.command().identifying_name != "finish_macro" {
|
if ctx.command().identifying_name != "finish_macro" {
|
||||||
let mut lock = ctx.data().recording_macros.write().await;
|
let mut lock = ctx.data().recording_macros.write().await;
|
||||||
@ -35,6 +40,7 @@ async fn macro_check(ctx: Context<'_>) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
@ -89,5 +95,5 @@ async fn check_self_permissions(ctx: Context<'_>) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn all_checks(ctx: Context<'_>) -> Result<bool, Error> {
|
pub async fn all_checks(ctx: Context<'_>) -> Result<bool, Error> {
|
||||||
Ok(macro_check(ctx).await && check_self_permissions(ctx).await)
|
Ok(recording_macro_check(ctx).await && check_self_permissions(ctx).await)
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,7 @@ async fn _main(tx: Sender<()>) -> Result<(), Box<dyn StdError + Send + Sync>> {
|
|||||||
command_macro::record::record_macro(),
|
command_macro::record::record_macro(),
|
||||||
command_macro::run::run_macro(),
|
command_macro::run::run_macro(),
|
||||||
command_macro::migrate::migrate_macro(),
|
command_macro::migrate::migrate_macro(),
|
||||||
|
command_macro::install::install_macro(),
|
||||||
],
|
],
|
||||||
..command_macro::macro_base()
|
..command_macro::macro_base()
|
||||||
},
|
},
|
||||||
|
@ -37,6 +37,7 @@ pub struct RawCommandMacro {
|
|||||||
pub commands: Value,
|
pub commands: Value,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get a macro by name form a guild.
|
||||||
pub async fn guild_command_macro(
|
pub async fn guild_command_macro(
|
||||||
ctx: &Context<'_>,
|
ctx: &Context<'_>,
|
||||||
name: &str,
|
name: &str,
|
||||||
|
Loading…
Reference in New Issue
Block a user