Skip to content

Commit

Permalink
Merge pull request #52 from TicClick/re-introduce-mod-names
Browse files Browse the repository at this point in the history
  • Loading branch information
TicClick authored Jan 6, 2024
2 parents e0be0ec + b4888bf commit cf7671b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "steel"
version = "0.7.1"
version = "0.7.2"
edition = "2021"
build = "src/build.rs"

Expand Down
2 changes: 2 additions & 0 deletions crates/steel_core/src/ipc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ pub enum AppMessageIn {
UIChatMessageSent { target: String, text: String },
UISettingsRequested,
UISettingsUpdated(Settings),

ChatModeratorAdded(String),
}
1 change: 1 addition & 0 deletions crates/steel_core/src/ipc/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ pub enum UIMessageIn {
ChatSwitchRequested(String, usize),
ChannelJoined(String),
ChatClosed(String),
ChatModeratorAdded(String),
}
36 changes: 10 additions & 26 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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 => {}
Expand Down
23 changes: 20 additions & 3 deletions src/core/irc/event_handler.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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 |
Expand Down
9 changes: 9 additions & 0 deletions src/gui/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ', "_"));
}
}
}
}
}
Expand Down

0 comments on commit cf7671b

Please sign in to comment.