[no description]
devious
| -rw-r--r-- | Cargo.toml | 11 | ||||
| -rw-r--r-- | src/main.rs | 32 |
2 files changed, 39 insertions, 4 deletions
@@ -18,7 +18,7 @@ serenity = { version = "0.12", features = [ "rustls_backend", "gateway", "model", -], default-features = false, git = "https://github.com/serenity-rs/serenity" } +], default-features = false } clap = { version = "4.4", features = ["derive"] } env_logger = "0.10" log = "0.4" @@ -32,7 +32,14 @@ rustls = "0.23.36" openssl = { version = "0.10.35", features = ["vendored"] } fimg = { git = "https://git.bendn.org/fimg", version = "0.4.51" } gif = "0.14.1" -image = { version = "0.25.9", features = ["bmp", "dds", "hdr", "ico", "pnm", "tga"] } +image = { version = "0.25.9", features = [ + "bmp", + "dds", + "hdr", + "ico", + "pnm", + "tga", +] } [patch.crates-io] serenity = { git = "https://github.com/serenity-rs/serenity" } 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, |