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 (
|
CREATE TABLE IF NOT EXISTS server_icons (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
|
path TEXT NOT NULL,
|
||||||
date 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, "icon", "Information on current icon."))
|
||||||
.add_sub_option(CreateCommandOption::new(CommandOptionType::SubCommand, "festival", "Information on current festival.")),
|
.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 {
|
fn get_logo_url(config_toml: &ConfigTomlLocal, logo_name: &str) -> String {
|
||||||
|
@ -64,6 +64,7 @@ pub(crate) mod user {
|
||||||
|
|
||||||
pub(crate) mod icon {
|
pub(crate) mod icon {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use serenity::all::{CreateAttachment, EditInteractionResponse};
|
||||||
|
|
||||||
use sqlx::{Pool, Sqlite};
|
use sqlx::{Pool, Sqlite};
|
||||||
|
|
||||||
|
@ -77,7 +78,15 @@ pub(crate) mod user {
|
||||||
let config_toml = get_config_icons::minimal();
|
let config_toml = get_config_icons::minimal();
|
||||||
|
|
||||||
if let Some(logo) = get_current_icon(&db).await {
|
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 {
|
} else {
|
||||||
"Could not find current icon".to_string()
|
"Could not find current icon".to_string()
|
||||||
}
|
}
|
||||||
|
@ -102,8 +111,8 @@ pub(crate) mod user {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) mod festival {
|
pub(crate) mod festival {
|
||||||
use serenity::all::{CommandInteraction, CommandOptionType, Context, CreateCommand, CreateCommandOption};
|
use serenity::all::{CommandInteraction, Context};
|
||||||
use skynet_discord_bot::common::server_icon::get_config_icons;
|
use skynet_discord_bot::common::server_icon::{get_config_icons, update_icon::get_festival};
|
||||||
use skynet_discord_bot::Config;
|
use skynet_discord_bot::Config;
|
||||||
|
|
||||||
// use this to return what current festivals are active?
|
// 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 config_toml = get_config_icons::full(&config);
|
||||||
|
|
||||||
let mut response = vec![];
|
let response = get_festival(&config_toml).current;
|
||||||
|
|
||||||
for festival in &config_toml.festivals {
|
if response.is_empty() {
|
||||||
response.push(festival.name.to_owned());
|
"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 {
|
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
|
// msg can be a max 2000 chars long
|
||||||
let mut limit = 2000 - 3;
|
let mut limit = 2000 - 3;
|
||||||
|
|
||||||
|
@ -177,7 +190,7 @@ pub(crate) mod user {
|
||||||
for CountResult {
|
for CountResult {
|
||||||
name,
|
name,
|
||||||
times,
|
times,
|
||||||
} in totals
|
} in &totals_local
|
||||||
{
|
{
|
||||||
let current_leading = if times < &10 {
|
let current_leading = if times < &10 {
|
||||||
"00"
|
"00"
|
||||||
|
@ -189,7 +202,9 @@ pub(crate) mod user {
|
||||||
|
|
||||||
let url = get_logo_url(config_toml, name);
|
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;
|
let length = line.len() + 1;
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,7 @@ pub struct LogoData {
|
||||||
pub struct ServerIcons {
|
pub struct ServerIcons {
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub path: String,
|
||||||
pub date: String,
|
pub date: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,12 +121,12 @@ pub mod update_icon {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct FestivalData {
|
pub struct FestivalData {
|
||||||
current: Vec<String>,
|
pub current: Vec<String>,
|
||||||
exclusions: 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 today = Utc::now();
|
||||||
let day = today.day();
|
let day = today.day();
|
||||||
let month = today.month();
|
let month = today.month();
|
||||||
|
@ -276,15 +277,17 @@ pub mod update_icon {
|
||||||
|
|
||||||
async fn logo_set_db(db: &Pool<Sqlite>, logo_selected: &LogoData) {
|
async fn logo_set_db(db: &Pool<Sqlite>, logo_selected: &LogoData) {
|
||||||
let name = logo_selected.name.to_str().unwrap_or_default();
|
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>(
|
match sqlx::query_as::<_, ServerIcons>(
|
||||||
"
|
"
|
||||||
INSERT OR REPLACE INTO server_icons (name, date)
|
INSERT OR REPLACE INTO server_icons (name, date, path)
|
||||||
VALUES (?1, ?2)
|
VALUES (?1, ?2, ?3)
|
||||||
",
|
",
|
||||||
)
|
)
|
||||||
.bind(name)
|
.bind(name)
|
||||||
.bind(get_now_iso(false))
|
.bind(get_now_iso(false))
|
||||||
|
.bind(path)
|
||||||
.fetch_optional(db)
|
.fetch_optional(db)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue