diff --git a/Cargo.lock b/Cargo.lock index 9074cb2..4cb27b8 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -1030,7 +1030,7 @@ dependencies = [ [[package]] name = "rustcord" -version = "0.2.8" +version = "0.3.0" dependencies = [ "owoify 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 2d69b0f..c80ed85 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustcord" -version = "0.2.8" +version = "0.3.0" authors = ["Agatha <@protonmail.com>"] edition = "2018" diff --git a/src/main.rs b/src/main.rs index f7c439b..c773b33 100755 --- a/src/main.rs +++ b/src/main.rs @@ -164,11 +164,11 @@ fn embed(ctx: &mut Context, message: &Message, args: Args) -> CommandResult { #[derive(Deserialize)] struct EmbedProperties { - author: [Option; 2], - colour: u32, + author: Option<(String, Option)>, + colour: String, description: Option, - fields: Vec<(String, String, bool)>, - footer: [Option; 2], + fields: Option>, + footer: Option<(String, Option)>, image: Option, timestamp: Option, title: Option, @@ -177,11 +177,11 @@ fn embed(ctx: &mut Context, message: &Message, args: Args) -> CommandResult { let input_embed: EmbedProperties = toml::from_str(args.rest().trim()).unwrap_or(EmbedProperties { - author: [None, None], - colour: 0x000000, + author: None, + colour: 0x000000.to_string(), description: None, - fields: vec![], - footer: [None, None], + fields: None, + footer: None, image: None, timestamp: None, title: None, @@ -191,30 +191,41 @@ fn embed(ctx: &mut Context, message: &Message, args: Args) -> CommandResult { let _ = message.channel_id.send_message(&ctx.http, |m| { m.embed(|e| { // Set embed author unless empty - if input_embed.author != [None, None] { - let auth = input_embed.author; + if input_embed.author != None { + let auth = input_embed.author.unwrap(); e.author(|a| { //assumin first array element is name and second is icon url - a.name(auth[0].as_ref().unwrap()); - a.icon_url(auth[1].as_ref().unwrap()); + a.name(auth.0); + if auth.1 != None { + a.icon_url(auth.1.unwrap()); + } a }); } - e.color(Colour::new(input_embed.colour)); + e.color(Colour::new( + usize::from_str_radix(&input_embed.colour, 16) + .ok() + .unwrap_or(0x000000) as u32, + )); // Set embed description unless empty if input_embed.description != None { e.description(input_embed.description.unwrap()); } - e.fields(input_embed.fields); + // Set embed fields unless empty + if input_embed.fields != None { + e.fields(input_embed.fields.unwrap()); + } // Set embed footer unless empty - if input_embed.footer != [None, None] { - let foot = input_embed.footer; + if input_embed.footer != None { + let foot = input_embed.footer.unwrap(); e.footer(|f| { - f.text(&foot[0].as_ref().unwrap()); - f.icon_url(&foot[1].as_ref().unwrap()); + f.text(foot.0); + if foot.1 != None { + f.icon_url(foot.1.unwrap()); + } f }); @@ -302,7 +313,7 @@ fn ship(ctx: &mut Context, message: &Message, args: Args) -> CommandResult { m.embed(|e| { e.title(format!("Original names: {}", args.rest().trim())) .description(format!( - "Ship name:\n{}\nCompatibility: **{}%**\n{}", + "Ship name:\n**{}**\nCompatibility: **{}%**\n{}", shipname.unwrap_or_else(|_| "Invalid input!".to_string()), compat, compbar