[no description]
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 00aff29..0c561c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,8 @@ use anyhow::Result; use fimg::scale::{Lanczos3, Nearest}; use fimg::{Image, WritePng}; use gif::Frame; +use poise::CreateReply; +use poise::samples::register_globally; use regex::Regex; use serenity::all::*; @@ -51,7 +53,7 @@ pub async fn spawn() { let tok = include_str!("../token"); let f = poise::Framework::<(), anyhow::Error>::builder() .options(poise::FrameworkOptions { - commands: vec![], + commands: vec![resize()], event_handler: |c, e, _, ()| { Box::pin(async move { match e { @@ -105,8 +107,9 @@ pub async fn spawn() { }, ..Default::default() }) - .setup(|_, _, _| { + .setup(|c, _, _| { Box::pin(async move { + register_globally(c, &[resize()]).await?; println!("registered"); Ok(()) }) @@ -132,6 +135,31 @@ static DISCORD: LazyLock<Regex> = LazyLock::new(|| { ) .unwrap() }); +#[poise::command( + context_menu_command = "resize", + install_context = "User", + interaction_context = "Guild|PrivateChannel" +)] +pub async fn resize( + c: poise::Context<'_, (), anyhow::Error>, + m: serenity::all::Message, +) -> Result<()> { + c.defer().await?; + if let Some(x) = handle_message(c.serenity_context(), &m).await? { + c.send( + CreateReply::default() + .content(format!("<@{}>", m.author.id)) + .allowed_mentions( + CreateAllowedMentions::new().empty_roles().empty_users(), + ) + .attachment(x), // .flags(MessageFlags::SUPPRESS_NOTIFICATIONS) + // .add_file(x), + ) + .await?; + // .await?; + } + Ok(()) +} async fn handle_message( c: &poise::serenity_prelude::Context, new_message: &Message, |