Merge pull request #76 from miedzinski/ctcp-config
Use CTCP VERSION and SOURCE replies from Config
This commit is contained in:
commit
d68e998f44
3 changed files with 26 additions and 2 deletions
|
@ -88,6 +88,8 @@ fail for obvious reasons). That being said, here's an example of a complete conf
|
||||||
},
|
},
|
||||||
"umodes": "+RB-x",
|
"umodes": "+RB-x",
|
||||||
"user_info": "I'm a test user for the Rust IRC crate.",
|
"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_time": 180,
|
||||||
"ping_timeout": 10,
|
"ping_timeout": 10,
|
||||||
"options": {
|
"options": {
|
||||||
|
|
|
@ -42,6 +42,10 @@ pub struct Config {
|
||||||
pub umodes: Option<String>,
|
pub umodes: Option<String>,
|
||||||
/// The text that'll be sent in response to CTCP USERINFO requests.
|
/// The text that'll be sent in response to CTCP USERINFO requests.
|
||||||
pub user_info: Option<String>,
|
pub user_info: Option<String>,
|
||||||
|
/// The text that'll be sent in response to CTCP VERSION requests.
|
||||||
|
pub version: Option<String>,
|
||||||
|
/// The text that'll be sent in response to CTCP SOURCE requests.
|
||||||
|
pub source: Option<String>,
|
||||||
/// The amount of inactivity in seconds before the client will ping the server.
|
/// The amount of inactivity in seconds before the client will ping the server.
|
||||||
pub ping_time: Option<u32>,
|
pub ping_time: Option<u32>,
|
||||||
/// The amount of time in seconds for a client to reconnect due to no ping response.
|
/// 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[..])
|
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
|
/// Gets the amount of time in seconds since last activity necessary for the client to ping the
|
||||||
/// server.
|
/// server.
|
||||||
/// This defaults to 180 seconds when not specified.
|
/// This defaults to 180 seconds when not specified.
|
||||||
|
@ -227,6 +243,8 @@ mod test {
|
||||||
channels: Some(vec![format!("#test"), format!("#test2")]),
|
channels: Some(vec![format!("#test"), format!("#test2")]),
|
||||||
channel_keys: None,
|
channel_keys: None,
|
||||||
user_info: None,
|
user_info: None,
|
||||||
|
version: None,
|
||||||
|
source: None,
|
||||||
ping_time: None,
|
ping_time: None,
|
||||||
ping_timeout: None,
|
ping_timeout: None,
|
||||||
should_ghost: None,
|
should_ghost: None,
|
||||||
|
@ -254,6 +272,8 @@ mod test {
|
||||||
channels: Some(vec![format!("#test"), format!("#test2")]),
|
channels: Some(vec![format!("#test"), format!("#test2")]),
|
||||||
channel_keys: None,
|
channel_keys: None,
|
||||||
user_info: None,
|
user_info: None,
|
||||||
|
version: None,
|
||||||
|
source: None,
|
||||||
ping_time: None,
|
ping_time: None,
|
||||||
ping_timeout: None,
|
ping_timeout: None,
|
||||||
should_ghost: None,
|
should_ghost: None,
|
||||||
|
|
|
@ -464,9 +464,11 @@ impl IrcServer {
|
||||||
"FINGER" => self.send_ctcp_internal(resp, &format!(
|
"FINGER" => self.send_ctcp_internal(resp, &format!(
|
||||||
"FINGER :{} ({})", self.config().real_name(), self.config().username()
|
"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" => {
|
"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")
|
self.send_ctcp_internal(resp, "SOURCE")
|
||||||
},
|
},
|
||||||
"PING" if tokens.len() > 1 => {
|
"PING" if tokens.len() > 1 => {
|
||||||
|
|
Loading…
Reference in a new issue