Wip commit
This commit is contained in:
85
src/hooks.rs
85
src/hooks.rs
@ -1,42 +1,41 @@
|
||||
use poise::{
|
||||
serenity_prelude::model::channel::Channel, ApplicationCommandOrAutocompleteInteraction,
|
||||
};
|
||||
use poise::{serenity_prelude::model::channel::Channel, CreateReply};
|
||||
|
||||
use crate::{consts::MACRO_MAX_COMMANDS, models::command_macro::RecordedCommand, Context, Error};
|
||||
|
||||
async fn macro_check(ctx: Context<'_>) -> bool {
|
||||
if let Context::Application(app_ctx) = ctx {
|
||||
if let ApplicationCommandOrAutocompleteInteraction::ApplicationCommand(_) =
|
||||
app_ctx.interaction
|
||||
{
|
||||
if let Some(guild_id) = ctx.guild_id() {
|
||||
if ctx.command().identifying_name != "finish_macro" {
|
||||
let mut lock = ctx.data().recording_macros.write().await;
|
||||
if let Some(guild_id) = ctx.guild_id() {
|
||||
if ctx.command().identifying_name != "finish_macro" {
|
||||
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(|m| {
|
||||
m.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: Vec::from(app_ctx.args),
|
||||
};
|
||||
|
||||
command_macro.commands.push(recorded);
|
||||
|
||||
let _ = ctx
|
||||
.send(|m| m.ephemeral(true).content("Command recorded to macro"))
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
let recorded = RecordedCommand {
|
||||
action: None,
|
||||
command_name: ctx.command().identifying_name.clone(),
|
||||
options: app_ctx.interaction.data.options.clone(),
|
||||
};
|
||||
|
||||
return false;
|
||||
command_macro.commands.push(recorded);
|
||||
|
||||
let _ = ctx
|
||||
.send(
|
||||
CreateReply::default()
|
||||
.ephemeral(true)
|
||||
.content("Command recorded to macro"),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -46,11 +45,13 @@ async fn macro_check(ctx: Context<'_>) -> bool {
|
||||
}
|
||||
|
||||
async fn check_self_permissions(ctx: Context<'_>) -> bool {
|
||||
if let Some(guild) = ctx.guild() {
|
||||
let user_id = ctx.serenity_context().cache.current_user_id();
|
||||
if let Some(guild_id) = ctx.guild_id() {
|
||||
let user_id = ctx.serenity_context().cache.current_user().id;
|
||||
|
||||
let manage_webhooks =
|
||||
guild.member_permissions(&ctx, user_id).await.map_or(false, |p| p.manage_webhooks());
|
||||
let manage_webhooks = guild_id
|
||||
.current_user_member(&ctx)
|
||||
.await
|
||||
.map_or(false, |m| m.permissions(&ctx).map_or(false, |p| p.manage_webhooks()));
|
||||
|
||||
let (view_channel, send_messages, embed_links) = ctx
|
||||
.channel_id()
|
||||
@ -72,20 +73,18 @@ async fn check_self_permissions(ctx: Context<'_>) -> bool {
|
||||
true
|
||||
} else {
|
||||
let _ = ctx
|
||||
.send(|m| {
|
||||
m.content(format!(
|
||||
"Please ensure the bot has the correct permissions:
|
||||
.send(CreateReply::default().content(format!(
|
||||
"Please ensure the bot has the correct permissions:
|
||||
|
||||
{} **View Channel**
|
||||
{} **Send Message**
|
||||
{} **Embed Links**
|
||||
{} **Manage Webhooks**",
|
||||
if view_channel { "✅" } else { "❌" },
|
||||
if send_messages { "✅" } else { "❌" },
|
||||
if embed_links { "✅" } else { "❌" },
|
||||
if manage_webhooks { "✅" } else { "❌" },
|
||||
))
|
||||
})
|
||||
if view_channel { "✅" } else { "❌" },
|
||||
if send_messages { "✅" } else { "❌" },
|
||||
if embed_links { "✅" } else { "❌" },
|
||||
if manage_webhooks { "✅" } else { "❌" },
|
||||
)))
|
||||
.await;
|
||||
|
||||
false
|
||||
|
Reference in New Issue
Block a user