From 6bd5da9c3afe801c2c23f158428a7d2445b73878 Mon Sep 17 00:00:00 2001 From: Ladislav Hano <524934@mail.muni.cz> Date: Fri, 14 Jul 2023 15:04:01 +0200 Subject: [PATCH 1/4] Not working so far --- Cargo.lock | 33 ++++++++++++++++--- Cargo.toml | 2 ++ src/main.rs | 47 +++++++++++++++------------- src/moove.rs | 73 +++++++++++++++++++++++++++++++++++++++++++ src/util/embeds.rs | 0 src/util/security.rs | 3 +- src/util/utilities.rs | 0 7 files changed, 130 insertions(+), 28 deletions(-) create mode 100644 src/moove.rs create mode 100644 src/util/embeds.rs create mode 100644 src/util/utilities.rs diff --git a/Cargo.lock b/Cargo.lock index 77fac90..e03925d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,6 +28,15 @@ dependencies = [ "version_check", ] +[[package]] +name = "aho-corasick" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" +dependencies = [ + "memchr", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -967,6 +976,8 @@ dependencies = [ "dotenv", "mongodb", "poise", + "rand", + "regex", "serenity", "serenity_utils", "tokio", @@ -1183,18 +1194,32 @@ dependencies = [ [[package]] name = "regex" -version = "1.8.4" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f" +checksum = "89089e897c013b3deb627116ae56a6955a72b8bed395c9526af31c9fe528b484" dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa250384981ea14565685dea16a9ccc4d1c541a13f82b9c168572264d1df8c56" +dependencies = [ + "aho-corasick", + "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" +checksum = "2ab07dc67230e4a4718e70fd5c20055a4334b121f1f9db8fe63ef39ce9b8c846" [[package]] name = "reqwest" diff --git a/Cargo.toml b/Cargo.toml index 1bed005..1065af0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,5 @@ poise = "0.5.5" serenity = { version = "0.11.6", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "http"] } serenity_utils = "0.7.0" tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] } +rand = "0.8.4" +regex = "1.9.0" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e9522dc..75ac657 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,11 @@ -use std::sync::Arc; - -use poise::serenity_prelude::GuildChannel; use serenity::async_trait; -use serenity::http::{self, Http}; use serenity::model::channel::Message; use serenity::model::gateway::Ready; -use serenity::model::id::ChannelId; use serenity::prelude::*; use util::security::dotenv_var; +use rand::random; +mod moove; mod util; struct Handler; @@ -25,22 +22,29 @@ impl EventHandler for Handler { async fn ready(&self, ctx: Context, ready: Ready) { println!("{} is connected!", ready.user.name); - // if (ready.user.name != "MOOver Debug") { - let messages = [ - "AAAAAAAAAAAAAAAAAAAA", - "Henlooo", - "Good day y'all!", - "May have crashed...", - "MOOOooo", - "Heyyyyy!", - "I'm baaaaack!", - "Whom'st have summoned the ancient one?", - ]; - - // } - - let channel = ctx.http.get_channel(780439236867653635).await.unwrap(); - + let debug = match dotenv_var("DEBUG") { + Some(v) => v, + None => "OFF".to_string() + }; + if debug == "ON" { + let messages = [ + "AAAAAAAAAAAAAAAAAAAA", + "Henlooo", + "Good day y'all!", + "May have crashed...", + "MOOOooo", + "Heyyyyy!", + "I'm baaaaack!", + "Whom'st have summoned the ancient one?", + ]; + + let rand_num = random::() % messages.len(); + let channel = ctx.http.get_channel(780439236867653635).await.unwrap().id(); + match channel.say(&ctx.http, messages[rand_num]).await { + Err(e) => println!("Something went wrong: {e}"), + Ok(_) => return + }; + } } } @@ -49,7 +53,6 @@ async fn main() -> anyhow::Result<()> { use anyhow::Context; let token = dotenv_var("TOKEN").context("No TOKEN in env")?; let intents = GatewayIntents::GUILD_MESSAGES - | GatewayIntents::DIRECT_MESSAGES | GatewayIntents::MESSAGE_CONTENT; let mut client = Client::builder(&token, intents) diff --git a/src/moove.rs b/src/moove.rs new file mode 100644 index 0000000..b525fce --- /dev/null +++ b/src/moove.rs @@ -0,0 +1,73 @@ +use serenity::builder::{CreateEmbed, CreateMessage}; +use serenity::model::channel::Message; +use serenity::http::Http; +use serenity::model::channel::Attachment; +use anyhow; +use serenity::model::mention; + +// use regex::Regex; + +// Checks if the message should be mooved, if not returns Ok(0) +// If the message should be mooved, try to move it and return Ok(1) if mooved succesfully +// else returns Err() +pub async fn moove(http: Http, msg: Message) -> Result{ + let channel_mentions = msg.mention_channels; + let words = msg.content.trim().split_whitespace().count(); + + // let re = Regex::new(r"<#[0-9]*>$").unwrap(); + // if re.captures(content) + + if channel_mentions.len() != 1 || words != 1 { + return Ok(0); + } + + let mut msg_to_moove = match msg.referenced_message { + Some(m) => m, + None => return Ok(0) + }; + + let mentioned_channel = channel_mentions[0].id; + + let attachments = msg_to_moove.attachments; + let embeds = msg_to_moove.embeds; + + let sent_by = format!("Sent by {}\n mooved {}\n", msg_to_moove.author, msg.author); + + let mut embeds_copy : Vec = Vec::new(); + for embed in msg_to_moove.embeds { + embeds_copy.push(CreateEmbed::from(embed)); + } + + // let mut attachment_links : Vec = Vec::new(); + let attachment_link = msg_to_moove.attachments.pop(); + // for attachment in msg_to_moove.attachments { + // attachment_links.push(attachment.url); + // } + + // if embeds_copy.len() > 0 || attachment_links.len() > 0 { + if embeds_copy.len() > 0 { + let mut new_content = "".to_string(); + if !msg_to_moove.content.is_empty() { + new_content = format!("Message:\n{}", msg_to_moove.content); + } + sent_by.push_str(&new_content); + match mentioned_channel.send_message(http, |m| { + m.content(sent_by).add_embeds(embeds_copy).add_file(attachment_link) + }).await { + Ok(_) => return Ok(0), + Err(e) => return Err(e.to_string()) + }; + } + else if !msg_to_moove.content.is_empty() { + match mentioned_channel.send_message(http, |m| { + m.add_embed(|e| { + e.title("MOO").field(sent_by, " ", false).field("Message:\n", msg_to_moove.content, false) + }) + }).await { + Ok(_) => return Ok(0), + Err(e) => return Err(e.to_string()) + }; + } + + Err("Something went wrong while mooving the message".to_string()) +} \ No newline at end of file diff --git a/src/util/embeds.rs b/src/util/embeds.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/util/security.rs b/src/util/security.rs index b33047d..7473fcb 100644 --- a/src/util/security.rs +++ b/src/util/security.rs @@ -3,10 +3,9 @@ use std::env; pub fn dotenv_var(key: &str) -> Option { dotenv().ok(); - let key = "TOKEN"; match env::var(key) { Ok(val) => return Some(val), - Err(_) => None, + Err(_) => None } } diff --git a/src/util/utilities.rs b/src/util/utilities.rs new file mode 100644 index 0000000..e69de29 From 9f02f554790b2ceef58a616dff482f44f0eb0f47 Mon Sep 17 00:00:00 2001 From: Djkato Date: Fri, 14 Jul 2023 16:41:16 +0200 Subject: [PATCH 2/4] Cleanup :) --- Cargo.lock | 1 + Cargo.toml | 3 +- src/main.rs | 22 ++++++++------ src/moove.rs | 83 +++++++++++++++++++++------------------------------- 4 files changed, 49 insertions(+), 60 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e03925d..963eea2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -981,6 +981,7 @@ dependencies = [ "serenity", "serenity_utils", "tokio", + "url", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 1065af0..03fddad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,4 +15,5 @@ serenity = { version = "0.11.6", default-features = false, features = ["client", serenity_utils = "0.7.0" tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] } rand = "0.8.4" -regex = "1.9.0" \ No newline at end of file +regex = "1.9.0" +url = "2.4.0" diff --git a/src/main.rs b/src/main.rs index 75ac657..f82f07c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,10 @@ +use moove::moove; +use rand::random; use serenity::async_trait; use serenity::model::channel::Message; use serenity::model::gateway::Ready; use serenity::prelude::*; use util::security::dotenv_var; -use rand::random; mod moove; mod util; @@ -13,6 +14,10 @@ struct Handler; #[async_trait] impl EventHandler for Handler { async fn message(&self, ctx: Context, msg: Message) { + match moove(ctx.http.clone(), msg.clone()).await { + Ok(_) => (), + Err(e) => println!("ERROR MOVING!{e}"), + } if msg.content == "!ping" { if let Err(why) = msg.channel_id.say(&ctx.http, "Pong!").await { println!("Error sending message: {:?}", why); @@ -24,7 +29,7 @@ impl EventHandler for Handler { println!("{} is connected!", ready.user.name); let debug = match dotenv_var("DEBUG") { Some(v) => v, - None => "OFF".to_string() + None => "OFF".to_string(), }; if debug == "ON" { let messages = [ @@ -36,13 +41,13 @@ impl EventHandler for Handler { "Heyyyyy!", "I'm baaaaack!", "Whom'st have summoned the ancient one?", - ]; - + ]; + let rand_num = random::() % messages.len(); let channel = ctx.http.get_channel(780439236867653635).await.unwrap().id(); match channel.say(&ctx.http, messages[rand_num]).await { Err(e) => println!("Something went wrong: {e}"), - Ok(_) => return + Ok(_) => return, }; } } @@ -52,14 +57,13 @@ impl EventHandler for Handler { async fn main() -> anyhow::Result<()> { use anyhow::Context; let token = dotenv_var("TOKEN").context("No TOKEN in env")?; - let intents = GatewayIntents::GUILD_MESSAGES - | GatewayIntents::MESSAGE_CONTENT; - + let intents = GatewayIntents::GUILD_MESSAGES | GatewayIntents::MESSAGE_CONTENT; + let mut client = Client::builder(&token, intents) .event_handler(Handler) .await .context("Failed to build client")?; - + client.start().await?; Ok(()) } diff --git a/src/moove.rs b/src/moove.rs index b525fce..5afcb95 100644 --- a/src/moove.rs +++ b/src/moove.rs @@ -1,73 +1,56 @@ +use std::sync::Arc; + +use anyhow::{self, Context}; +use poise::serenity_prelude::AttachmentType; use serenity::builder::{CreateEmbed, CreateMessage}; -use serenity::model::channel::Message; use serenity::http::Http; use serenity::model::channel::Attachment; -use anyhow; +use serenity::model::channel::Message; use serenity::model::mention; +use url::Url; // use regex::Regex; // Checks if the message should be mooved, if not returns Ok(0) // If the message should be mooved, try to move it and return Ok(1) if mooved succesfully // else returns Err() -pub async fn moove(http: Http, msg: Message) -> Result{ + +pub async fn moove(http: Arc, msg: Message) -> anyhow::Result<()> { let channel_mentions = msg.mention_channels; let words = msg.content.trim().split_whitespace().count(); - // let re = Regex::new(r"<#[0-9]*>$").unwrap(); // if re.captures(content) - if channel_mentions.len() != 1 || words != 1 { - return Ok(0); + if channel_mentions.len() != 1 || words != 1 || msg.content.is_empty() { + anyhow::bail!("no message worth processing"); } - let mut msg_to_moove = match msg.referenced_message { - Some(m) => m, - None => return Ok(0) - }; + let msg_to_moove = msg.referenced_message.context("no message present")?; let mentioned_channel = channel_mentions[0].id; - let attachments = msg_to_moove.attachments; - let embeds = msg_to_moove.embeds; + //steals all attachments, but sets all of them as Image urls, so rip actual docs etc + let attachments = msg_to_moove + .attachments + .into_iter() + .map(|att| AttachmentType::Image(Url::parse(att.url.as_str()).unwrap())); - let sent_by = format!("Sent by {}\n mooved {}\n", msg_to_moove.author, msg.author); + //steals all the embeds + let embeds: Vec = msg_to_moove + .embeds + .into_iter() + .map(|em| CreateEmbed::from(em)) + .collect(); - let mut embeds_copy : Vec = Vec::new(); - for embed in msg_to_moove.embeds { - embeds_copy.push(CreateEmbed::from(embed)); - } + let mut new_content = format!("Sent by {}\n mooved {}\n", msg_to_moove.author, msg.author); + new_content += format!("Message:\n{}", msg_to_moove.content).as_str(); - // let mut attachment_links : Vec = Vec::new(); - let attachment_link = msg_to_moove.attachments.pop(); - // for attachment in msg_to_moove.attachments { - // attachment_links.push(attachment.url); - // } - - // if embeds_copy.len() > 0 || attachment_links.len() > 0 { - if embeds_copy.len() > 0 { - let mut new_content = "".to_string(); - if !msg_to_moove.content.is_empty() { - new_content = format!("Message:\n{}", msg_to_moove.content); - } - sent_by.push_str(&new_content); - match mentioned_channel.send_message(http, |m| { - m.content(sent_by).add_embeds(embeds_copy).add_file(attachment_link) - }).await { - Ok(_) => return Ok(0), - Err(e) => return Err(e.to_string()) - }; - } - else if !msg_to_moove.content.is_empty() { - match mentioned_channel.send_message(http, |m| { - m.add_embed(|e| { - e.title("MOO").field(sent_by, " ", false).field("Message:\n", msg_to_moove.content, false) - }) - }).await { - Ok(_) => return Ok(0), - Err(e) => return Err(e.to_string()) - }; - } - - Err("Something went wrong while mooving the message".to_string()) -} \ No newline at end of file + mentioned_channel + .send_message(http, |m| { + m.content(new_content) + .add_embeds(embeds) + .add_files(attachments) + }) + .await?; + Ok(()) +} From 487ceae1108a49e6d272a205abb5eec272773fb8 Mon Sep 17 00:00:00 2001 From: Ladislav Hano <524934@mail.muni.cz> Date: Sat, 15 Jul 2023 11:18:08 +0200 Subject: [PATCH 3/4] MOOving works --- .gitignore | 3 +- src/commands/mod.rs | 1 + src/commands/moove.rs | 67 ++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 19 +++++------- src/message_handler.rs | 12 ++++++++ src/moove.rs | 56 ----------------------------------- 6 files changed, 89 insertions(+), 69 deletions(-) create mode 100644 src/commands/mod.rs create mode 100644 src/commands/moove.rs create mode 100644 src/message_handler.rs delete mode 100644 src/moove.rs diff --git a/.gitignore b/.gitignore index 0b745e2..a5cbe4f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -.env \ No newline at end of file +.env +.vscode \ No newline at end of file diff --git a/src/commands/mod.rs b/src/commands/mod.rs new file mode 100644 index 0000000..2930a52 --- /dev/null +++ b/src/commands/mod.rs @@ -0,0 +1 @@ +pub mod moove; \ No newline at end of file diff --git a/src/commands/moove.rs b/src/commands/moove.rs new file mode 100644 index 0000000..7c10d38 --- /dev/null +++ b/src/commands/moove.rs @@ -0,0 +1,67 @@ +use std::sync::Arc; + +use anyhow::{self, Context}; +use poise::serenity_prelude::AttachmentType; +use serenity::builder::CreateEmbed; +use serenity::http::Http; +use serenity::model::channel::Message; +use url::Url; +use regex::Regex; + +// Checks if the message should be mooved +// If the message should be mooved, try to move it and return Ok if mooved succesfully +// else returns Err() + +pub enum MooveResult { + Mooved, + NotMooveRequest +} + +pub async fn moove(http: Arc, msg: Message) -> anyhow::Result { + let word_count = msg.content.trim().split_whitespace().count(); + + let re = Regex::new(r"<#[0-9]*>$").unwrap(); + + if word_count != 1 || re.captures(&msg.content).is_none() { + return Ok(MooveResult::NotMooveRequest); + } + + let msg_to_moove = msg.referenced_message.context("no message present")?; + + let mentioned_channel = http.get_channel( + msg.content[2..msg.content.len() - 1].parse::() + .unwrap()).await?.id(); + + //steals all attachments, but sets all of them as Image urls, so rip actual docs etc + let attachments = msg_to_moove + .attachments + .into_iter() + .map(|att| AttachmentType::Image(Url::parse(att.url.as_str()).unwrap())); + + //steals all the embeds + let embeds: Vec = msg_to_moove + .embeds + .into_iter() + .map(|em| CreateEmbed::from(em)) + .collect(); + + let mut new_content = format!("Sent by {}\n mooved {}\n", msg_to_moove.author, msg.author); + + if !msg_to_moove.content.is_empty() { + mentioned_channel.send_message(http, |m| { + m.add_embed(|e| { + e.field("MOO", new_content, false) + .field("Message:\n", msg_to_moove.content.clone(), false) + }) + }).await?; + } + else if attachments.len() > 0 || embeds.len() > 0 { + new_content += format!("Message:\n{}", msg_to_moove.content).as_str(); + mentioned_channel.send_message(http, |m| { + m.content(new_content) + .add_embeds(embeds) + .add_files(attachments) + }).await?; + } + Ok(MooveResult::Mooved) +} diff --git a/src/main.rs b/src/main.rs index f82f07c..724b8ff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,3 @@ -use moove::moove; use rand::random; use serenity::async_trait; use serenity::model::channel::Message; @@ -6,7 +5,10 @@ use serenity::model::gateway::Ready; use serenity::prelude::*; use util::security::dotenv_var; -mod moove; +mod message_handler; +use message_handler::handle; + +mod commands; mod util; struct Handler; @@ -14,15 +16,8 @@ struct Handler; #[async_trait] impl EventHandler for Handler { async fn message(&self, ctx: Context, msg: Message) { - match moove(ctx.http.clone(), msg.clone()).await { - Ok(_) => (), - Err(e) => println!("ERROR MOVING!{e}"), - } - if msg.content == "!ping" { - if let Err(why) = msg.channel_id.say(&ctx.http, "Pong!").await { - println!("Error sending message: {:?}", why); - } - } + println!("Got message"); + handle(ctx, msg).await; } async fn ready(&self, ctx: Context, ready: Ready) { @@ -31,7 +26,7 @@ impl EventHandler for Handler { Some(v) => v, None => "OFF".to_string(), }; - if debug == "ON" { + if debug != "ON" { let messages = [ "AAAAAAAAAAAAAAAAAAAA", "Henlooo", diff --git a/src/message_handler.rs b/src/message_handler.rs new file mode 100644 index 0000000..b06f005 --- /dev/null +++ b/src/message_handler.rs @@ -0,0 +1,12 @@ +use serenity::client::Context; +use serenity::model::channel::Message; + +use crate::commands::moove::moove; + +pub async fn handle(ctx: Context, msg: Message) { + println!("In handler"); + match moove(ctx.http, msg).await { + Ok(_) => return, + Err(e) => println!("ERROR: {e}") + }; +} \ No newline at end of file diff --git a/src/moove.rs b/src/moove.rs deleted file mode 100644 index 5afcb95..0000000 --- a/src/moove.rs +++ /dev/null @@ -1,56 +0,0 @@ -use std::sync::Arc; - -use anyhow::{self, Context}; -use poise::serenity_prelude::AttachmentType; -use serenity::builder::{CreateEmbed, CreateMessage}; -use serenity::http::Http; -use serenity::model::channel::Attachment; -use serenity::model::channel::Message; -use serenity::model::mention; -use url::Url; - -// use regex::Regex; - -// Checks if the message should be mooved, if not returns Ok(0) -// If the message should be mooved, try to move it and return Ok(1) if mooved succesfully -// else returns Err() - -pub async fn moove(http: Arc, msg: Message) -> anyhow::Result<()> { - let channel_mentions = msg.mention_channels; - let words = msg.content.trim().split_whitespace().count(); - // let re = Regex::new(r"<#[0-9]*>$").unwrap(); - // if re.captures(content) - - if channel_mentions.len() != 1 || words != 1 || msg.content.is_empty() { - anyhow::bail!("no message worth processing"); - } - - let msg_to_moove = msg.referenced_message.context("no message present")?; - - let mentioned_channel = channel_mentions[0].id; - - //steals all attachments, but sets all of them as Image urls, so rip actual docs etc - let attachments = msg_to_moove - .attachments - .into_iter() - .map(|att| AttachmentType::Image(Url::parse(att.url.as_str()).unwrap())); - - //steals all the embeds - let embeds: Vec = msg_to_moove - .embeds - .into_iter() - .map(|em| CreateEmbed::from(em)) - .collect(); - - let mut new_content = format!("Sent by {}\n mooved {}\n", msg_to_moove.author, msg.author); - new_content += format!("Message:\n{}", msg_to_moove.content).as_str(); - - mentioned_channel - .send_message(http, |m| { - m.content(new_content) - .add_embeds(embeds) - .add_files(attachments) - }) - .await?; - Ok(()) -} From 2452c0abc1809b7a908b833a28627b58d9a1ba52 Mon Sep 17 00:00:00 2001 From: Ladislav Hano <524934@mail.muni.cz> Date: Sat, 15 Jul 2023 12:11:57 +0200 Subject: [PATCH 4/4] message deletion works --- src/commands/moove.rs | 33 ++++++++++++++++++++------------- src/main.rs | 1 - src/message_handler.rs | 1 - 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/commands/moove.rs b/src/commands/moove.rs index 7c10d38..8ffff87 100644 --- a/src/commands/moove.rs +++ b/src/commands/moove.rs @@ -1,10 +1,12 @@ use std::sync::Arc; +use std::time::Duration; use anyhow::{self, Context}; use poise::serenity_prelude::AttachmentType; use serenity::builder::CreateEmbed; use serenity::http::Http; use serenity::model::channel::Message; +use tokio::time::sleep; use url::Url; use regex::Regex; @@ -26,7 +28,7 @@ pub async fn moove(http: Arc, msg: Message) -> anyhow::Result return Ok(MooveResult::NotMooveRequest); } - let msg_to_moove = msg.referenced_message.context("no message present")?; + let msg_to_moove = msg.clone().referenced_message.context("no message present")?; let mentioned_channel = http.get_channel( msg.content[2..msg.content.len() - 1].parse::() @@ -34,34 +36,39 @@ pub async fn moove(http: Arc, msg: Message) -> anyhow::Result //steals all attachments, but sets all of them as Image urls, so rip actual docs etc let attachments = msg_to_moove - .attachments + .attachments.clone() .into_iter() .map(|att| AttachmentType::Image(Url::parse(att.url.as_str()).unwrap())); //steals all the embeds let embeds: Vec = msg_to_moove - .embeds + .embeds.clone() .into_iter() .map(|em| CreateEmbed::from(em)) .collect(); let mut new_content = format!("Sent by {}\n mooved {}\n", msg_to_moove.author, msg.author); - if !msg_to_moove.content.is_empty() { - mentioned_channel.send_message(http, |m| { + if attachments.len() > 0 || embeds.len() > 0 { + new_content += format!("Message:\n{}", msg_to_moove.content).as_str(); + mentioned_channel.send_message(http.clone(), |m| { + m.content(new_content) + .add_embeds(embeds) + .add_files(attachments) + }).await?; + } + else if !msg_to_moove.content.is_empty() { + mentioned_channel.send_message(http.clone(), |m| { m.add_embed(|e| { e.field("MOO", new_content, false) .field("Message:\n", msg_to_moove.content.clone(), false) }) }).await?; } - else if attachments.len() > 0 || embeds.len() > 0 { - new_content += format!("Message:\n{}", msg_to_moove.content).as_str(); - mentioned_channel.send_message(http, |m| { - m.content(new_content) - .add_embeds(embeds) - .add_files(attachments) - }).await?; - } + + sleep(Duration::from_secs(2)).await; + + msg_to_moove.delete(http.clone()).await?; + msg.delete(http).await?; Ok(MooveResult::Mooved) } diff --git a/src/main.rs b/src/main.rs index 724b8ff..71198aa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,6 @@ struct Handler; #[async_trait] impl EventHandler for Handler { async fn message(&self, ctx: Context, msg: Message) { - println!("Got message"); handle(ctx, msg).await; } diff --git a/src/message_handler.rs b/src/message_handler.rs index b06f005..391dae9 100644 --- a/src/message_handler.rs +++ b/src/message_handler.rs @@ -4,7 +4,6 @@ use serenity::model::channel::Message; use crate::commands::moove::moove; pub async fn handle(ctx: Context, msg: Message) { - println!("In handler"); match moove(ctx.http, msg).await { Ok(_) => return, Err(e) => println!("ERROR: {e}")