From fcb0c1da649b9c5af5710dbd799be72b28eba1c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Miedzi=C5=84ski?= Date: Wed, 22 Mar 2017 22:06:43 +0100 Subject: [PATCH] Use CTCP VERSION and SOURCE replies from Config --- README.md | 2 ++ src/client/data/config.rs | 20 ++++++++++++++++++++ src/client/server/mod.rs | 6 ++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1e65e77..50ced87 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,8 @@ fail for obvious reasons). That being said, here's an example of a complete conf }, "umodes": "+RB-x", "user_info": "I'm a test user for the Rust IRC crate.", + "version": "irc:git:Rust", + "source": "https://github.com/aatxe/irc", "ping_time": 180, "ping_timeout": 10, "options": { diff --git a/src/client/data/config.rs b/src/client/data/config.rs index 088adfc..cb32c73 100644 --- a/src/client/data/config.rs +++ b/src/client/data/config.rs @@ -42,6 +42,10 @@ pub struct Config { pub umodes: Option, /// The text that'll be sent in response to CTCP USERINFO requests. pub user_info: Option, + /// The text that'll be sent in response to CTCP VERSION requests. + pub version: Option, + /// The text that'll be sent in response to CTCP SOURCE requests. + pub source: Option, /// The amount of inactivity in seconds before the client will ping the server. pub ping_time: Option, /// The amount of time in seconds for a client to reconnect due to no ping response. @@ -169,6 +173,18 @@ impl Config { self.user_info.as_ref().map_or("", |s| &s[..]) } + /// Gets the string to be sent in response to CTCP VERSION requests. + /// This defaults to `irc:git:Rust` when not specified. + pub fn version(&self) -> &str { + self.version.as_ref().map_or("irc:git:Rust", |s| &s[..]) + } + + /// Gets the string to be sent in response to CTCP SOURCE requests. + /// This defaults to `https://github.com/aatxe/irc` when not specified. + pub fn source(&self) -> &str { + self.source.as_ref().map_or("https://github.com/aatxe/irc", |s| &s[..]) + } + /// Gets the amount of time in seconds since last activity necessary for the client to ping the /// server. /// This defaults to 180 seconds when not specified. @@ -227,6 +243,8 @@ mod test { channels: Some(vec![format!("#test"), format!("#test2")]), channel_keys: None, user_info: None, + version: None, + source: None, ping_time: None, ping_timeout: None, should_ghost: None, @@ -254,6 +272,8 @@ mod test { channels: Some(vec![format!("#test"), format!("#test2")]), channel_keys: None, user_info: None, + version: None, + source: None, ping_time: None, ping_timeout: None, should_ghost: None, diff --git a/src/client/server/mod.rs b/src/client/server/mod.rs index f893be7..efd707a 100644 --- a/src/client/server/mod.rs +++ b/src/client/server/mod.rs @@ -464,9 +464,11 @@ impl IrcServer { "FINGER" => self.send_ctcp_internal(resp, &format!( "FINGER :{} ({})", self.config().real_name(), self.config().username() )), - "VERSION" => self.send_ctcp_internal(resp, "VERSION irc:git:Rust"), + "VERSION" => { + self.send_ctcp_internal(resp, &format!("VERSION {}", self.config().version())) + }, "SOURCE" => { - try!(self.send_ctcp_internal(resp, "SOURCE https://github.com/aatxe/irc")); + try!(self.send_ctcp_internal(resp, &format!("SOURCE {}", self.config().source()))); self.send_ctcp_internal(resp, "SOURCE") }, "PING" if tokens.len() > 1 => {