feat: tidied up the command outouts
This commit is contained in:
parent
86f54aec6d
commit
0f4524ea63
3 changed files with 35 additions and 16 deletions
|
@ -51,7 +51,7 @@ pub(crate) mod user {
|
|||
.add_sub_option(CreateCommandOption::new(CommandOptionType::SubCommand, "icon", "Information on current icon."))
|
||||
.add_sub_option(CreateCommandOption::new(CommandOptionType::SubCommand, "festival", "Information on current festival.")),
|
||||
)
|
||||
.add_option(CreateCommandOption::new(CommandOptionType::SubCommand, "stats", "Some Stats."))
|
||||
.add_option(CreateCommandOption::new(CommandOptionType::SubCommand, "stats", "How many times the particular icon has been used"))
|
||||
}
|
||||
|
||||
fn get_logo_url(config_toml: &ConfigTomlLocal, logo_name: &str) -> String {
|
||||
|
@ -64,6 +64,7 @@ pub(crate) mod user {
|
|||
|
||||
pub(crate) mod icon {
|
||||
use super::*;
|
||||
use serenity::all::{CreateAttachment, EditInteractionResponse};
|
||||
|
||||
use sqlx::{Pool, Sqlite};
|
||||
|
||||
|
@ -77,7 +78,15 @@ pub(crate) mod user {
|
|||
let config_toml = get_config_icons::minimal();
|
||||
|
||||
if let Some(logo) = get_current_icon(&db).await {
|
||||
get_logo_url(&config_toml, &logo.name)
|
||||
let attachment = CreateAttachment::path(&logo.path).await.unwrap();
|
||||
match command.edit_response(&ctx.http, EditInteractionResponse::new().new_attachment(attachment)).await {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
dbg!(e);
|
||||
}
|
||||
}
|
||||
|
||||
format!("[{}]({})", &logo.name, get_logo_url(&config_toml, &logo.name))
|
||||
} else {
|
||||
"Could not find current icon".to_string()
|
||||
}
|
||||
|
@ -102,8 +111,8 @@ pub(crate) mod user {
|
|||
}
|
||||
|
||||
pub(crate) mod festival {
|
||||
use serenity::all::{CommandInteraction, CommandOptionType, Context, CreateCommand, CreateCommandOption};
|
||||
use skynet_discord_bot::common::server_icon::get_config_icons;
|
||||
use serenity::all::{CommandInteraction, Context};
|
||||
use skynet_discord_bot::common::server_icon::{get_config_icons, update_icon::get_festival};
|
||||
use skynet_discord_bot::Config;
|
||||
|
||||
// use this to return what current festivals are active?
|
||||
|
@ -116,13 +125,13 @@ pub(crate) mod user {
|
|||
|
||||
let config_toml = get_config_icons::full(&config);
|
||||
|
||||
let mut response = vec![];
|
||||
let response = get_festival(&config_toml).current;
|
||||
|
||||
for festival in &config_toml.festivals {
|
||||
response.push(festival.name.to_owned());
|
||||
if response.is_empty() {
|
||||
"No festival currently active".to_string()
|
||||
} else {
|
||||
format!("Festivals active: {}", response.join(", "))
|
||||
}
|
||||
|
||||
format!("Festivals active: {}", response.join(", "))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -170,6 +179,10 @@ pub(crate) mod user {
|
|||
}
|
||||
|
||||
fn fmt_msg(config_toml: &ConfigTomlLocal, totals: &Vec<CountResult>) -> String {
|
||||
let mut totals_local = totals.clone();
|
||||
totals_local.sort_by_key(|x| x.times);
|
||||
totals_local.reverse();
|
||||
|
||||
// msg can be a max 2000 chars long
|
||||
let mut limit = 2000 - 3;
|
||||
|
||||
|
@ -177,7 +190,7 @@ pub(crate) mod user {
|
|||
for CountResult {
|
||||
name,
|
||||
times,
|
||||
} in totals
|
||||
} in &totals_local
|
||||
{
|
||||
let current_leading = if times < &10 {
|
||||
"00"
|
||||
|
@ -189,7 +202,9 @@ pub(crate) mod user {
|
|||
|
||||
let url = get_logo_url(config_toml, name);
|
||||
|
||||
let line = format!("{}{} <{}>", current_leading, times, url);
|
||||
// the `` is so that the numbers will be rendered in monospaced font
|
||||
// the <> is to suppress the URL embed
|
||||
let line = format!("``{}{}`` [{}](<{}>)", current_leading, times, name, url);
|
||||
|
||||
let length = line.len() + 1;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue