bin/ircd: implement a function for Privmsg to build irc msg

This commit is contained in:
ghassmo
2022-06-17 04:23:21 +03:00
parent 79e83a286e
commit 62e84c017a
2 changed files with 12 additions and 9 deletions

View File

@@ -43,13 +43,6 @@ use crate::{
const SIZE_OF_MSGS_BUFFER: usize = 4096;
fn build_irc_msg(msg: &Privmsg) -> String {
debug!("ABOUT TO SEND: {:?}", msg);
let irc_msg =
format!(":{}!anon@dark.fi PRIVMSG {} :{}\r\n", msg.nickname, msg.channel, msg.message);
irc_msg
}
fn clean_input(mut line: String, peer_addr: &SocketAddr) -> Result<String> {
if line.is_empty() {
warn!("Received empty line from {}. ", peer_addr);
@@ -61,6 +54,7 @@ fn clean_input(mut line: String, peer_addr: &SocketAddr) -> Result<String> {
warn!("Closing connection.");
return Err(Error::ChannelStopped)
}
// Remove CRLF
line.pop();
line.pop();
@@ -142,8 +136,7 @@ impl Ircd {
(*privmsgs_buffer.lock().await).push(msg.clone());
}
let irc_msg = build_irc_msg(&msg);
conn.reply(&irc_msg).await?;
conn.reply(&msg.to_irc_msg()).await?;
}
err = reader.read_line(&mut line).fuse() => {
if let Err(e) = err {

View File

@@ -17,3 +17,13 @@ pub struct Privmsg {
pub channel: String,
pub message: String,
}
impl Privmsg {
pub fn to_irc_msg(&self) -> String {
let irc_msg = format!(
":{}!anon@dark.fi PRIVMSG {} :{}\r\n",
self.nickname, self.channel, self.message
);
irc_msg
}
}