Skip to content

Commit

Permalink
Merge pull request #49 from stifskere/main
Browse files Browse the repository at this point in the history
feat: save github embeds
  • Loading branch information
SergioRibera authored Dec 30, 2024
2 parents 49f63f7 + 3f96d9e commit 120e094
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/bot/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ pub async fn handle(
FullEvent::InteractionCreate { interaction } => {
// for buttons
if let Some (interaction) = interaction.as_message_component() {
if read_github_links::handle_delete_embed(ctx, interaction).await {

if
read_github_links::handle_delete_embed(ctx, interaction).await
|| read_github_links::handle_save_embed(ctx, interaction).await
{
return Ok(());
}
}
}
Expand Down
56 changes: 54 additions & 2 deletions src/bot/events/read_github_links.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use lazy_static::lazy_static;
use poise::serenity_prelude::{ButtonStyle, ComponentInteraction, Context, CreateButton, CreateInteractionResponse, CreateInteractionResponseMessage, CreateMessage, Message, MESSAGE_CODE_LIMIT};
use poise::serenity_prelude::{ButtonStyle, ComponentInteraction, Context, CreateButton, CreateInteractionResponse, CreateInteractionResponseMessage, CreateMessage, Message, ReactionType, MESSAGE_CODE_LIMIT};
use regex::{Captures, Regex};
use reqwest::get;
use tracing::info;
use std::collections::{HashMap, HashSet};
use std::option::Option;

Expand Down Expand Up @@ -182,6 +181,13 @@ pub async fn message(ctx: &Context, msg: &Message) -> bool {
CreateButton::new("delete_github_embed")
.label("Borrar")
.style(ButtonStyle::Danger)
.emoji(ReactionType::try_from("🗑️").unwrap())
)
.button(
CreateButton::new("save_github_embed")
.label("Guardar")
.style(ButtonStyle::Secondary)
.emoji(ReactionType::try_from("💾").unwrap())
);

if let Some(reference) = &msg.message_reference {
Expand Down Expand Up @@ -236,3 +242,49 @@ pub async fn handle_delete_embed(ctx: &Context, interaction: &ComponentInteracti

true
}

pub async fn handle_save_embed(ctx: &Context, interaction: &ComponentInteraction) -> bool {
if interaction.data.custom_id != "save_github_embed" {
return false;
}

let send_result = interaction
.user
.dm(
ctx,
CreateMessage::new()
.content(
interaction
.message
.content
.clone()
.replacen("Mostrando", "El codigo que solicitaste:", 1)
)
)
.await;

match send_result {
Ok(_) => interaction
.create_response(
ctx,
CreateInteractionResponse::Message(
CreateInteractionResponseMessage::new()
.content("Enviado. Revisa tus mensajes directos con el bot.")
.ephemeral(true)
)
),
Err(err) => interaction
.create_response(
ctx,
CreateInteractionResponse::Message(
CreateInteractionResponseMessage::new()
.content(format!("Error: {err}"))
.ephemeral(true)
)
)
}
.await
.ok();

return true;
}

0 comments on commit 120e094

Please sign in to comment.