Skip to content

Commit

Permalink
Merge pull request #112 from TicClick/channel-qf
Browse files Browse the repository at this point in the history
  • Loading branch information
TicClick authored Apr 21, 2024
2 parents 26d2bb5 + 5271649 commit 39010c5
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 5 deletions.
35 changes: 34 additions & 1 deletion crates/steel_core/src/chat/links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ impl Message {
// Channel name.
if i < bs.len() && bs[i] == b'#' {
i += 1;
while i < bs.len() && ((b'a' <= bs[i] && bs[i] <= b'z') || bs[i] == b'_') {
while i < bs.len()
&& ((b'a' <= bs[i] && bs[i] <= b'z')
|| bs[i] == b'_'
|| (b'0' <= bs[i] && bs[i] <= b'9'))
{
i += 1;
}
// '#' is an invalid channel name -- skip it.
Expand Down Expand Up @@ -684,4 +688,33 @@ mod tests {
]
);
}

#[test]
fn plain_channel_names() {
let message = m("Check this out: #russian + #mp_10966036 + #spect_672931 = ???");
assert_eq!(
message.chunks.unwrap(),
vec![
MessageChunk::Text("Check this out: ".into()),
MessageChunk::Link {
location: "#russian".into(),
title: "#russian".into(),
link_type: LinkType::Channel,
},
MessageChunk::Text(" + ".into()),
MessageChunk::Link {
location: "#mp_10966036".into(),
title: "#mp_10966036".into(),
link_type: LinkType::Channel,
},
MessageChunk::Text(" + ".into()),
MessageChunk::Link {
location: "#spect_672931".into(),
title: "#spect_672931".into(),
link_type: LinkType::Channel,
},
MessageChunk::Text(" = ???".into()),
]
);
}
}
44 changes: 40 additions & 4 deletions src/gui/command.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use eframe::egui;
use steel_core::chat::ChatLike;

use super::state::UIState;

Expand Down Expand Up @@ -90,14 +91,14 @@ struct OpenChat {
impl Command for OpenChat {
fn new() -> Self {
Self {
aliases: ["/chat".into(), "/query".into(), "/q".into(), "/join".into()].to_vec(),
aliases: ["/chat".into(), "/query".into(), "/q".into()].to_vec(),
}
}
fn description(&self) -> &str {
"open a chat tab with user, or join a new #channel"
"open a chat tab with a user"
}
fn example(&self) -> &str {
"/chat #russian"
"/chat BanchoBot"
}
fn aliases(&self) -> &Vec<String> {
&self.aliases
Expand All @@ -106,13 +107,47 @@ impl Command for OpenChat {
1
}
fn ui_title(&self) -> egui::RichText {
egui::RichText::new("/chat <user or #channel>")
egui::RichText::new("/chat <user>")
}
fn action(&self, state: &UIState, args: Vec<String>) {
state.core.private_chat_opened(&args[0]);
}
}

struct JoinChannel {
pub aliases: Vec<String>,
}

impl Command for JoinChannel {
fn new() -> Self {
Self {
aliases: ["/join".into(), "/j".into()].to_vec(),
}
}
fn description(&self) -> &str {
"join a channel"
}
fn example(&self) -> &str {
"/join #mapping"
}
fn aliases(&self) -> &Vec<String> {
&self.aliases
}
fn argcount(&self) -> usize {
1
}
fn ui_title(&self) -> egui::RichText {
egui::RichText::new("/join <#channel>")
}
fn action(&self, state: &UIState, args: Vec<String>) {
if args[0].is_channel() {
state.core.private_chat_opened(&args[0]);
} else {
state.core.private_chat_opened(&format!("#{}", &args[0]));
}
}
}

struct CloseChat {
pub aliases: Vec<String>,
}
Expand Down Expand Up @@ -237,6 +272,7 @@ impl Default for CommandHelper {
commands: vec![
Box::new(Me::new()),
Box::new(OpenChat::new()),
Box::new(JoinChannel::new()),
Box::new(CloseChat::new()),
Box::new(ClearChat::new()),
Box::new(ShowUsage::new()),
Expand Down

0 comments on commit 39010c5

Please sign in to comment.