Crates.io | irc3 |
lib.rs | irc3 |
version | 0.3.0 |
source | src |
created_at | 2020-03-20 22:04:27.027384 |
updated_at | 2020-03-21 21:39:13.062864 |
description | An IRC3 client and server toolchain |
homepage | https://gitlab.com/FrostBytes/irc3-rs |
repository | https://gitlab.com/FrostBytes/irc3-rs |
max_upload_size | |
id | 220801 |
size | 36,362 |
Good, Rusty IRC for the humans.
If you're looking for a time-tested library, irc3
is not for you. Releases are coming out every day with new bugs
and other scary issues. Please go check out the irc crate instead. Otherwise, happy
debugging!
Get started by installing irc3 and an async runtime
(tokio in this example). You will also need the
futures abstractions to directly interact with the Stream
/Sink
API.
irc3 = "0.2"
tokio = "0.2"
futures = "0.3"
You first begin by creating an unsecure client with a Client::new(...)
, and then sending any necessary
authentication messages (such as PASS
, NICK
and USER
). Then, just listen for any incoming messages that
have a PING
command, and reply with a PONG
command. The commands will look similar to this:
> PING :tmi.twitch.tv
< PONG :tmi.twitch.tv
You can implement this in Rust:
extern crate tokio;
extern crate irc3;
extern crate futures;
use std::env::var;
use irc3::Client;
use futures::stream::StreamExt as _;
use futures::sink::SinkExt as _;
#[tokio::main]
async fn main() {
// build a client
let mut client = Client::new("irc.chat.twitch.tv").await.unwrap();
client.send(Message::new("PASS").with_param(&var("IRC3_RS_PASSWORD").unwrap())).await.unwrap();
client.send(Message::new("NICK").with_param(&var("IRC3_RS_NICKNAME").unwrap())).await.unwrap();
loop {
let message = match client.next().await {
Some(res) => res,
None => break,
}.unwrap();
if message.command() == "PING" {
client.send(Message::new("PONG").with_param(message.params().last().unwrap())).await.unwrap();
}
}
}
You may use the Client::new_secure(...)
function to create TLS encrypted connections. All the TLS is
handled at the time of connection, so you don't have to type anything extra.
The irc3
crate wants to support servers, but the code isn't there yet. However, the technology is there.
Using the MessageTransport
struct, you can wait and then accept connections from clients.
If you want the Server
abstractions, come back later! Or, you can come and help!