use std::sync::Arc;
use soup_sdk::{
SoopHttpClient,
chat::{Event, SoopChatConnection, SoopChatOptions, commands::MessageType},
};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let soop_client = Arc::new(SoopHttpClient::new());
let data = soop_client.get_live_detail_state("danchu17").await?;
println!("{:?}", data);
let options = SoopChatOptions {
streamer_id: "inehine".to_string(),
password: "".to_string(),
};
println!("[System] Chat connection object created and initialized.");
let chat_connection = SoopChatConnection::new(Arc::clone(&soop_client), options)?;
let mut event_receiver = chat_connection.subscribe();
println!("[System] Subscribed to event channel.");
if let Err(e) = chat_connection.start().await {
eprintln!("[Error] Failed to start a connection loop: {}", e);
return Ok(());
}
println!("[System] Connection loop started. Waiting for events...");
loop {
match event_receiver.recv().await {
Ok(event) => handle_event(event),
Err(_) => {
break;
}
}
}
Ok(())
}
fn handle_event(event: Event) {
match event {
Event::Chat(e) => {
println!("채팅 {:<10} {}", e.user.id, e.comment)
}
Event::Join(v) => {
}
Event::Disconnected => {
println!("정상 종료됨");
}
Event::Donation(d) => {
println!("별풍선 {} {}", d.from_label, d.amount)
}
Event::Freeze(e) => {
println!("얼리기 {:?}", e)
}
Event::Mute(e) => {
println!("채팅 금지 {:?}", e);
}
Event::Slow(e) => {
println!("슬로우 {:?}", e)
}
Event::Notification(e) => {
println!("공지 {:?}", e)
}
Event::KickCancel(e) => {
println!("취소 {:?}", e)
}
Event::MissionDonation(e) => {
println!(
"미션풍({:?}) {} {}개",
e.mission_type, e.from_label, e.amount
)
}
Event::MissionTotal(e) => {
println!("미션전체 {:?}", e)
}
Event::BattleMissionResult(e) => {
println!("배틀결과 {:?}", e)
}
Event::ChallengeMissionResult(e) => {
println!("도전결과 {:?}", e)
}
Event::Subscribe(e) => {
println!("구독 {:?}", e)
}
_ => {
}
}
}