docs.rs failed to build twitchchat-0.8.0-beta.3
Please check the
build logs for more information.
See
Builds for ideas on how to fix a failed build,
or
Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault,
open an issue.
twitchchat
This crate provides a way to interace with Twitch's chat.
Along with the messages as Rust types, it provides methods for sending messages.
License
twitchchat
is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.
A demo of the API:
#[tokio::main]
async fn main() {
use futures::prelude::*;
let (nick, pass) = (
std::env::var("TWITCH_NICK").unwrap(),
std::env::var("TWITCH_PASS").unwrap(),
);
let channel = std::env::var("TWITCH_CHANNEL").unwrap();
let (read, write) = twitchchat::connect_easy(&nick, &pass, twitchchat::Secure::Nope)
.await
.unwrap();
let client = twitchchat::Client::new();
let done = client.run(read, write);
let mut dispatcher = client.dispatcher().await;
let mut privmsg = dispatcher.subscribe::<twitchchat::events::Privmsg>();
tokio::task::spawn(async move {
while let Some(msg) = privmsg.next().await {
eprintln!("[{}] {}: {}", msg.channel, msg.user, msg.data);
}
});
let mut join = dispatcher.subscribe::<twitchchat::events::Join>();
tokio::task::spawn(async move {
while let Some(msg) = join.next().await {
if msg.user == nick {
eprintln!("you joined {}", msg.channel);
break; }
}
});
let mut bot = dispatcher.subscribe::<twitchchat::events::Privmsg>();
let bot_client = client.clone();
tokio::task::spawn(async move {
let mut writer = bot_client.writer();
while let Some(msg) = bot.next().await {
match msg.data.split(" ").next() {
Some("!quit") => {
bot_client.stop().await.unwrap();
}
Some("!hello") => {
let response = format!("hello {}!", msg.user);
if let Err(_err) = writer.privmsg(&msg.channel, &response).await {
return;
}
}
_ => {}
}
}
});
drop(dispatcher);
if let Err(err) = client.writer().join(&channel).await {
match err {
twitchchat::Error::InvalidChannel(..) => {
eprintln!("you cannot join a channel with an empty name. demo is ending");
std::process::exit(1);
}
_ => {
}
}
}
match done.await {
Ok(twitchchat::client::Status::Eof) => {
eprintln!("done!");
}
Ok(twitchchat::client::Status::Canceled) => {
eprintln!("client was stopped by user");
}
Err(err) => {
eprintln!("error: {}", err);
}
}
client.dispatcher().await.clear_subscriptions_all();
}