Added JOIN to config
This commit is contained in:
parent
f1eb3c337c
commit
c399d2569b
30
src/lib.rs
30
src/lib.rs
|
@ -7,10 +7,12 @@ pub struct Client {
|
|||
config: Config,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Config {
|
||||
username: String,
|
||||
nickname: String,
|
||||
mode: String,
|
||||
channels: Box<[&'static str]>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -26,6 +28,7 @@ pub enum Command {
|
|||
CAP(CapMode),
|
||||
USER(String, String, String, String),
|
||||
NICK(String),
|
||||
JOIN(String),
|
||||
OTHER(String),
|
||||
}
|
||||
|
||||
|
@ -59,6 +62,21 @@ impl Client {
|
|||
))?;
|
||||
self.write_command(Command::NICK(self.config.nickname.clone()))?;
|
||||
|
||||
loop {
|
||||
if let Ok(ref command) = self.read() {
|
||||
if let Command::OTHER(line) = command {
|
||||
if line.contains("001") {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let config = self.config.clone();
|
||||
for channel in config.channels.iter() {
|
||||
self.write_command(Command::JOIN(channel.to_string()))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -119,6 +137,10 @@ impl Client {
|
|||
let formatted = format!("PONG {}", code);
|
||||
Cow::Owned(formatted) as Cow<str>
|
||||
}
|
||||
JOIN(channel) => {
|
||||
let formatted = format!("JOIN {}", channel);
|
||||
Cow::Owned(formatted) as Cow<str>
|
||||
}
|
||||
OTHER(_) => {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
|
@ -134,11 +156,17 @@ impl Client {
|
|||
}
|
||||
|
||||
impl Config {
|
||||
pub fn new(username: &str, nickname: Option<&str>, mode: Option<&str>) -> Self {
|
||||
pub fn new(
|
||||
username: &str,
|
||||
nickname: Option<&str>,
|
||||
mode: Option<&str>,
|
||||
channels: Box<[&'static str]>,
|
||||
) -> Self {
|
||||
Self {
|
||||
username: username.into(),
|
||||
nickname: nickname.unwrap_or(username).into(),
|
||||
mode: mode.unwrap_or("").into(),
|
||||
channels: channels.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,9 +10,14 @@ macro_rules! loop_n {
|
|||
}
|
||||
|
||||
fn main() -> Result<(), std::io::Error> {
|
||||
let config = Config::new("test", Some("test"), Some("+B"));
|
||||
let config = Config::new(
|
||||
"test",
|
||||
Some("test"),
|
||||
Some("+B"),
|
||||
Box::new(["#main", "#main2"]),
|
||||
);
|
||||
let mut client =
|
||||
Client::new("192.168.1.28", 6667, config).expect("Unable to connect to IRC server");
|
||||
Client::new("192.168.178.100", 6667, config).expect("Unable to connect to IRC server");
|
||||
client.identify()?;
|
||||
|
||||
loop {
|
||||
|
|
Loading…
Reference in a new issue