• Stars
    star
    532
  • Rank 83,377 (Top 2 %)
  • Language
    Rust
  • License
    Mozilla Public Li...
  • Created about 10 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

the irc crate – usable, async IRC for Rust

the irc crate Build Status Crates.io Downloads Docs

"the irc crate" is a thread-safe and async-friendly IRC client library written in Rust. It's compliant with RFC 2812, IRCv3.1, IRCv3.2, and includes some additional, common features from popular IRCds. You can find up-to-date, ready-to-use documentation online on docs.rs.

Built with the irc crate

the irc crate is being used to build new IRC software in Rust. Here are some of our favorite projects:

Making your own project? Submit a pull request to add it!

Getting Started

To start using the irc crate with cargo, you can add irc = "0.13" to your dependencies in your Cargo.toml file. The high-level API can be found in irc::client::prelude. You'll find a number of examples to help you get started in examples/, throughout the documentation, and below.

Using Futures

The release of v0.14 replaced all existing APIs with one based on async/await.

use irc::client::prelude::*;
use futures::prelude::*;

#[tokio::main]
async fn main() -> Result<(), failure::Error> {
    // We can also load the Config at runtime via Config::load("path/to/config.toml")
    let config = Config {
        nickname: Some("the-irc-crate".to_owned()),
        server: Some("chat.freenode.net".to_owned()),
        channels: vec!["#test".to_owned()],
        ..Config::default()
    };

    let mut client = Client::from_config(config).await?;
    client.identify()?;

    let mut stream = client.stream()?;

    while let Some(message) = stream.next().await.transpose()? {
        print!("{}", message);
    }

    Ok(())
}

Example Cargo.toml file:

[package]
name = "example"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
irc = "0.15.0"
tokio = { version = "1.0.0", features = ["rt", "rt-multi-thread", "macros", "net", "time"] }
futures = "0.3.0"
failure = "0.1.8"

Configuring IRC Clients

As seen above, there are two techniques for configuring the irc crate: runtime loading and programmatic configuration. Runtime loading is done via the function Config::load, and is likely sufficient for most IRC bots. Programmatic configuration is convenient for writing tests, but can also be useful when defining your own custom configuration format that can be converted to Config. The primary configuration format is TOML, but if you are so inclined, you can use JSON and/or YAML via the optional json_config and yaml_config features respectively. At the minimum, a configuration requires nickname and server to be defined, and all other fields are optional. You can find detailed explanations of the various fields on docs.rs.

Alternatively, you can look at the example below of a TOML configuration with all the fields:

owners = []
nickname = "user"
nick_password = "password"
alt_nicks = ["user_", "user__"]
username = "user"
realname = "Test User"
server = "chat.freenode.net"
port = 6697
password = ""
proxy_type = "None"
proxy_server = "127.0.0.1"
proxy_port = "1080"
proxy_username = ""
proxy_password = ""
use_tls = true
cert_path = "cert.der"
client_cert_path = "client.der"
client_cert_pass = "password"
encoding = "UTF-8"
channels = ["#rust", "#haskell", "#fake"]
umodes = "+RB-x"
user_info = "I'm a test user for the irc crate."
version = "irc:git:Rust"
source = "https://github.com/aatxe/irc"
ping_time = 180
ping_timeout = 20
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"

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 easier for users to migrate their old configurations to TOML.

Contributing

the irc crate is a free, open source library that relies on contributions from its maintainers, Aaron Weiss (@aatxe) and Peter Atashian (@retep998), as well as the broader Rust community. It's licensed under the Mozilla Public License 2.0 whose text can be found in LICENSE.md. To foster an inclusive community around the irc crate, we have adopted a Code of Conduct whose text can be found in CODE_OF_CONDUCT.md. You can find details about how to contribute in CONTRIBUTING.md.

More Repositories

1

oxide

The essence of Rust.
OCaml
122
star
2

Orpheus

Open Source MapleStory Server Emulator (v83)
Java
97
star
3

markov

A generic markov chain implementation in Rust.
Rust
85
star
4

alectro

A terminal IRC client in Rust.
Rust
68
star
5

OpenMaple

A fast MapleStory emulator aiming to bring openness back to the private server community.
Java
21
star
6

pkgnx

Blazing fast binary data format for video games – PKG4 for Java
Java
12
star
7

spilo

A minimalistic IRC bouncer in Rust.
Rust
10
star
8

diet-coke

A small functional language with effect inference based on Koka.
Scala
9
star
9

cube.idr

An implementation of the Lambda Cube in Idris.
Idris
7
star
10

meep

A simple pasting service with syntax highlighting support.
Rust
6
star
11

Ultimate-Ascent

FIRST Team 1923's official repository for the 2013 game, Ultimate Ascent.
Java
5
star
12

awebot

An IRC bot in Rust.
Rust
5
star
13

tokio-mockstream

A fake stream for testing network applications backed by buffers.
Rust
5
star
14

Team-1923-Rebound-Rumble

Team 1923's software for the FIRST Robotics Competition for 2012.
Java
4
star
15

life-sim

An artificial life simulator in Rust.
Rust
4
star
16

tomato

Java MapleStory Server Emulator - v111
Java
4
star
17

amomentoflove.org

Share your appreciation with someone you love.
HTML
3
star
18

irc-services

A unified IRC services bot in Rust, used long ago by PdgnCo but replaced with anope.
Rust
3
star
19

dotfiles

My configuration files and whatnot.
Emacs Lisp
3
star
20

dnd

An IRC bot in Rust for playing Dungeons and Dragons.
Rust
3
star
21

sanguinello

🍊
Rust
2
star
22

libjinx2

A Java library for the NX file format.
Java
2
star
23

rip

Rest in peace.
Rust
2
star
24

weiss.city

The latest in a long line of personal websites.
CSS
2
star
25

Tupelo

A (work-in-progress) IRC client for the 21st Century.
JavaScript
2
star
26

reasoning-with-types

Corresponding example code from my blog post "Reasoning with Types in Rust"
Rust
2
star
27

awebot-plugins

A collection of plugins for awebot.
Rust
1
star
28

critters

A modern, extensible Creatures clone.
C++
1
star
29

hamelin.rs

An implementation of Hamelin in Rust.
Rust
1
star
30

chipster

A fast CHIP-8 emulator with indie cred.
C
1
star
31

minuet

A simple, lightweight utility library for C.
1
star
32

srcerror

An exercise in data modelling and frustration.
Java
1
star
33

pixalia

The worst, best MMO client ever.
Java
1
star
34

vr.pyv

A specification of Viewstamped Replication in mypvy.
1
star
35

theraphosa

Snakes on the web? I think they're getting eaten.
JavaScript
1
star
36

pixalia-server

The worst, best MMO server ever.
Java
1
star
37

hacl-rs

Rusty bindings for HACL*, a formally verified cryptographic library written in F*.
Rust
1
star
38

heuler

Project Euler problems in (poor) Haskell.
Haskell
1
star