From 155d1558401a734f81596b281ab0b7b8afc98a9b Mon Sep 17 00:00:00 2001 From: TicClick Date: Sun, 4 Feb 2024 02:03:02 +0100 Subject: [PATCH] Add `/shrug` chat command (#81) --- src/gui/command.rs | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/gui/command.rs b/src/gui/command.rs index 9750aa4..f9497fd 100644 --- a/src/gui/command.rs +++ b/src/gui/command.rs @@ -14,7 +14,9 @@ trait Command { fn preferred_alias(&self) -> &String { self.aliases().first().unwrap() } - fn example(&self) -> &str; + fn example(&self) -> &str { + self.preferred_alias() + } fn argcount(&self) -> usize; fn ui_hint(&self, ui: &mut egui::Ui) { @@ -124,9 +126,6 @@ impl Command for CloseChat { fn description(&self) -> &str { "close the active tab, or leave the channel" } - fn example(&self) -> &str { - self.preferred_alias() - } fn aliases(&self) -> &Vec { &self.aliases } @@ -156,9 +155,6 @@ impl Command for ClearChat { fn description(&self) -> &str { "clear the active tab, removing all messages" } - fn example(&self) -> &str { - self.preferred_alias() - } fn aliases(&self) -> &Vec { &self.aliases } @@ -188,9 +184,6 @@ impl Command for ShowUsage { fn description(&self) -> &str { "show a guide around the application" } - fn example(&self) -> &str { - self.preferred_alias() - } fn aliases(&self) -> &Vec { &self.aliases } @@ -205,6 +198,35 @@ impl Command for ShowUsage { } } +struct Shrug { + pub aliases: Vec, +} + +impl Command for Shrug { + fn new() -> Self { + Self { + aliases: ["/shrug".into()].to_vec(), + } + } + fn description(&self) -> &str { + "¯\\_(ツ)_/¯" + } + fn aliases(&self) -> &Vec { + &self.aliases + } + fn argcount(&self) -> usize { + 0 + } + fn ui_title(&self) -> egui::RichText { + egui::RichText::new(self.preferred_alias()) + } + fn action(&self, state: &UIState, _args: Vec) { + state + .core + .chat_message_sent(&state.active_chat_tab_name, "¯\\_(ツ)_/¯"); + } +} + pub struct CommandHelper { commands: Vec>, } @@ -218,6 +240,7 @@ impl Default for CommandHelper { Box::new(CloseChat::new()), Box::new(ClearChat::new()), Box::new(ShowUsage::new()), + Box::new(Shrug::new()), ], }; s.commands