Update ship formatting
Fix colour not working in embeds Attempt fixing author, footer and fields in embeds
This commit is contained in:
parent
02b8e50b18
commit
9b1990c084
|
@ -1030,7 +1030,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustcord"
|
name = "rustcord"
|
||||||
version = "0.2.8"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"owoify 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "rustcord"
|
name = "rustcord"
|
||||||
version = "0.2.8"
|
version = "0.3.0"
|
||||||
authors = ["Agatha <EvilDeaaaadd@protonmail.com>"]
|
authors = ["Agatha <EvilDeaaaadd@protonmail.com>"]
|
||||||
edition = "2018"
|
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)]
|
#[derive(Deserialize)]
|
||||||
struct EmbedProperties {
|
struct EmbedProperties {
|
||||||
author: [Option<String>; 2],
|
author: Option<(String, Option<String>)>,
|
||||||
colour: u32,
|
colour: String,
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
fields: Vec<(String, String, bool)>,
|
fields: Option<Vec<(String, String, bool)>>,
|
||||||
footer: [Option<String>; 2],
|
footer: Option<(String, Option<String>)>,
|
||||||
image: Option<String>,
|
image: Option<String>,
|
||||||
timestamp: Option<String>,
|
timestamp: Option<String>,
|
||||||
title: Option<String>,
|
title: Option<String>,
|
||||||
|
@ -177,11 +177,11 @@ fn embed(ctx: &mut Context, message: &Message, args: Args) -> CommandResult {
|
||||||
|
|
||||||
let input_embed: EmbedProperties =
|
let input_embed: EmbedProperties =
|
||||||
toml::from_str(args.rest().trim()).unwrap_or(EmbedProperties {
|
toml::from_str(args.rest().trim()).unwrap_or(EmbedProperties {
|
||||||
author: [None, None],
|
author: None,
|
||||||
colour: 0x000000,
|
colour: 0x000000.to_string(),
|
||||||
description: None,
|
description: None,
|
||||||
fields: vec![],
|
fields: None,
|
||||||
footer: [None, None],
|
footer: None,
|
||||||
image: None,
|
image: None,
|
||||||
timestamp: None,
|
timestamp: None,
|
||||||
title: 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| {
|
let _ = message.channel_id.send_message(&ctx.http, |m| {
|
||||||
m.embed(|e| {
|
m.embed(|e| {
|
||||||
// Set embed author unless empty
|
// Set embed author unless empty
|
||||||
if input_embed.author != [None, None] {
|
if input_embed.author != None {
|
||||||
let auth = input_embed.author;
|
let auth = input_embed.author.unwrap();
|
||||||
e.author(|a| {
|
e.author(|a| {
|
||||||
//assumin first array element is name and second is icon url
|
//assumin first array element is name and second is icon url
|
||||||
a.name(auth[0].as_ref().unwrap());
|
a.name(auth.0);
|
||||||
a.icon_url(auth[1].as_ref().unwrap());
|
if auth.1 != None {
|
||||||
|
a.icon_url(auth.1.unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
a
|
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
|
// Set embed description unless empty
|
||||||
if input_embed.description != None {
|
if input_embed.description != None {
|
||||||
e.description(input_embed.description.unwrap());
|
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
|
// Set embed footer unless empty
|
||||||
if input_embed.footer != [None, None] {
|
if input_embed.footer != None {
|
||||||
let foot = input_embed.footer;
|
let foot = input_embed.footer.unwrap();
|
||||||
e.footer(|f| {
|
e.footer(|f| {
|
||||||
f.text(&foot[0].as_ref().unwrap());
|
f.text(foot.0);
|
||||||
f.icon_url(&foot[1].as_ref().unwrap());
|
if foot.1 != None {
|
||||||
|
f.icon_url(foot.1.unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
f
|
f
|
||||||
});
|
});
|
||||||
|
@ -302,7 +313,7 @@ fn ship(ctx: &mut Context, message: &Message, args: Args) -> CommandResult {
|
||||||
m.embed(|e| {
|
m.embed(|e| {
|
||||||
e.title(format!("Original names: {}", args.rest().trim()))
|
e.title(format!("Original names: {}", args.rest().trim()))
|
||||||
.description(format!(
|
.description(format!(
|
||||||
"Ship name:\n{}\nCompatibility: **{}%**\n{}",
|
"Ship name:\n**{}**\nCompatibility: **{}%**\n{}",
|
||||||
shipname.unwrap_or_else(|_| "Invalid input!".to_string()),
|
shipname.unwrap_or_else(|_| "Invalid input!".to_string()),
|
||||||
compat,
|
compat,
|
||||||
compbar
|
compbar
|
||||||
|
|
Loading…
Reference in New Issue