diff --git a/Cargo.toml b/Cargo.toml index 752bc8c..3315972 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "steel" -version = "0.7.1" +version = "0.7.2" edition = "2021" build = "src/build.rs" diff --git a/crates/steel_core/src/ipc/server.rs b/crates/steel_core/src/ipc/server.rs index 2fb23c4..d415d84 100644 --- a/crates/steel_core/src/ipc/server.rs +++ b/crates/steel_core/src/ipc/server.rs @@ -21,4 +21,6 @@ pub enum AppMessageIn { UIChatMessageSent { target: String, text: String }, UISettingsRequested, UISettingsUpdated(Settings), + + ChatModeratorAdded(String), } diff --git a/crates/steel_core/src/ipc/ui.rs b/crates/steel_core/src/ipc/ui.rs index 9cbcc16..8d66049 100644 --- a/crates/steel_core/src/ipc/ui.rs +++ b/crates/steel_core/src/ipc/ui.rs @@ -20,4 +20,5 @@ pub enum UIMessageIn { ChatSwitchRequested(String, usize), ChannelJoined(String), ChatClosed(String), + ChatModeratorAdded(String), } diff --git a/src/app/mod.rs b/src/app/mod.rs index b6c2c55..9b4508d 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -57,6 +57,9 @@ impl Application { AppMessageIn::ChannelJoined(channel) => { self.handle_channel_join(channel); } + AppMessageIn::ChatModeratorAdded(username) => { + self.handle_chat_moderator_added(username); + } AppMessageIn::UIConnectRequested => { self.connect(); @@ -117,35 +120,10 @@ impl Application { pub fn load_settings(&mut self, source: settings::Source, fallback: bool) { self.state.settings = settings::Settings::from_file(&source, fallback); - self.setup_mod_users(); + self.handle_chat_moderator_added("BanchoBot".into()); self.ui_handle_settings_requested(); } - // TODO: remove when osu!api integration is ready - // Snapshots taken on 2023-07-23 - #[rustfmt::skip] - fn setup_mod_users(&mut self) { - for mods in [ - &mut self.state.settings.ui.dark_colours.mod_users, - &mut self.state.settings.ui.light_colours.mod_users, - ] { - for group in [ - // GMT -- https://osu.ppy.sh/groups/4 - ["- Felix", "[ Another ]", "[ryuu]", "0x84f", "abraker", "Albionthegreat", "Azer", "bibitaru", "Burak", "ChillierPear", "chromb", "Civil oath", "Corne2Plum3", "D I O", "Death", "Dntm8kmeeatu", "Edward", "Ephemeral", "Flutteh", "Galkan", "Ganondorf", "Halfslashed", "Imakuri", "JBHyperion", "Jerry", "kanpakyin", "Kobold84", "KSHR", "Kudou Chitose", "Kyubey", "Laurakko", "LeoFLT", "Loctav", "maot", "MillhioreF", "My Angel Chino", "Nathanael", "Nevo", "Niva", "Nozhomi", "Okoratu", "OnosakiHito", "Osu Tatakae Ouendan", "osu!team", "p3n", "Petal", "Petit", "Protastic101", "QHideaki13", "Redo_", "Repflez", "Roan", "RockRoller", "ruexia", "S o h", "Saten", "Shiro", "Shurelia", "Sies", "spboxer3", "terho", "THAT_otaku", "TicClick", "TKS", "ToGlette", "topecnz", "Trigonoculus", "Trosk-", "Uni", "Venix", "Yason", "Zallius",] - .as_slice(), - // NAT -- https://osu.ppy.sh/groups/7 - ["-Mo-", "AirinCat", "Akasha-", "Capu", "Chaoslitz", "Dada", "Deif", "elicz1", "Enneya", "Firika", "FuJu", "Garden", "Greaper", "gzdongsheng", "Hivie", "Ideal", "Maxus", "Naxess", "Noffy", "Nomination Assessment Team", "Petal", "pishifat", "radar", "Secre", "StarCastler", "Stixy", "Tailsdk", "yaspo", "Yogurtt", "Zelq",] - .as_slice(), - // DEV -- https://osu.ppy.sh/groups/11 - ["Damnae", "Domco", "Ephemeral", "flyte", "MillhioreF", "nanaya", "nekodex", "notbakaneko", "osu!team", "peppy", "RBRat3", "smoogipoo", "ThePooN", "Tom94",] - .as_slice(), - ] { - mods.extend(group.iter().map(|u| u.to_lowercase().replace(' ', "_"))) - } - mods.insert("banchobot".into()); - } - } - pub fn ui_handle_settings_requested(&self) { self.ui_queue .blocking_send(UIMessageIn::SettingsChanged(self.state.settings.clone())) @@ -279,6 +257,12 @@ impl Application { .unwrap(); } + pub fn handle_chat_moderator_added(&mut self, username: String) { + self.ui_queue + .blocking_send(UIMessageIn::ChatModeratorAdded(username)) + .unwrap(); + } + pub fn connect(&mut self) { match self.state.connection { ConnectionStatus::Connected | ConnectionStatus::InProgress => {} diff --git a/src/core/irc/event_handler.rs b/src/core/irc/event_handler.rs index 3a0f06d..83b6033 100644 --- a/src/core/irc/event_handler.rs +++ b/src/core/irc/event_handler.rs @@ -1,6 +1,7 @@ use tokio::sync::mpsc::Sender; use irc::client::prelude::*; +use irc_proto::mode::{ChannelMode, Mode}; use steel_core::chat::irc::IRCError; use steel_core::chat::{Message, MessageType}; @@ -111,14 +112,30 @@ pub fn dispatch_message( Command::Response( Response::RPL_TOPIC | // channel topic Response::RPL_TOPICWHOTIME | // channel topic author/mtime - Response::RPL_NAMREPLY | // channel users Response::RPL_ENDOFNAMES, // channel users .. ) | // PING and PONG are handled by the library Command::PING(..) | - Command::PONG(..) | - Command::ChannelMODE(..) => self::empty_handler(sender, msg), + Command::PONG(..) => self::empty_handler(sender, msg), + Command::ChannelMODE(_, modes) => { + for m in modes { + if let Mode::Plus(ChannelMode::Oper, Some(user)) = m { + sender.blocking_send(AppMessageIn::ChatModeratorAdded(user)).unwrap(); + } + } + } + + Command::Response( + Response::RPL_NAMREPLY, + cmd + ) => { + if let Some(users) = cmd.get(3) { + for user in users.split_ascii_whitespace().filter(|u| u.starts_with('@')) { + sender.blocking_send(AppMessageIn::ChatModeratorAdded(user[1..].to_owned())).unwrap(); + } + } + }, Command::Response( Response::RPL_WELCOME | diff --git a/src/gui/window.rs b/src/gui/window.rs index 0692715..1831caf 100644 --- a/src/gui/window.rs +++ b/src/gui/window.rs @@ -261,6 +261,15 @@ impl ApplicationWindow { UIMessageIn::ChatClosed(name) => { self.s.remove_chat(name); } + + UIMessageIn::ChatModeratorAdded(name) => { + for mods in [ + &mut self.s.settings.ui.dark_colours.mod_users, + &mut self.s.settings.ui.light_colours.mod_users, + ] { + mods.insert(name.to_lowercase().replace(' ', "_")); + } + } } } }