Merge pull request #14 from filipegoncalves/master
Added config support to set umodes on connect.
This commit is contained in:
commit
ced1b7fa9a
2 changed files with 16 additions and 1 deletions
|
@ -29,6 +29,8 @@ pub struct Config {
|
||||||
/// The bot's real name.
|
/// The bot's real name.
|
||||||
#[stable]
|
#[stable]
|
||||||
pub realname: Option<String>,
|
pub realname: Option<String>,
|
||||||
|
/// User modes to set on connect. Example: "+RB-x"
|
||||||
|
pub umodes: Option<String>,
|
||||||
/// The server to connect to.
|
/// The server to connect to.
|
||||||
#[stable]
|
#[stable]
|
||||||
pub server: Option<String>,
|
pub server: Option<String>,
|
||||||
|
@ -119,6 +121,13 @@ impl Config {
|
||||||
self.realname.as_ref().map(|s| &s[]).unwrap_or(self.nickname())
|
self.realname.as_ref().map(|s| &s[]).unwrap_or(self.nickname())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets the user modes set on connect specified in the configuration.
|
||||||
|
/// This defaults to an empty string when not specified.
|
||||||
|
#[stable]
|
||||||
|
pub fn umodes(&self) -> &str {
|
||||||
|
self.umodes.as_ref().map(|s| &s[]).unwrap_or("")
|
||||||
|
}
|
||||||
|
|
||||||
/// Gets the address of the server specified in the configuration.
|
/// Gets the address of the server specified in the configuration.
|
||||||
/// This panics when not specified.
|
/// This panics when not specified.
|
||||||
#[stable]
|
#[stable]
|
||||||
|
@ -197,6 +206,7 @@ mod test {
|
||||||
username: Some(format!("test")),
|
username: Some(format!("test")),
|
||||||
realname: Some(format!("test")),
|
realname: Some(format!("test")),
|
||||||
password: Some(String::new()),
|
password: Some(String::new()),
|
||||||
|
umodes: Some(format!("+BR")),
|
||||||
server: Some(format!("irc.test.net")),
|
server: Some(format!("irc.test.net")),
|
||||||
port: Some(6667),
|
port: Some(6667),
|
||||||
use_ssl: Some(false),
|
use_ssl: Some(false),
|
||||||
|
@ -217,6 +227,7 @@ mod test {
|
||||||
alt_nicks: None,
|
alt_nicks: None,
|
||||||
username: Some(format!("test")),
|
username: Some(format!("test")),
|
||||||
realname: Some(format!("test")),
|
realname: Some(format!("test")),
|
||||||
|
umodes: Some(format!("+BR")),
|
||||||
password: Some(String::new()),
|
password: Some(String::new()),
|
||||||
server: Some(format!("irc.test.net")),
|
server: Some(format!("irc.test.net")),
|
||||||
port: Some(6667),
|
port: Some(6667),
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::old_io::{BufferedReader, BufferedWriter, IoError, IoErrorKind, IoResult
|
||||||
use std::sync::{Mutex, RwLock};
|
use std::sync::{Mutex, RwLock};
|
||||||
use client::conn::{Connection, NetStream};
|
use client::conn::{Connection, NetStream};
|
||||||
use client::data::{Command, Config, Message, Response, User};
|
use client::data::{Command, Config, Message, Response, User};
|
||||||
use client::data::Command::{JOIN, NICK, NICKSERV, PONG};
|
use client::data::Command::{JOIN, NICK, NICKSERV, PONG, MODE};
|
||||||
use client::data::kinds::{IrcReader, IrcWriter};
|
use client::data::kinds::{IrcReader, IrcWriter};
|
||||||
#[cfg(feature = "ctcp")] use time::now;
|
#[cfg(feature = "ctcp")] use time::now;
|
||||||
|
|
||||||
|
@ -147,6 +147,10 @@ impl<T: IrcReader, U: IrcWriter> IrcServer<T, U> {
|
||||||
&format!("IDENTIFY {}", self.config.nick_password())[]
|
&format!("IDENTIFY {}", self.config.nick_password())[]
|
||||||
)).unwrap();
|
)).unwrap();
|
||||||
}
|
}
|
||||||
|
if self.config.umodes() != "" {
|
||||||
|
self.send(MODE(
|
||||||
|
self.config.nickname(), self.config.umodes(), None)).unwrap();
|
||||||
|
}
|
||||||
for chan in self.config.channels().into_iter() {
|
for chan in self.config.channels().into_iter() {
|
||||||
self.send(JOIN(&chan[], None)).unwrap();
|
self.send(JOIN(&chan[], None)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue