2017-04-02 01:35:16 +02:00
|
|
|
# irc [![Build Status](https://travis-ci.org/aatxe/irc.svg?branch=master)](https://travis-ci.org/aatxe/irc) [![Crates.io](https://img.shields.io/crates/v/irc.svg)](https://crates.io/crates/irc) [![Built with Spacemacs](https://cdn.rawgit.com/syl20bnr/spacemacs/442d025779da2f62fc86c2082703697714db6514/assets/spacemacs-badge.svg)](http://spacemacs.org) #
|
2016-01-18 07:17:32 +01:00
|
|
|
A robust, thread-safe IRC library in Rust. The client portion is compliant with
|
2015-06-08 00:45:59 +02:00
|
|
|
[RFC 2812](http://tools.ietf.org/html/rfc2812), [IRCv3.1](http://ircv3.net/irc/3.1.html),
|
2016-01-18 07:17:32 +01:00
|
|
|
[IRCv3.2](http://ircv3.net/irc/3.2.html), and includes some additional, common features. It also
|
|
|
|
features automatic reconnection in unstable networking conditions, flexibility allowing easy unit
|
|
|
|
testing, and a number of useful built-in features for building a powerful client quickly. The
|
|
|
|
server portion is still a work in progress. You can find up-to-date, ready-to-use documentation
|
|
|
|
online [here](http://aatxe.github.io/irc/irc/). The documentation is generated with the default
|
|
|
|
features. These are, however, strictly optional and can be disabled accordingly.
|
2014-12-02 18:26:50 +01:00
|
|
|
|
|
|
|
## Getting Started ##
|
|
|
|
|
2016-04-24 02:36:38 +02:00
|
|
|
To start using this library with cargo, you can simply add `irc = "0.11.0"` to your dependencies to
|
2016-02-10 21:41:54 +01:00
|
|
|
your Cargo.toml file. You'll likely want to take a look at some of the examples, as well as the
|
2015-01-13 08:57:40 +01:00
|
|
|
documentation. You'll also be able to find a small template to get a feel for the library.
|
|
|
|
|
2016-01-18 07:17:32 +01:00
|
|
|
## Getting Started by Example ##
|
2014-12-02 18:26:50 +01:00
|
|
|
|
|
|
|
```rust
|
2014-12-05 16:27:58 +01:00
|
|
|
extern crate irc;
|
|
|
|
|
2016-06-30 20:09:25 +02:00
|
|
|
use std::default::Default;
|
2015-02-23 03:22:33 +01:00
|
|
|
use irc::client::prelude::*;
|
2014-12-05 16:27:58 +01:00
|
|
|
|
2014-12-02 18:26:50 +01:00
|
|
|
fn main() {
|
2016-06-30 20:09:25 +02:00
|
|
|
let cfg = Config {
|
|
|
|
nickname: Some(format!("irc-rs")),
|
|
|
|
server: Some(format!("irc.example.com")),
|
2017-01-08 21:52:54 +01:00
|
|
|
channels: Some(vec![format!("#test")]),
|
2016-06-30 20:09:25 +02:00
|
|
|
.. Default::default()
|
|
|
|
};
|
|
|
|
let server = IrcServer::from_config(cfg).unwrap();
|
2014-12-02 18:26:50 +01:00
|
|
|
server.identify().unwrap();
|
|
|
|
for message in server.iter() {
|
2014-12-05 16:27:58 +01:00
|
|
|
// Do message processing.
|
2014-12-02 18:26:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2014-11-05 08:11:33 +01:00
|
|
|
|
2016-01-18 07:17:32 +01:00
|
|
|
It may not seem like much, but all it takes to get started with an IRC connection is the stub
|
2017-05-17 23:58:35 +02:00
|
|
|
above. In just a few lines, you can be connected to a server and processing IRC messages as you
|
2016-01-18 07:17:32 +01:00
|
|
|
wish. The library is built with flexibility in mind. If you need to work on multiple threads,
|
|
|
|
simply clone the server and have at it. We'll take care of the rest.
|
|
|
|
|
2016-06-30 20:09:25 +02:00
|
|
|
You'll probably find that programmatic configuration is a bit of a chore, and you'll often want to
|
|
|
|
be able to change the configuration between runs of the program (for example, to change the server
|
|
|
|
that you're connecting to). Fortunately, runtime configuration loading is straightforward.
|
|
|
|
|
|
|
|
```rust
|
|
|
|
extern crate irc;
|
|
|
|
|
|
|
|
use irc::client::prelude::*;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let server = IrcServer::new("config.json").unwrap();
|
|
|
|
server.identify().unwrap();
|
|
|
|
for message in server.iter() {
|
|
|
|
// Do message processing.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2016-01-18 07:17:32 +01:00
|
|
|
## Configuration ##
|
|
|
|
|
|
|
|
Like the rest of the IRC crate, configuration is built with flexibility in mind. You can easily
|
|
|
|
create `Config` objects programmatically and choose your own methods for handling any saving or
|
|
|
|
loading of configuration required. However, for convenience, we've also included the option of
|
|
|
|
loading JSON files with `rust-serialize` to write configurations. All the fields are optional, and
|
|
|
|
thus any of them can be omitted (though, omitting a nickname or server will cause the program to
|
|
|
|
fail for obvious reasons). That being said, here's an example of a complete configuration:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"owners": [],
|
|
|
|
"nickname": "user",
|
|
|
|
"nick_password": "password",
|
|
|
|
"alt_nicks": ["user_", "user__"],
|
|
|
|
"username": "user",
|
|
|
|
"realname": "Test User",
|
|
|
|
"server": "chat.freenode.net",
|
|
|
|
"port": 6697,
|
|
|
|
"password": "",
|
|
|
|
"use_ssl": true,
|
|
|
|
"encoding": "UTF-8",
|
2016-07-05 22:22:31 +02:00
|
|
|
"channels": ["#rust", "#haskell", "#fake"],
|
|
|
|
"channel_keys": {
|
|
|
|
"#fake": "password"
|
|
|
|
},
|
2016-01-18 07:17:32 +01:00
|
|
|
"umodes": "+RB-x",
|
|
|
|
"user_info": "I'm a test user for the Rust IRC crate.",
|
2017-03-22 22:06:43 +01:00
|
|
|
"version": "irc:git:Rust",
|
|
|
|
"source": "https://github.com/aatxe/irc",
|
2016-01-18 07:17:32 +01:00
|
|
|
"ping_time": 180,
|
|
|
|
"ping_timeout": 10,
|
|
|
|
"options": {
|
|
|
|
"key": "value",
|
|
|
|
"note": "anything you want can be in here!",
|
2016-04-24 02:35:21 +02:00
|
|
|
"and": "you can use it to build your own additional configuration options."
|
2016-01-18 07:17:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
2014-11-05 08:11:33 +01:00
|
|
|
## Contributing ##
|
2015-02-20 04:44:33 +01:00
|
|
|
Contributions to this library would be immensely appreciated. It should be noted that as this is a
|
|
|
|
public domain project, any contributions will thus be released into the public domain as well.
|