use crate::{messages::Privmsg, Encodable};
use std::io::Write;
pub trait PrivmsgExt {
fn reply(&mut self, msg: &Privmsg<'_>, data: &str) -> std::io::Result<()>;
fn say(&mut self, msg: &Privmsg<'_>, data: &str) -> std::io::Result<()>;
}
impl<'a, W: Write + ?Sized> PrivmsgExt for W {
fn reply(&mut self, msg: &Privmsg<'_>, data: &str) -> std::io::Result<()> {
let cmd = crate::commands::reply(
msg.channel(),
msg.tags().get("id").ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::PermissionDenied,
"you must have `TAGS` enabled",
)
})?,
data,
);
cmd.encode(self)?;
self.flush()
}
fn say(&mut self, msg: &Privmsg<'_>, data: &str) -> std::io::Result<()> {
let cmd = crate::commands::privmsg(msg.channel(), data);
cmd.encode(self)?;
self.flush()
}
}