From 4dd30a4d394cb9ff1b293449092ac92a6280f8e0 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Wed, 26 Oct 2022 17:58:44 -0700 Subject: [PATCH] improve irc ux --- src/app.rs | 4 +++- src/irc.rs | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index 351cd16..a667065 100644 --- a/src/app.rs +++ b/src/app.rs @@ -7,7 +7,6 @@ use crate::player::Player; use crate::tor::GuiTor; use crate::stats::Market; use crate::irc::Client as IRCClient; -use crate::irc::send_cmd; use libtor::Error as libtorError; pub struct App { @@ -150,6 +149,9 @@ impl eframe::App for App { self.player.exif_date = SystemTime::now(); self.player.stream_exif = self.player.get_song_meta().unwrap(); } + if ui.button("!tune - i love this song!").clicked() { + let _ = self.irc.send_tune(); + } } ui.separator(); diff --git a/src/irc.rs b/src/irc.rs index 29e977a..50729a9 100644 --- a/src/irc.rs +++ b/src/irc.rs @@ -92,6 +92,9 @@ fn receive(mut stream: &TcpStream) -> std::io::Result<()> { match res_string { Ok(r) => { if !res_string.unwrap().is_empty() { + if std::fs::File::open("irc.log").is_err() { + let _ = std::fs::write("irc.log", ""); + } let mut f = OpenOptions::new() .append(true) .open("irc.log") @@ -199,6 +202,14 @@ impl Client { return s; } + pub fn send_tune(&self) -> std::io::Result<()> { + let mut stream = connect(self.nick.to_owned())?; + thread::spawn(move || { + let _ = stream.write(b"PRIVMSG #wownero-music !tune\r\n"); + }); + Ok(()) + } + /// Creates a send and recv TcpStream (with the same socket) /// spins recv to its own thread /// main thread takes user input and matches it to commands