23 lines
770 B
Rust
23 lines
770 B
Rust
use anyhow::Result;
|
|
use irc::client::prelude::{Capability, Client as IrcClient, Config as IrcConfig};
|
|
use crate::app::twitch::Twitch;
|
|
|
|
pub async fn connect(twitch: &Twitch) -> Result<IrcClient> {
|
|
let token = twitch.bot_token().await?;
|
|
let irc_config = IrcConfig {
|
|
server: Some("irc.chat.twitch.tv".into()),
|
|
port: Some(6697),
|
|
username: Some(token.login.clone()),
|
|
nickname: Some(token.login.clone()),
|
|
password: Some(format!("oauth:{}", token.access_token.secret())),
|
|
..Default::default()
|
|
};
|
|
let irc = IrcClient::from_config(irc_config).await?;
|
|
irc.send_cap_req(&[
|
|
Capability::Custom("twitch.tv/tags"),
|
|
Capability::Custom("twitch.tv/commands"),
|
|
])?;
|
|
irc.identify()?;
|
|
Ok(irc)
|
|
}
|