Removed trailing whitespace.
This commit is contained in:
parent
a5306f8391
commit
05186cf670
15 changed files with 52 additions and 52 deletions
|
@ -13,20 +13,20 @@ fn main() {
|
|||
.. Default::default()
|
||||
};
|
||||
let server = Arc::new(IrcServer::from_config(config).unwrap());
|
||||
// FIXME: if set_keepalive is stabilized, this can be readded.
|
||||
// FIXME: if set_keepalive is stabilized, this can be readded.
|
||||
// server.conn().set_keepalive(Some(5)).unwrap();
|
||||
let server = server.clone();
|
||||
let _ = spawn(move || {
|
||||
let _ = spawn(move || {
|
||||
server.identify().unwrap();
|
||||
loop {
|
||||
let mut quit = false;
|
||||
for msg in server.iter() {
|
||||
match msg {
|
||||
Ok(msg) => {
|
||||
Ok(msg) => {
|
||||
print!("{}", msg.into_string());
|
||||
match (&msg).into() {
|
||||
Ok(Command::PRIVMSG(_, msg)) => if msg.contains("bye") {
|
||||
server.send_quit("").unwrap()
|
||||
Ok(Command::PRIVMSG(_, msg)) => if msg.contains("bye") {
|
||||
server.send_quit("").unwrap()
|
||||
},
|
||||
Ok(Command::ERROR(ref msg)) if msg.contains("Quit") => quit = true,
|
||||
_ => (),
|
||||
|
@ -39,5 +39,5 @@ fn main() {
|
|||
server.reconnect().unwrap();
|
||||
server.identify().unwrap();
|
||||
}
|
||||
}).join();
|
||||
}).join();
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ fn main() {
|
|||
let server = Arc::new(IrcServer::from_config(config).unwrap());
|
||||
server.identify().unwrap();
|
||||
let server = server.clone();
|
||||
let _ = spawn(move || {
|
||||
let _ = spawn(move || {
|
||||
for msg in server.iter() {
|
||||
print!("{}", msg.unwrap().into_string());
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ fn main() {
|
|||
channels: Some(vec![format!("#vana")]),
|
||||
.. Default::default()
|
||||
};
|
||||
let server = IrcServer::from_config(config).unwrap();
|
||||
let server = IrcServer::from_config(config).unwrap();
|
||||
server.identify().unwrap();
|
||||
for message in server.iter() {
|
||||
let message = message.unwrap(); // We'll just panic if there's an error.
|
||||
|
|
|
@ -11,7 +11,7 @@ fn main() {
|
|||
channels: Some(vec![format!("#vana")]),
|
||||
.. Default::default()
|
||||
};
|
||||
let server = IrcServer::from_config(config).unwrap();
|
||||
let server = IrcServer::from_config(config).unwrap();
|
||||
server.identify().unwrap();
|
||||
for command in server.iter_cmd() {
|
||||
// Use of unwrap() on the results of iter_cmd() is discouraged since response codes will be
|
||||
|
|
|
@ -11,13 +11,13 @@ fn main() {
|
|||
server: Some(format!("irc.fyrechat.net")),
|
||||
channels: Some(vec![format!("#vana")]),
|
||||
.. Default::default()
|
||||
};
|
||||
};
|
||||
let server = Arc::new(IrcServer::from_config(config).unwrap());
|
||||
server.identify().unwrap();
|
||||
let server2 = server.clone();
|
||||
// Let's set up a loop that just prints the messages.
|
||||
spawn(move || {
|
||||
server2.iter().map(|m| print!("{}", m.unwrap().into_string())).count();
|
||||
spawn(move || {
|
||||
server2.iter().map(|m| print!("{}", m.unwrap().into_string())).count();
|
||||
});
|
||||
loop {
|
||||
server.send_privmsg("#vana", "TWEET TWEET").unwrap();
|
||||
|
|
|
@ -79,7 +79,7 @@ impl Connection<BufReader<NetStream>, BufWriter<NetStream>> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
FIXME: removed until set_keepalive is stabilized.
|
||||
/// Sets the keepalive for the network stream.
|
||||
|
@ -120,7 +120,7 @@ impl<T: IrcRead, U: IrcWrite> Connection<T, U> {
|
|||
let msg: Message = to_msg.into();
|
||||
let data = match encoding.encode(&msg.into_string(), EncoderTrap::Replace) {
|
||||
Ok(data) => data,
|
||||
Err(data) => return Err(Error::new(ErrorKind::InvalidInput,
|
||||
Err(data) => return Err(Error::new(ErrorKind::InvalidInput,
|
||||
&format!("Failed to encode {} as {}.", data, encoding.name())[..]
|
||||
))
|
||||
};
|
||||
|
@ -129,7 +129,7 @@ impl<T: IrcRead, U: IrcWrite> Connection<T, U> {
|
|||
writer.flush()
|
||||
}
|
||||
|
||||
/// Sends a message over this connection.
|
||||
/// Sends a message over this connection.
|
||||
#[cfg(not(feature = "encode"))]
|
||||
pub fn send<M: Into<Message>>(&self, to_msg: M) -> Result<()> {
|
||||
let mut writer = self.writer.lock().unwrap();
|
||||
|
@ -152,7 +152,7 @@ impl<T: IrcRead, U: IrcWrite> Connection<T, U> {
|
|||
match encoding.decode(&buf, DecoderTrap::Replace) {
|
||||
_ if buf.is_empty() => Err(Error::new(ErrorKind::Other, "EOF")),
|
||||
Ok(data) => Ok(data),
|
||||
Err(data) => return Err(Error::new(ErrorKind::InvalidInput,
|
||||
Err(data) => return Err(Error::new(ErrorKind::InvalidInput,
|
||||
&format!("Failed to decode {} as {}.", data, encoding.name())[..]
|
||||
))
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ impl<T: IrcRead, U: IrcWrite> Connection<T, U> {
|
|||
fn ssl_to_io<T>(res: StdResult<T, SslError>) -> Result<T> {
|
||||
match res {
|
||||
Ok(x) => Ok(x),
|
||||
Err(e) => Err(Error::new(ErrorKind::Other,
|
||||
Err(e) => Err(Error::new(ErrorKind::Other,
|
||||
&format!("An SSL error occurred. ({})", e.description())[..]
|
||||
)),
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ mod test {
|
|||
let data = String::from_utf8(conn.writer().to_vec()).unwrap();
|
||||
assert_eq!(&data[..], "PRIVMSG test :Testing!\r\n");
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
#[cfg(not(feature = "encode"))]
|
||||
fn send_str() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Enumeration of all supported IRCv3 capability extensions.
|
||||
|
||||
/// List of all supported IRCv3 capability extensions from the
|
||||
/// [IRCv3 specifications](http://ircv3.net/irc/).
|
||||
/// [IRCv3 specifications](http://ircv3.net/irc/).
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Capability {
|
||||
/// [multi-prefix](http://ircv3.net/specs/extensions/multi-prefix-3.1.html)
|
||||
|
|
|
@ -461,7 +461,7 @@ impl<'a> From<&'a Message> for Result<Command> {
|
|||
} else if m.args.len() == 2 {
|
||||
Command::JOIN(m.args[0].clone(), Some(m.args[1].clone()), None)
|
||||
} else if m.args.len() == 3 {
|
||||
Command::JOIN(m.args[0].clone(), Some(m.args[1].clone()),
|
||||
Command::JOIN(m.args[0].clone(), Some(m.args[1].clone()),
|
||||
Some(m.args[2].clone()))
|
||||
} else {
|
||||
return Err(invalid_input())
|
||||
|
@ -750,7 +750,7 @@ impl<'a> From<&'a Message> for Result<Command> {
|
|||
} else if m.args.len() == 1 {
|
||||
Command::WHOWAS(m.args[0].clone(), None, Some(suffix.clone()))
|
||||
} else if m.args.len() == 2 {
|
||||
Command::WHOWAS(m.args[0].clone(), Some(m.args[1].clone()),
|
||||
Command::WHOWAS(m.args[0].clone(), Some(m.args[1].clone()),
|
||||
Some(suffix.clone()))
|
||||
} else {
|
||||
return Err(invalid_input())
|
||||
|
@ -760,7 +760,7 @@ impl<'a> From<&'a Message> for Result<Command> {
|
|||
} else if m.args.len() == 2 {
|
||||
Command::WHOWAS(m.args[0].clone(), None, Some(m.args[1].clone()))
|
||||
} else if m.args.len() == 3 {
|
||||
Command::WHOWAS(m.args[0].clone(), Some(m.args[1].clone()),
|
||||
Command::WHOWAS(m.args[0].clone(), Some(m.args[1].clone()),
|
||||
Some(m.args[2].clone()))
|
||||
} else {
|
||||
return Err(invalid_input())
|
||||
|
@ -854,7 +854,7 @@ impl<'a> From<&'a Message> for Result<Command> {
|
|||
} else if m.args.len() == 1 {
|
||||
Command::SUMMON(m.args[0].clone(), Some(suffix.clone()), None)
|
||||
} else if m.args.len() == 2 {
|
||||
Command::SUMMON(m.args[0].clone(), Some(m.args[1].clone()),
|
||||
Command::SUMMON(m.args[0].clone(), Some(m.args[1].clone()),
|
||||
Some(suffix.clone()))
|
||||
} else {
|
||||
return Err(invalid_input())
|
||||
|
@ -864,7 +864,7 @@ impl<'a> From<&'a Message> for Result<Command> {
|
|||
} else if m.args.len() == 2 {
|
||||
Command::SUMMON(m.args[0].clone(), Some(m.args[1].clone()), None)
|
||||
} else if m.args.len() == 3 {
|
||||
Command::SUMMON(m.args[0].clone(), Some(m.args[1].clone()),
|
||||
Command::SUMMON(m.args[0].clone(), Some(m.args[1].clone()),
|
||||
Some(m.args[2].clone()))
|
||||
} else {
|
||||
return Err(invalid_input())
|
||||
|
@ -1044,7 +1044,7 @@ impl<'a> From<&'a Message> for Result<Command> {
|
|||
} else if m.args.len() == 2 {
|
||||
if let Ok(cmd) = m.args[0].parse() {
|
||||
match m.suffix {
|
||||
Some(ref suffix) => Command::CAP(None, cmd, Some(m.args[1].clone()),
|
||||
Some(ref suffix) => Command::CAP(None, cmd, Some(m.args[1].clone()),
|
||||
Some(suffix.clone())),
|
||||
None => Command::CAP(None, cmd, Some(m.args[1].clone()), None),
|
||||
}
|
||||
|
@ -1060,7 +1060,7 @@ impl<'a> From<&'a Message> for Result<Command> {
|
|||
} else if m.args.len() == 3 {
|
||||
if let Ok(cmd) = m.args[1].parse() {
|
||||
match m.suffix {
|
||||
Some(ref suffix) => Command::CAP(Some(m.args[0].clone()), cmd,
|
||||
Some(ref suffix) => Command::CAP(Some(m.args[0].clone()), cmd,
|
||||
Some(m.args[2].clone()),
|
||||
Some(suffix.clone())),
|
||||
None => Command::CAP(Some(m.args[0].clone()), cmd, Some(m.args[2].clone()),
|
||||
|
|
|
@ -50,7 +50,7 @@ impl Config {
|
|||
let mut file = try!(File::open(path));
|
||||
let mut data = String::new();
|
||||
try!(file.read_to_string(&mut data));
|
||||
decode(&data[..]).map_err(|_|
|
||||
decode(&data[..]).map_err(|_|
|
||||
Error::new(ErrorKind::InvalidInput, "Failed to decode configuration file.")
|
||||
)
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ impl Config {
|
|||
/// Gets the channels to join upon connection.
|
||||
/// This defaults to an empty vector if it's not specified.
|
||||
pub fn channels(&self) -> Vec<&str> {
|
||||
self.channels.as_ref().map(|v| v.iter().map(|s| &s[..]).collect()).unwrap_or(vec![])
|
||||
self.channels.as_ref().map(|v| v.iter().map(|s| &s[..]).collect()).unwrap_or(vec![])
|
||||
}
|
||||
|
||||
/// Gets the user modes to set on connect specified in the configuration.
|
||||
|
|
|
@ -45,7 +45,7 @@ impl Message {
|
|||
}
|
||||
}
|
||||
|
||||
/// Gets the nickname of the message source, if it exists.
|
||||
/// Gets the nickname of the message source, if it exists.
|
||||
pub fn get_source_nickname(&self) -> Option<&str> {
|
||||
self.prefix.as_ref().and_then(|s| s.find('!').map(|i| &s[..i]))
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ pub enum Response {
|
|||
RPL_ENDOFEXCEPTLIST = 349,
|
||||
/// 351 <version>.<debuglevel> <server> :<comments>
|
||||
RPL_VERSION = 351,
|
||||
/// 352 <channel> <user> <host> <server> <nick> ( "H" / "G" > ["*"] [ ( "@" / "+" ) ]
|
||||
/// 352 <channel> <user> <host> <server> <nick> ( "H" / "G" > ["*"] [ ( "@" / "+" ) ]
|
||||
/// :<hopcount> <real name>
|
||||
RPL_WHOREPLY = 352,
|
||||
/// 315 <name> :End of WHO list
|
||||
|
@ -95,7 +95,7 @@ pub enum Response {
|
|||
RPL_INFO = 371,
|
||||
/// 374 :End of INFO list
|
||||
RPL_ENDOFINFO = 374,
|
||||
/// 375 :- <server> Message of the day -
|
||||
/// 375 :- <server> Message of the day -
|
||||
RPL_MOTDSTART = 375,
|
||||
/// 372 :- <text>
|
||||
RPL_MOTD = 372,
|
||||
|
@ -190,7 +190,7 @@ pub enum Response {
|
|||
/// 733 <nick> :End of MONITOR list
|
||||
RPL_ENDOFMONLIST = 733,
|
||||
|
||||
|
||||
|
||||
// Error replies
|
||||
/// 401 <nickname> :No such nick/channel
|
||||
ERR_NOSUCHNICK = 401,
|
||||
|
@ -304,11 +304,11 @@ pub enum Response {
|
|||
|
||||
impl Response {
|
||||
/// Gets a response from a message.
|
||||
pub fn from_message(m: &Message) -> Option<Response> {
|
||||
pub fn from_message(m: &Message) -> Option<Response> {
|
||||
m.command.parse().ok()
|
||||
}
|
||||
|
||||
/// Determines whether or not this response is an error response.
|
||||
/// Determines whether or not this response is an error response.
|
||||
pub fn is_error(&self) -> bool {
|
||||
*self as u16 >= 400
|
||||
}
|
||||
|
@ -320,12 +320,12 @@ impl FromStr for Response {
|
|||
if let Ok(rc) = s.parse::<u16>() {
|
||||
// This wall of text was brought to you by the removal of FromPrimitive.
|
||||
if (rc > 0 && rc < 5) || (rc > 200 && rc < 213) || rc == 219 || rc == 221 || rc == 234
|
||||
|| rc == 235 || rc == 242 || rc == 243 || (rc > 250 && rc < 260) ||
|
||||
(rc > 260 && rc < 264) || (rc > 300 && rc < 307) ||
|
||||
(rc > 310 && rc < 326 && rc != 320) || rc == 331 || rc == 332 || rc == 341 ||
|
||||
rc == 342 || (rc > 345 && rc < 354 && rc != 350) ||
|
||||
(rc > 363 && rc < 377 && rc != 370) || (rc > 380 && rc < 384) ||
|
||||
(rc > 390 && rc < 396) || (rc > 400 && rc < 415 && rc != 410) ||
|
||||
|| rc == 235 || rc == 242 || rc == 243 || (rc > 250 && rc < 260) ||
|
||||
(rc > 260 && rc < 264) || (rc > 300 && rc < 307) ||
|
||||
(rc > 310 && rc < 326 && rc != 320) || rc == 331 || rc == 332 || rc == 341 ||
|
||||
rc == 342 || (rc > 345 && rc < 354 && rc != 350) ||
|
||||
(rc > 363 && rc < 377 && rc != 370) || (rc > 380 && rc < 384) ||
|
||||
(rc > 390 && rc < 396) || (rc > 400 && rc < 415 && rc != 410) ||
|
||||
(rc > 420 && rc < 425) || (rc > 430 && rc < 434) || rc == 436 || rc == 437 ||
|
||||
(rc > 440 && rc < 447) || rc == 451 || (rc > 460 && rc < 468) ||
|
||||
(rc > 470 && rc < 479) || (rc > 480 && rc < 486) || rc == 491 || rc == 501 ||
|
||||
|
@ -336,7 +336,7 @@ impl FromStr for Response {
|
|||
}
|
||||
} else {
|
||||
Err("Failed to parse response code.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ impl User {
|
|||
nickname: nickname,
|
||||
username: username,
|
||||
hostname: hostname,
|
||||
access_levels: {
|
||||
access_levels: {
|
||||
let mut ranks = ranks.clone();
|
||||
ranks.push(AccessLevel::Member);
|
||||
ranks
|
||||
|
@ -96,7 +96,7 @@ impl User {
|
|||
/// Adds an access level to the list, and updates the highest level if necessary.
|
||||
fn add_access_level(&mut self, level: AccessLevel) {
|
||||
if level > self.highest_access_level() {
|
||||
self.highest_access_level = level
|
||||
self.highest_access_level = level
|
||||
}
|
||||
self.access_levels.push(level.clone())
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ impl PartialOrd for AccessLevel {
|
|||
}
|
||||
},
|
||||
&AccessLevel::Member => Some(Less),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ pub mod prelude {
|
|||
#[cfg(test)]
|
||||
pub mod test {
|
||||
use std::io::{BufReader, Empty, empty};
|
||||
|
||||
|
||||
pub fn buf_empty() -> BufReader<Empty> {
|
||||
BufReader::new(empty())
|
||||
}
|
||||
|
|
|
@ -125,7 +125,7 @@ impl<T: IrcRead, U: IrcWrite> IrcServer<T, U> {
|
|||
if resp == Response::RPL_NAMREPLY {
|
||||
if cfg!(not(feature = "nochanlists")) {
|
||||
if let Some(users) = msg.suffix.clone() {
|
||||
if msg.args.len() == 3 {
|
||||
if msg.args.len() == 3 {
|
||||
// TODO: replace with slice pattern matching when/if stable
|
||||
let ref chan = msg.args[2];
|
||||
for user in users.split(" ") {
|
||||
|
@ -133,7 +133,7 @@ impl<T: IrcRead, U: IrcWrite> IrcServer<T, U> {
|
|||
Some(vec) => { vec.push(User::new(user)); false },
|
||||
None => true,
|
||||
} {
|
||||
self.chanlists.lock().unwrap().insert(chan.clone(),
|
||||
self.chanlists.lock().unwrap().insert(chan.clone(),
|
||||
vec!(User::new(user)));
|
||||
}
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ impl<T: IrcRead, U: IrcWrite> IrcServer<T, U> {
|
|||
}
|
||||
if &msg.command[..] == "PING" {
|
||||
self.send(PONG(msg.suffix.as_ref().unwrap().to_owned(), None)).unwrap();
|
||||
} else if cfg!(not(feature = "nochanlists")) &&
|
||||
} else if cfg!(not(feature = "nochanlists")) &&
|
||||
(&msg.command[..] == "JOIN" || &msg.command[..] == "PART") {
|
||||
let chan = match msg.suffix {
|
||||
Some(ref suffix) => &suffix[..],
|
||||
|
@ -234,7 +234,7 @@ impl<T: IrcRead, U: IrcWrite> IrcServer<T, U> {
|
|||
self.send_ctcp_internal(resp, "SOURCE");
|
||||
},
|
||||
"PING" => self.send_ctcp_internal(resp, &format!("PING {}", tokens[1])),
|
||||
"TIME" => self.send_ctcp_internal(resp, &format!("TIME :{}",
|
||||
"TIME" => self.send_ctcp_internal(resp, &format!("TIME :{}",
|
||||
now().rfc822z())),
|
||||
"USERINFO" => self.send_ctcp_internal(resp, &format!("USERINFO :{}",
|
||||
self.config.user_info())),
|
||||
|
@ -293,7 +293,7 @@ impl<'a, T: IrcRead, U: IrcWrite> Iterator for ServerIterator<'a, T, U> {
|
|||
self.server.handle_message(&msg);
|
||||
Ok(msg)
|
||||
},
|
||||
Err(_) => Err(Error::new(ErrorKind::InvalidInput,
|
||||
Err(_) => Err(Error::new(ErrorKind::InvalidInput,
|
||||
&format!("Failed to parse message. (Message: {})", msg)[..]
|
||||
))
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ pub trait ServerExt<'a, T, U>: Server<'a, T, U> {
|
|||
self.send(INVITE(nick.to_owned(), chan.to_owned()))
|
||||
}
|
||||
|
||||
/// Quits the server entirely with a message.
|
||||
/// Quits the server entirely with a message.
|
||||
/// This defaults to `Powered by Rust.` if none is specified.
|
||||
fn send_quit(&self, msg: &str) -> Result<()> where Self: Sized {
|
||||
self.send(QUIT(Some(if msg.len() == 0 {
|
||||
|
@ -212,7 +212,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn identify() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
server.identify().unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "CAP END\r\nNICK :test\r\n\
|
||||
|
|
Loading…
Reference in a new issue