message deletion works
This commit is contained in:
parent
487ceae110
commit
2452c0abc1
3 changed files with 20 additions and 15 deletions
|
@ -1,10 +1,12 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::{self, Context};
|
use anyhow::{self, Context};
|
||||||
use poise::serenity_prelude::AttachmentType;
|
use poise::serenity_prelude::AttachmentType;
|
||||||
use serenity::builder::CreateEmbed;
|
use serenity::builder::CreateEmbed;
|
||||||
use serenity::http::Http;
|
use serenity::http::Http;
|
||||||
use serenity::model::channel::Message;
|
use serenity::model::channel::Message;
|
||||||
|
use tokio::time::sleep;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
|
@ -26,7 +28,7 @@ pub async fn moove(http: Arc<Http>, msg: Message) -> anyhow::Result<MooveResult>
|
||||||
return Ok(MooveResult::NotMooveRequest);
|
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(
|
let mentioned_channel = http.get_channel(
|
||||||
msg.content[2..msg.content.len() - 1].parse::<u64>()
|
msg.content[2..msg.content.len() - 1].parse::<u64>()
|
||||||
|
@ -34,34 +36,39 @@ pub async fn moove(http: Arc<Http>, msg: Message) -> anyhow::Result<MooveResult>
|
||||||
|
|
||||||
//steals all attachments, but sets all of them as Image urls, so rip actual docs etc
|
//steals all attachments, but sets all of them as Image urls, so rip actual docs etc
|
||||||
let attachments = msg_to_moove
|
let attachments = msg_to_moove
|
||||||
.attachments
|
.attachments.clone()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|att| AttachmentType::Image(Url::parse(att.url.as_str()).unwrap()));
|
.map(|att| AttachmentType::Image(Url::parse(att.url.as_str()).unwrap()));
|
||||||
|
|
||||||
//steals all the embeds
|
//steals all the embeds
|
||||||
let embeds: Vec<CreateEmbed> = msg_to_moove
|
let embeds: Vec<CreateEmbed> = msg_to_moove
|
||||||
.embeds
|
.embeds.clone()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|em| CreateEmbed::from(em))
|
.map(|em| CreateEmbed::from(em))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut new_content = format!("Sent by {}\n mooved {}\n", msg_to_moove.author, msg.author);
|
let mut new_content = format!("Sent by {}\n mooved {}\n", msg_to_moove.author, msg.author);
|
||||||
|
|
||||||
if !msg_to_moove.content.is_empty() {
|
if attachments.len() > 0 || embeds.len() > 0 {
|
||||||
mentioned_channel.send_message(http, |m| {
|
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| {
|
m.add_embed(|e| {
|
||||||
e.field("MOO", new_content, false)
|
e.field("MOO", new_content, false)
|
||||||
.field("Message:\n", msg_to_moove.content.clone(), false)
|
.field("Message:\n", msg_to_moove.content.clone(), false)
|
||||||
})
|
})
|
||||||
}).await?;
|
}).await?;
|
||||||
}
|
}
|
||||||
else if attachments.len() > 0 || embeds.len() > 0 {
|
|
||||||
new_content += format!("Message:\n{}", msg_to_moove.content).as_str();
|
sleep(Duration::from_secs(2)).await;
|
||||||
mentioned_channel.send_message(http, |m| {
|
|
||||||
m.content(new_content)
|
msg_to_moove.delete(http.clone()).await?;
|
||||||
.add_embeds(embeds)
|
msg.delete(http).await?;
|
||||||
.add_files(attachments)
|
|
||||||
}).await?;
|
|
||||||
}
|
|
||||||
Ok(MooveResult::Mooved)
|
Ok(MooveResult::Mooved)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ struct Handler;
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl EventHandler for Handler {
|
impl EventHandler for Handler {
|
||||||
async fn message(&self, ctx: Context, msg: Message) {
|
async fn message(&self, ctx: Context, msg: Message) {
|
||||||
println!("Got message");
|
|
||||||
handle(ctx, msg).await;
|
handle(ctx, msg).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ use serenity::model::channel::Message;
|
||||||
use crate::commands::moove::moove;
|
use crate::commands::moove::moove;
|
||||||
|
|
||||||
pub async fn handle(ctx: Context, msg: Message) {
|
pub async fn handle(ctx: Context, msg: Message) {
|
||||||
println!("In handler");
|
|
||||||
match moove(ctx.http, msg).await {
|
match moove(ctx.http, msg).await {
|
||||||
Ok(_) => return,
|
Ok(_) => return,
|
||||||
Err(e) => println!("ERROR: {e}")
|
Err(e) => println!("ERROR: {e}")
|
||||||
|
|
Loading…
Reference in a new issue