From 95087349e7edd0d275fe788d4b5c9e7538579e02 Mon Sep 17 00:00:00 2001 From: Jacherr Date: Sun, 15 Sep 2024 21:01:47 +0100 Subject: [PATCH] add stats autocomplete --- assyst-core/src/command/misc/stats.rs | 27 +++++++++++++++++++++------ assyst-core/src/main.rs | 12 ------------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/assyst-core/src/command/misc/stats.rs b/assyst-core/src/command/misc/stats.rs index 278ee00..46e28b9 100644 --- a/assyst-core/src/command/misc/stats.rs +++ b/assyst-core/src/command/misc/stats.rs @@ -8,11 +8,23 @@ use assyst_string_fmt::{Ansi, Markdown}; use human_bytes::human_bytes; use twilight_model::gateway::SessionStartLimit; -use crate::command::arguments::Word; +use crate::assyst::ThreadSafeAssyst; +use crate::command::arguments::WordAutocomplete; +use crate::command::autocomplete::AutocompleteData; use crate::command::misc::key_value; use crate::command::{Availability, Category, CommandCtxt}; use crate::rest::filer::{get_filer_stats as filer_stats, FilerStats}; +async fn stats_autocomplete(_a: ThreadSafeAssyst, _d: AutocompleteData) -> Vec { + vec![ + "sessions".to_owned(), + "caches".to_owned(), + "processes".to_owned(), + "all".to_owned(), + "general".to_owned(), + ] +} + #[command( description = "get bot stats", cooldown = Duration::from_secs(5), @@ -22,7 +34,10 @@ use crate::rest::filer::{get_filer_stats as filer_stats, FilerStats}; examples = ["", "sessions", "storage", "processes", "all"], send_processing = true )] -pub async fn stats(ctxt: CommandCtxt<'_>, option: Option) -> anyhow::Result<()> { +pub async fn stats( + ctxt: CommandCtxt<'_>, + #[autocomplete = "crate::command::misc::stats::stats_autocomplete"] option: Option, +) -> anyhow::Result<()> { fn get_process_stats() -> String { let mem_usages = get_processes_mem_usage(); let mem_usages_fmt = mem_usages @@ -146,25 +161,25 @@ pub async fn stats(ctxt: CommandCtxt<'_>, option: Option) -> anyhow::Resul stats_table.codeblock("ansi") } - if let Some(Word(ref x)) = option + if let Some(WordAutocomplete(ref x)) = option && x.to_lowercase() == "sessions" { let table = get_session_stats(&ctxt).await?; ctxt.reply(table).await?; - } else if let Some(Word(ref x)) = option + } else if let Some(WordAutocomplete(ref x)) = option && (x.to_lowercase() == "caches" || x.to_lowercase() == "storage") { let table = get_storage_stats(&ctxt).await?; ctxt.reply(table).await?; - } else if let Some(Word(ref x)) = option + } else if let Some(WordAutocomplete(ref x)) = option && x.to_lowercase() == "processes" { let table = get_process_stats(); ctxt.reply(table).await?; - } else if let Some(Word(ref x)) = option + } else if let Some(WordAutocomplete(ref x)) = option && x.to_lowercase() == "all" { let stats_table = get_general_stats(&ctxt).await; diff --git a/assyst-core/src/main.rs b/assyst-core/src/main.rs index 163002d..e0b36fe 100644 --- a/assyst-core/src/main.rs +++ b/assyst-core/src/main.rs @@ -65,18 +65,6 @@ async fn main() { let assyst: ThreadSafeAssyst = Arc::new(Assyst::new().await.unwrap()); - println!( - "{:?}", - assyst - .http_client - .entitlements(assyst.application_id) - .await - .unwrap() - .model() - .await - .unwrap() - ); - // Custom panic hook that will send errors to a discord channel { let handle = tokio::runtime::Handle::current();