feat: tidied up the command outouts
This commit is contained in:
parent
86f54aec6d
commit
0f4524ea63
3 changed files with 35 additions and 16 deletions
|
@ -2,6 +2,7 @@
|
|||
CREATE TABLE IF NOT EXISTS server_icons (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
path TEXT NOT NULL,
|
||||
date TEXT NOT NULL
|
||||
);
|
||||
|
||||
|
|
|
@ -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,16 +125,16 @@ pub(crate) mod user {
|
|||
|
||||
let config_toml = get_config_icons::full(&config);
|
||||
|
||||
let mut response = vec![];
|
||||
|
||||
for festival in &config_toml.festivals {
|
||||
response.push(festival.name.to_owned());
|
||||
}
|
||||
let response = get_festival(&config_toml).current;
|
||||
|
||||
if response.is_empty() {
|
||||
"No festival currently active".to_string()
|
||||
} else {
|
||||
format!("Festivals active: {}", response.join(", "))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the statistics of the icons
|
||||
pub(crate) mod stats {
|
||||
|
@ -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;
|
||||
|
||||
|
|
|
@ -72,6 +72,7 @@ pub struct LogoData {
|
|||
pub struct ServerIcons {
|
||||
pub id: i64,
|
||||
pub name: String,
|
||||
pub path: String,
|
||||
pub date: String,
|
||||
}
|
||||
|
||||
|
@ -120,12 +121,12 @@ pub mod update_icon {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct FestivalData {
|
||||
current: Vec<String>,
|
||||
pub struct FestivalData {
|
||||
pub current: Vec<String>,
|
||||
exclusions: Vec<String>,
|
||||
}
|
||||
|
||||
fn get_festival(config_toml: &ConfigToml) -> FestivalData {
|
||||
pub fn get_festival(config_toml: &ConfigToml) -> FestivalData {
|
||||
let today = Utc::now();
|
||||
let day = today.day();
|
||||
let month = today.month();
|
||||
|
@ -276,15 +277,17 @@ pub mod update_icon {
|
|||
|
||||
async fn logo_set_db(db: &Pool<Sqlite>, logo_selected: &LogoData) {
|
||||
let name = logo_selected.name.to_str().unwrap_or_default();
|
||||
let path = logo_selected.path.to_str().unwrap_or_default();
|
||||
|
||||
match sqlx::query_as::<_, ServerIcons>(
|
||||
"
|
||||
INSERT OR REPLACE INTO server_icons (name, date)
|
||||
VALUES (?1, ?2)
|
||||
INSERT OR REPLACE INTO server_icons (name, date, path)
|
||||
VALUES (?1, ?2, ?3)
|
||||
",
|
||||
)
|
||||
.bind(name)
|
||||
.bind(get_now_iso(false))
|
||||
.bind(path)
|
||||
.fetch_optional(db)
|
||||
.await
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue