Skip to content

Commit

Permalink
fix interaction failure bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbt365 committed Apr 29, 2024
1 parent 4b06939 commit 3801adc
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ serde_json = { version = "1.0" }

# Discord API
poise = { git = "https://github.com/serenity-rs/poise.git", branch = "current" }
serenity = {version = "0.12", default-features = false, features = ["cache", "client", "gateway", "rustls_backend", "model", "framework", "standard_framework"] }
serenity = {version = "0.12" }
tokio = { version = "1.29.1", features = ["macros", "signal", "rt-multi-thread"] }

# Misc
Expand Down
15 changes: 9 additions & 6 deletions src/commands/snippets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,10 @@ async fn remove_snippet_confirm(ctx: &Context<'_>, snippet: &Snippet) -> Result<
]);

let builder: poise::CreateReply = poise::CreateReply::default()
.content(format!("Are you sure you want to delete snippet `{}`?", snippet.id))
.content(format!(
"Are you sure you want to delete snippet `{}`?",
snippet.id
))
.ephemeral(true)
.embed(snippet_embed)
.components(vec![components]);
Expand All @@ -321,22 +324,22 @@ async fn handle_delete(
snippet: &Snippet,
interaction: serenity::ComponentInteraction,
) -> Result<(), Error> {

rm_snippet(ctx, snippet).await;
interaction
.create_response(
ctx,
CreateInteractionResponse::UpdateMessage(
CreateInteractionResponseMessage::new().content("Deleted!")
CreateInteractionResponseMessage::new()
.content("Deleted!")
.embeds(vec![])
.components(vec![]),
),
)
.await?;

let title = format!("{} removed a snippet", ctx.author().tag());
let content = &&format!("Removed snippet `{}`", snippet.format_output());
respond_ok(ctx, &title, content).await;
let title = format!("{} removed a snippet", ctx.author().tag());
let content = &&format!("Removed snippet `{}`", snippet.format_output());
respond_ok(ctx, &title, content).await;

Ok(())
}
Expand Down
97 changes: 49 additions & 48 deletions src/events/issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use ::serenity::builder::CreateEmbedAuthor;
use octocrab::models::issues::Issue;
use octocrab::models::pulls::PullRequest;
use poise::serenity_prelude::{
self as serenity, ButtonStyle, Colour, Context, CreateActionRow, CreateButton, CreateEmbed,
CreateInteractionResponse, Message, Permissions,
self as serenity, ButtonStyle, Colour, Context, CreateActionRow,
CreateButton, CreateEmbed, CreateInteractionResponse, Message, Permissions
};
use regex::Regex;

Expand Down Expand Up @@ -49,65 +49,65 @@ pub async fn message(data: &Data, ctx: &Context, message: &Message) {
.timeout(Duration::from_secs(60))
.await
{
// Safe to unwap member because this only runs in guilds.
// The only way this could go wrong if cache isn't ready? (fresh bot restart)
let has_perms = press.member.as_ref().map_or(false, |member| {
member.permissions.map_or(false, |member_perms| {
member_perms.contains(Permissions::MANAGE_MESSAGES)
})
});

if press.data.custom_id == remove_id
&& (press.user.id == message.author.id || has_perms)
{
let _ = press
.create_response(ctx, CreateInteractionResponse::Acknowledge)


if press.data.custom_id == remove_id {
if press.user.id == message.author.id || has_perms {
let _ = press
.create_response(ctx, CreateInteractionResponse::Acknowledge)
.await;
if let Ok(ref msg) = msg_result {
let _ = msg.delete(ctx).await;
}
msg_deleted = true;
} else {
interaction_err(
ctx,
&press,
"Unable to use interaction because you are missing `MANAGE_MESSAGES`.",
)
.await;
if let Ok(ref msg) = msg_result {
let _ = msg.delete(ctx).await;
}
msg_deleted = true;
} else {
interaction_err(
ctx,
&press,
"Unable to use interaction because you are missing `MANAGE_MESSAGES`.",
)
.await;
}

if press.data.custom_id == hide_body_id
&& (press.user.id == message.author.id || has_perms)
{
if !body_hid {
let mut hid_body_embeds: Vec<CreateEmbed> = Vec::new();
if let Ok(ref msg) = msg_result {
for mut embed in msg.embeds.clone() {
embed.description = None;
let embed: CreateEmbed = embed.clone().into();
hid_body_embeds.push(embed);
if press.data.custom_id == hide_body_id {
if press.user.id == message.author.id || has_perms {
if !body_hid {
let mut hid_body_embeds: Vec<CreateEmbed> = Vec::new();
if let Ok(ref msg) = msg_result {
for mut embed in msg.embeds.clone() {
embed.description = None;
let embed: CreateEmbed = embed.clone().into();
hid_body_embeds.push(embed);
}
}
}

let _ = press
.create_response(
ctx,
serenity::CreateInteractionResponse::UpdateMessage(
serenity::CreateInteractionResponseMessage::new()
.embeds(hid_body_embeds)
.components(vec![remove.clone()]),
),
)
.await;
let _ = press
.create_response(
ctx,
serenity::CreateInteractionResponse::UpdateMessage(
serenity::CreateInteractionResponseMessage::new()
.embeds(hid_body_embeds)
.components(vec![remove.clone()]),
),
)
.await;
}
body_hid = true;
} else {
interaction_err(
ctx,
&press,
"Unable to use interaction because you are missing `MANAGE_MESSAGES`.",
)
.await;
}
body_hid = true;
} else {
interaction_err(
ctx,
&press,
"Unable to use interaction because you are missing `MANAGE_MESSAGES`.",
)
.await;
}
}
// Triggers on timeout.
Expand All @@ -121,6 +121,7 @@ pub async fn message(data: &Data, ctx: &Context, message: &Message) {
}
}


async fn issue_embeds(data: &Data, message: &Message) -> Option<Vec<CreateEmbed>> {
let mut embeds: Vec<CreateEmbed> = vec![];
let client = octocrab::instance();
Expand Down

0 comments on commit 3801adc

Please sign in to comment.