2017-12-13 20:31:28 +01:00
|
|
|
# irc [![Build Status][ci-badge]][ci] [![Crates.io][cr-badge]][cr] [![Docs][doc-badge]][doc] [![Built with Spacemacs][bws]][sm]
|
|
|
|
|
2018-01-09 05:42:03 +01:00
|
|
|
[ci-badge]: https://travis-ci.org/aatxe/irc.svg?branch=stable
|
2017-12-13 20:31:28 +01:00
|
|
|
[ci]: https://travis-ci.org/aatxe/irc
|
|
|
|
[cr-badge]: https://img.shields.io/crates/v/irc.svg
|
|
|
|
[cr]: https://crates.io/crates/irc
|
|
|
|
[doc-badge]: https://docs.rs/irc/badge.svg
|
|
|
|
[doc]: https://docs.rs/irc
|
|
|
|
[bws]: https://cdn.rawgit.com/syl20bnr/spacemacs/442d025779da2f62fc86c2082703697714db6514/assets/spacemacs-badge.svg
|
|
|
|
[sm]: http://spacemacs.org
|
|
|
|
|
|
|
|
A robust, thread-safe and async-friendly library for IRC clients in Rust. It's 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
|
2017-12-13 20:31:28 +01:00
|
|
|
includes a number of useful built-in features to faciliate rapid development of clients. You can
|
|
|
|
find up-to-date, ready-to-use documentation online [here](https://docs.rs/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 ##
|
|
|
|
|
2018-01-28 04:27:08 +01:00
|
|
|
To start using this library with cargo, you can simply add `irc = "0.13"` to your dependencies in
|
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
|
2017-08-05 02:31:45 +02:00
|
|
|
documentation. You'll also be able to find below a small template to get a feel for the library.
|
2015-01-13 08:57:40 +01:00
|
|
|
|
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();
|
2017-06-22 04:07:53 +02:00
|
|
|
server.for_each_incoming(|message| {
|
2014-12-05 16:27:58 +01:00
|
|
|
// Do message processing.
|
2017-06-25 11:00:44 +02:00
|
|
|
}).unwrap()
|
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() {
|
2017-12-30 19:06:47 +01:00
|
|
|
let server = IrcServer::new("config.toml").unwrap();
|
2016-06-30 20:09:25 +02:00
|
|
|
server.identify().unwrap();
|
2017-06-22 04:07:53 +02:00
|
|
|
server.for_each_incoming(|message| {
|
2016-06-30 20:09:25 +02:00
|
|
|
// Do message processing.
|
2017-06-25 11:00:44 +02:00
|
|
|
}).unwrap()
|
2016-06-30 20:09:25 +02:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
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
|
2018-01-27 21:10:22 +01:00
|
|
|
loading files with `serde` to write configurations. The default configuration format is TOML,
|
|
|
|
though there is optional support for JSON and YAML via the optional `json` and `yaml` features. All
|
|
|
|
the configuration fields are optional, and can thus be omitted, but a working configuration requires
|
2018-01-27 21:12:56 +01:00
|
|
|
at least a `server` and `nickname`. You can find detailed explanations of the configuration format
|
|
|
|
[here](https://docs.rs/irc/0.12.8/irc/client/data/config/struct.Config.html#fields).
|
2017-08-05 02:31:45 +02:00
|
|
|
|
|
|
|
Here's an example of a complete configuration in TOML:
|
|
|
|
|
|
|
|
```toml
|
|
|
|
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
|
|
|
|
cert_path = "cert.der"
|
|
|
|
encoding = "UTF-8"
|
|
|
|
channels = ["#rust", "#haskell", "#fake"]
|
|
|
|
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
|
|
|
|
burst_window_length = 8
|
|
|
|
max_messages_in_burst = 15
|
|
|
|
should_ghost = false
|
|
|
|
ghost_sequence = []
|
|
|
|
|
|
|
|
[channel_keys]
|
|
|
|
"#fake" = "password"
|
|
|
|
|
|
|
|
[options]
|
|
|
|
note = "anything you want can be in here!"
|
|
|
|
and = "you can use it to build your own additional configuration options."
|
|
|
|
key = "value"
|
2016-01-18 07:17:32 +01:00
|
|
|
```
|
|
|
|
|
2017-12-13 20:31:28 +01:00
|
|
|
You can convert between different configuration formats with `convertconf` like so:
|
|
|
|
|
|
|
|
```
|
|
|
|
cargo run --example convertconf -- -i client_config.json -o client_config.toml
|
|
|
|
```
|
|
|
|
|
|
|
|
Note that the formats are automatically determined based on the selected file extensions. This
|
|
|
|
tool should make it easy for users to migrate their old configurations to TOML.
|
|
|
|
|
2014-11-05 08:11:33 +01:00
|
|
|
## Contributing ##
|
2017-12-13 20:31:28 +01:00
|
|
|
Contributions to this library would be immensely appreciated. Prior to version 0.12.0, this
|
|
|
|
library was public domain. As of 0.12.0, this library is offered under the Mozilla Public License
|
2017-12-25 03:56:38 +01:00
|
|
|
2.0 whose text can be found in `LICENSE.md`. Fostering an inclusive community around `irc` is
|
2018-01-27 20:53:12 +01:00
|
|
|
important, and to that end, we've adopted an explicit Code of Conduct found in `CODE_OF_CONDUCT.md`.
|