Update ship formatting
Fix colour not working in embeds Attempt fixing author, footer and fields in embeds
This commit is contained in:
parent
ca3142f9a5
commit
dcbc2753c4
|
@ -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)",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "rustcord"
|
||||
version = "0.2.8"
|
||||
version = "0.3.0"
|
||||
authors = ["Agatha <@protonmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
|
|
49
src/main.rs
49
src/main.rs
|
@ -164,11 +164,11 @@ fn embed(ctx: &mut Context, message: &Message, args: Args) -> CommandResult {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
struct EmbedProperties {
|
||||
author: [Option<String>; 2],
|
||||
colour: u32,
|
||||
author: Option<(String, Option<String>)>,
|
||||
colour: String,
|
||||
description: Option<String>,
|
||||
fields: Vec<(String, String, bool)>,
|
||||
footer: [Option<String>; 2],
|
||||
fields: Option<Vec<(String, String, bool)>>,
|
||||
footer: Option<(String, Option<String>)>,
|
||||
image: Option<String>,
|
||||
timestamp: Option<String>,
|
||||
title: Option<String>,
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue