From 5b0e9b8a50c337796963c04aabbe23ae4d4bf922 Mon Sep 17 00:00:00 2001 From: lancebord Date: Mon, 9 Mar 2026 13:47:23 -0400 Subject: initial move to async instead of polling --- src/connection/mod.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/connection/mod.rs') diff --git a/src/connection/mod.rs b/src/connection/mod.rs index bc837c0..10e8ec9 100644 --- a/src/connection/mod.rs +++ b/src/connection/mod.rs @@ -5,7 +5,7 @@ use tokio_util::codec::Framed; use tracing::{debug, error, info}; use crate::proto::codec::IrcCodec; -use crate::proto::message::IrcMessage; +use crate::proto::message::{Command, IrcMessage}; /// A handle to send messages to the server. /// Cheaply cloneable — pass it wherever you need to write. @@ -15,10 +15,38 @@ pub struct Sender { } impl Sender { + /// Send a raw `IrcMessage` to the server. pub fn send(&self, msg: IrcMessage) { // Only fails if the connection task has shut down let _ = self.tx.send(msg); } + + /// Send a PRIVMSG to a channel or user. + pub fn privmsg(&self, target: &str, text: &str) { + self.send(IrcMessage::new( + Command::Privmsg, + vec![target.to_string(), text.to_string()], + )); + } + + /// Join a channel. + pub fn join(&self, channel: &str) { + self.send(IrcMessage::new(Command::Join, vec![channel.to_string()])); + } + + /// Part a channel. + pub fn part(&self, channel: &str, reason: Option<&str>) { + let mut params = vec![channel.to_string()]; + if let Some(r) = reason { + params.push(r.to_string()); + } + self.send(IrcMessage::new(Command::Part, params)); + } + + /// Change nick. + pub fn nick(&self, new_nick: &str) { + self.send(IrcMessage::new(Command::Nick, vec![new_nick.to_string()])); + } } /// Establish a TCP connection and return: -- cgit v1.2.3-59-g8ed1b