mirror of
https://github.com/kurbezz/discord-bot.git
synced 2025-12-06 15:15:37 +01:00
Fix
This commit is contained in:
@@ -1,79 +0,0 @@
|
||||
use anyhow::bail;
|
||||
use anyhow::Result;
|
||||
|
||||
use irc::client::data::Config as IrcConfig;
|
||||
use irc::client::prelude::Capability as IrcCap;
|
||||
use irc::client::Client as IrcClient;
|
||||
use irc::client::ClientStream as IrcStream;
|
||||
|
||||
use super::auth;
|
||||
use super::helix;
|
||||
|
||||
|
||||
impl<T: auth::TokenStorage> helix::Client<T> {
|
||||
pub async fn connect_chat(&mut self, channels: Vec<String>) -> Result<(IrcClient, IrcStream)> {
|
||||
match self.validate_token().await {
|
||||
Err(e) => {
|
||||
println!("{e:?}");
|
||||
bail!("Invalid refresh token or no internet");
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
||||
let channels = channels
|
||||
.into_iter()
|
||||
.map(|c| {
|
||||
format!(
|
||||
"{0}{1}",
|
||||
if c.starts_with("#") { "" } else { "#" },
|
||||
c.to_lowercase()
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let config = IrcConfig {
|
||||
server: Some("irc.chat.twitch.tv".to_owned()),
|
||||
port: Some(6697),
|
||||
use_tls: Some(true),
|
||||
nickname: Some(self.get_token_user_login().await?.to_lowercase().to_owned()),
|
||||
password: Some(format!("oauth:{0}", self.token.access_token)),
|
||||
channels: channels,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let mut client = match IrcClient::from_config(config).await {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
println!("{e:?}");
|
||||
bail!("IrcClient::from_config failed");
|
||||
}
|
||||
};
|
||||
match client.send_cap_req(&[
|
||||
IrcCap::Custom("twitch.tv/tags"),
|
||||
IrcCap::Custom("twitch.tv/commands"),
|
||||
]) {
|
||||
Err(e) => {
|
||||
println!("{e:?}");
|
||||
bail!("IrcClient.send_cap_req failed");
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
match client.identify() {
|
||||
Err(e) => {
|
||||
println!("{e:?}");
|
||||
bail!("IrcClient.identify failed");
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
||||
let stream = match client.stream() {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
println!("{e:?}");
|
||||
bail!("IrcClient.stream failed");
|
||||
}
|
||||
};
|
||||
|
||||
Ok((client, stream))
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
pub mod eventsub;
|
||||
pub mod helix;
|
||||
pub mod auth;
|
||||
pub mod chat;
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use futures::StreamExt;
|
||||
@@ -64,25 +63,7 @@ pub async fn notify_stream_online(title: String, game: String) {
|
||||
|
||||
|
||||
impl TwitchBot {
|
||||
pub async fn start() {
|
||||
println!("Starting Twitch bot...");
|
||||
|
||||
let token_storage = TokenStorage {
|
||||
filepath: "/secrets/twitch_token.json".to_string()
|
||||
};
|
||||
let token = token_storage.load().await.unwrap();
|
||||
|
||||
let mut client = match helix::Client::from_token(
|
||||
config::CONFIG.twitch_client_id.clone(),
|
||||
config::CONFIG.twitch_client_secret.clone(),
|
||||
token_storage,
|
||||
token
|
||||
).await {
|
||||
Ok(v) => v,
|
||||
Err(err) => panic!("{:?}", err),
|
||||
};
|
||||
|
||||
|
||||
pub async fn start_watch(mut client: helix::Client<TokenStorage>) {
|
||||
let mut current_state: Option<State> = {
|
||||
let stream = client.get_stream(config::CONFIG.twitch_channel_id.clone()).await;
|
||||
|
||||
@@ -100,9 +81,6 @@ impl TwitchBot {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
client.validate_token().await.unwrap();
|
||||
|
||||
loop {
|
||||
println!("Checking Twitch events...");
|
||||
let mut eventsub_client = client.connect_eventsub(
|
||||
@@ -167,18 +145,28 @@ impl TwitchBot {
|
||||
}
|
||||
}
|
||||
|
||||
// if let Some(event) = chat_stream.next().await {
|
||||
// match event {
|
||||
// Ok(v) => {
|
||||
// println!("{:?}", v);
|
||||
// },
|
||||
// Err(err) => {
|
||||
// eprintln!("{:?}", err);
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
|
||||
client.validate_token().await.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn start() {
|
||||
println!("Starting Twitch bot...");
|
||||
|
||||
let token_storage = TokenStorage {
|
||||
filepath: "/secrets/twitch_token.json".to_string()
|
||||
};
|
||||
let token = token_storage.load().await.unwrap();
|
||||
|
||||
let mut client = match helix::Client::from_token(
|
||||
config::CONFIG.twitch_client_id.clone(),
|
||||
config::CONFIG.twitch_client_secret.clone(),
|
||||
token_storage,
|
||||
token
|
||||
).await {
|
||||
Ok(v) => v,
|
||||
Err(err) => panic!("{:?}", err),
|
||||
};
|
||||
|
||||
client.validate_token().await.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user