embedded message method????
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -255,6 +255,7 @@ dependencies = [
|
|||||||
name = "gighalara"
|
name = "gighalara"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"serde_json",
|
||||||
"serenity",
|
"serenity",
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -8,3 +8,4 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
serenity = { version ="0.11", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] }
|
serenity = { version ="0.11", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] }
|
||||||
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
|
||||||
|
serde_json = {version = "1.0.83"}
|
||||||
|
|||||||
102
src/main.rs
102
src/main.rs
@@ -1,25 +1,25 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use serenity::async_trait;
|
use serenity::async_trait;
|
||||||
use serenity::model::channel::Message;
|
use serenity::model::channel::Message;
|
||||||
use serenity::model::channel::Embed;
|
|
||||||
use serenity::model::gateway::Ready;
|
use serenity::model::gateway::Ready;
|
||||||
use serenity::prelude::*;
|
use serenity::prelude::*;
|
||||||
|
|
||||||
struct Handler;
|
struct Handler;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl EventHandler for Handler {
|
impl EventHandler for Handler
|
||||||
|
{
|
||||||
|
|
||||||
//function executed when new message sent
|
//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 text = msg.content.to_string();
|
||||||
let phrase = get_response(&text);
|
let phrase = get_response(&text);
|
||||||
|
|
||||||
if msg.content == "!help"
|
if msg.content == "!help"
|
||||||
{
|
{
|
||||||
let dm = msg.author.dm(&ctx, |m| m.content("I hate you")).await;
|
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);
|
println!("Couldn't dm the noob: {:?}", why);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,64 +27,96 @@ impl EventHandler for Handler {
|
|||||||
if &phrase != "not pog"
|
if &phrase != "not pog"
|
||||||
{
|
{
|
||||||
//Sending a message can fail, have to handle exceptions
|
//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);
|
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
|
//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);
|
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
|
//hard coded for now but will change later pls no bully
|
||||||
const CRING_WORDS: [&str;4] = ["arch btw","garuda","dragon ball legends", "roblox"];
|
const CRING_WORDS: [&str;4] = ["arch btw","garuda","dragon ball legends", "roblox"];
|
||||||
for cring in CRING_WORDS {
|
for cring in CRING_WORDS
|
||||||
if txt.to_lowercase().contains(&cring) {
|
{
|
||||||
return "you just posted cringe".to_string();
|
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(),
|
"hello" | "hi" | "hey" => return "https://nohello.com".to_string(),
|
||||||
"help" | "can anyone help?" | "helppp" => return "https://dontasktoask.com".to_string(),
|
"help" | "can anyone help?" | "helppp" => return "https://dontasktoask.com".to_string(),
|
||||||
_ => return "not pog".to_string(),
|
_ => return "not pog".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Embed function starts here (will likely break everything)
|
//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(
|
if let Err(why) = msg.channel_id.send_message(&ctx.http,|m|
|
||||||
"Wow rust is really cool",
|
{
|
||||||
"Idk what I'm doing",
|
m.content("").tts(false).embed( |e| e.title(&title).description(&description).field(&field1,&field2,false,))
|
||||||
false,
|
}).await{ println!("hello {:?}",why); }
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Purely for debugging
|
||||||
|
fn print_type_of<T>(_: &T)
|
||||||
|
{
|
||||||
|
println!("{}", std::any::type_name::<T>())
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
|||||||
Reference in New Issue
Block a user