Skip to content

Commit

Permalink
Allow failed requests to be re-submitted
Browse files Browse the repository at this point in the history
  • Loading branch information
p0rtL6 committed Mar 18, 2024
1 parent 7727025 commit 7db0f6a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "blackcube-rs"
version = "0.2.4"
version = "0.2.5"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
56 changes: 42 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use serenity::{
prelude::GatewayIntents,
};

use crate::{responses::delete_user_request, structs::HttpClient};
use crate::{responses::send_ephemeral_interaction_followup_reply, structs::HttpClient};
struct Handler;

#[async_trait]
Expand Down Expand Up @@ -117,29 +117,57 @@ impl EventHandler for Handler {

match embed {
Some(embed) => {
let delete_result = delete_user_request(&ctx, embed).await;
let embed = embed.clone();

match delete_result {
Ok(()) => {}
Err(err) => {
println!("error deleting user request: {}", err);
let thumbnail;

match &embed.thumbnail {
Some(embed_thumbnail) => {
thumbnail = Some(embed_thumbnail.url.as_str());
}
None => {
thumbnail = None;
}
}

let url;

match &embed.url {
Some(embed_url) => {
url = Some(embed_url.as_str());
}
None => {
url = None;
}
}

let result = edit_request(
&ctx,
&mut component_interaction.message,
"Request Pending",
thumbnail,
url,
true,
)
.await;
if result.is_err() {
println!("{:?}", result);
}
}
None => {}
}

let result = edit_request(
let result = send_ephemeral_interaction_followup_reply(
&ctx,
&mut component_interaction.message,
"Failed",
None,
None,
false,
component_interaction,
"Failed to accept request",
)
.await;
if result.is_err() {
println!("{:?}", result);
match result {
Ok(()) => {}
Err(err) => {
println!("{}", err);
}
}
}
});
Expand Down
22 changes: 20 additions & 2 deletions src/responses.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use anyhow::Context as AnyhowContext;
use serenity::{
all::{ButtonStyle, Embed, InteractionResponseFlags, MessageId, UserId},
all::{ButtonStyle, Embed, InteractionResponseFlags, MessageFlags, MessageId, UserId},
builder::{
CreateActionRow, CreateButton, CreateEmbed, CreateInteractionResponse,
CreateInteractionResponseMessage, CreateMessage, EditMessage,
CreateInteractionResponseFollowup, CreateInteractionResponseMessage, CreateMessage,
EditMessage,
},
client::Context,
model::{application::ComponentInteraction, channel::Message},
Expand Down Expand Up @@ -88,6 +89,23 @@ pub async fn send_ephemeral_interaction_reply(
Ok(())
}

pub async fn send_ephemeral_interaction_followup_reply(
ctx: &Context,
component_interaction: ComponentInteraction,
message: &str,
) -> anyhow::Result<()> {
component_interaction
.create_followup(
&ctx.http,
CreateInteractionResponseFollowup::new()
.content(message)
.flags(MessageFlags::EPHEMERAL),
)
.await
.context("could not create ephemeral response")?;
Ok(())
}

pub async fn send_command_reply(
msg: Message,
ctx: Context,
Expand Down

0 comments on commit 7db0f6a

Please sign in to comment.