diff options
| author | 2026-03-09 13:47:23 -0400 | |
|---|---|---|
| committer | 2026-03-09 13:47:23 -0400 | |
| commit | 5b0e9b8a50c337796963c04aabbe23ae4d4bf922 (patch) | |
| tree | 9e1c88b0394b4ff728e1eea469c11045e62a89d1 /src/connection/mod.rs | |
| parent | off by one fix for some word wrapping (diff) | |
initial move to async instead of polling
Diffstat (limited to 'src/connection/mod.rs')
| -rw-r--r-- | src/connection/mod.rs | 30 |
1 files changed, 29 insertions, 1 deletions
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: |
