Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate irc;
- extern crate dotenv;
- use irc::client::server::IrcServer;
- use irc::client::data::config::Config;
- use dotenv::dotenv;
- use std::env;
- fn main() {
- dotenv().ok();
- for (key, value) in env::vars() {
- println!("ITER: {}: {}", key, value);
- }
- let port_string = get_env_var("IRC_PORT");
- let port = if let Some(ref port_string) = port_string {
- Some(port_string.parse::<u16>().unwrap())
- } else {
- None
- };
- let config = Config {
- owners: get_split_env_var("IRC_OWNERS"),
- nickname: get_env_var("IRC_NICKNAME"),
- nick_password: get_env_var("IRC_PASSWORD"),
- alt_nicks: get_split_env_var("IRC_NICKNAME_ALTS"),
- username: get_env_var("IRC_USERNAME"),
- realname: get_env_var("IRC_REALNAME"),
- server: get_env_var("IRC_SERVER"),
- port: port,
- password: get_env_var("IRC_SERVER_PASSWORD"),
- use_ssl: Some(true),
- encoding: Some(String::from("UTF-8")),
- channels: get_split_env_var("IRC_CHANNELS"),
- // umodes: Some(String::from("+BCdi")),
- umodes: None,
- user_info: get_env_var("IRC_USER_INFO"),
- ping_time: Some(180),
- ping_timeout: Some(10),
- should_ghost: Some(true),
- ghost_sequence: None,
- options: None
- };
- let server = IrcServer::from_config(config).unwrap();
- }
- /// A helper method to split the given string into a `Vec` of `String`s by `,`.
- fn split_to_vec(var: String) -> Vec<String> {
- var.split(",").map(|i| i.to_owned()).collect::<Vec<String>>()
- }
- fn get_env_var(key: &str) -> Option<String> {
- let val = env::var(key);
- match val {
- Ok(s) => { println!("{}: {}", key, s); Some(s) },
- Err(_) => { println!("{}: None", key); None },
- }
- }
- fn get_split_env_var(key: &str) -> Option<Vec<String>> {
- let val = get_env_var(key);
- match val {
- Some(s) => { Some(split_to_vec(s)) },
- None => { None }
- }
- }
- #[test]
- fn test_split() {
- assert_eq!(vec![String::from("abc"), String::from("def")], split_to_vec(String::from("abc,def")));
- assert_eq!(vec![String::from("abc")], split_to_vec(String::from("abc")));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement