mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
bin/ircd: implement a function for Privmsg to build irc msg
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user