From 024bb60691be64b83d5fac7613d426ce1e103162 Mon Sep 17 00:00:00 2001 From: LinlyBoi Date: Wed, 10 Aug 2022 21:58:01 +0200 Subject: [PATCH] embedded message method???? --- Cargo.lock | 1 + Cargo.toml | 1 + src/main.rs | 106 ++++++++++++++++++++++++++++++++++------------------ 3 files changed, 71 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b80dad5..ceea339 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -255,6 +255,7 @@ dependencies = [ name = "gighalara" version = "0.1.0" dependencies = [ + "serde_json", "serenity", "tokio", ] diff --git a/Cargo.toml b/Cargo.toml index dfca2c7..41d1d79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,4 @@ edition = "2021" [dependencies] serenity = { version ="0.11", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] } tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] } +serde_json = {version = "1.0.83"} diff --git a/src/main.rs b/src/main.rs index 392f163..839067b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,25 +1,25 @@ use std::env; - use serenity::async_trait; use serenity::model::channel::Message; -use serenity::model::channel::Embed; use serenity::model::gateway::Ready; use serenity::prelude::*; - struct Handler; #[async_trait] -impl EventHandler for Handler { +impl EventHandler for Handler +{ //function executed when new message sent - async fn message(&self, ctx: Context, msg: Message) { + async fn message(&self, ctx: Context, msg: Message) + { let text = msg.content.to_string(); let phrase = get_response(&text); if msg.content == "!help" { let dm = msg.author.dm(&ctx, |m| m.content("I hate you")).await; - if let Err(why) = dm { + if let Err(why) = dm + { println!("Couldn't dm the noob: {:?}", why); } } @@ -27,64 +27,96 @@ impl EventHandler for Handler { if &phrase != "not pog" { //Sending a message can fail, have to handle exceptions - if let Err(why) = msg.channel_id.say(&ctx.http, &phrase).await { + if let Err(why) = msg.channel_id.say(&ctx.http, &phrase).await + { println!("Error sending message: {:?}", why); } } - if &text.to_lowercase() == "pls embeb" + //Holy fuck this code fucking sucks how do I sanitise this PLS HELP THERES NO OBJECTS + // if &text.to_lowercase() == "pls embeb" + // { + // if let Err(why) = msg.channel_id.send_message(&ctx.http, |m| + // { + // m.content("this is an embeb") + // .tts(true) + // .embed( |e| + // e.title("Really cool title") + // .description("This will explode") + // .field("Wow rust is really cool","Idk what I'm doing",false,) + // ) + // } + // ).await + // { + // println!("Error emebbing : {:?}",why); + // } + // + // } + // Hopefully a better refactored version of above function only here to showcase how awful + // I was + if &text.to_lowercase() == "pls embed fr fr" { - if let Err(why) = msg.channel_id.send_message(&ctx.http, |m| { - m.content("this is an embeb") - .tts(true) - .embed( |e| e.title("Really cool title").description("This will explode").field( - "Wow rust is really cool", - "Idk what I'm doing", - false, - ) - ) - } - ).await { - println!("Error emebbing : {:?}",why); - } - + + embedded_message(&ctx,&msg,"Wowowowow","Twitch sub notif!","woolHehe woolHoho","!momentummod"); } + + + + + + } //Handles the upon login event - async fn ready(&self, _: Context, ready: Ready) { + async fn ready(&self, _: Context, ready: Ready) + { println!("{} is connected!", ready.user.name); } } -fn get_response(txt: &str) -> String { +fn get_response(txt: &str) -> String +{ //hard coded for now but will change later pls no bully const CRING_WORDS: [&str;4] = ["arch btw","garuda","dragon ball legends", "roblox"]; - for cring in CRING_WORDS { - if txt.to_lowercase().contains(&cring) { - return "you just posted cringe".to_string(); + for cring in CRING_WORDS + { + if txt.to_lowercase().contains(&cring) + { + return "you just posted cringe".to_string(); } } - match txt.to_ascii_lowercase().as_str() { + match txt.to_ascii_lowercase().as_str() + { "hello" | "hi" | "hey" => return "https://nohello.com".to_string(), "help" | "can anyone help?" | "helppp" => return "https://dontasktoask.com".to_string(), _ => return "not pog".to_string(), } } //Embed function starts here (will likely break everything) -fn create_embed() +// fn create_embed(title: &str , description: &str, field1: &str , field2: &str ) -> CreateEmbed +// { +// return |e| CreateEmbed +// { +// e.title(&title).description(&description).field(&field1,&field2,false,) +// } +// } +//It did break everything +async fn embedded_message(ctx:&Context, msg: &Message,title: &str, description: &str, field1: &str, field2: &str ) { - let embed = Embed::fake(|e| { - e.title("Really cool title").description("This will explode").field( - "Wow rust is really cool", - "Idk what I'm doing", - false, - ) - }); - + + if let Err(why) = msg.channel_id.send_message(&ctx.http,|m| + { + m.content("").tts(false).embed( |e| e.title(&title).description(&description).field(&field1,&field2,false,)) + }).await{ println!("hello {:?}",why); } + } +//Purely for debugging +fn print_type_of(_: &T) +{ + println!("{}", std::any::type_name::()) +} #[tokio::main] async fn main() {