Broadcast, and FIFO are currently functional.
This commit is contained in:
20
src/event.rs
20
src/event.rs
@@ -1,14 +1,32 @@
|
||||
use irc::proto::{Command, Message};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Event {
|
||||
from: String,
|
||||
message: String,
|
||||
}
|
||||
|
||||
impl Event {
|
||||
pub fn new(msg: impl Into<String>) -> Self {
|
||||
pub fn new(from: impl Into<String>, msg: impl Into<String>) -> Self {
|
||||
Self {
|
||||
from: from.into(),
|
||||
message: msg.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&Message> for Event {
|
||||
type Error = &'static str;
|
||||
|
||||
fn try_from(value: &Message) -> Result<Self, Self::Error> {
|
||||
let from = value.response_target().unwrap_or("unknown").to_string();
|
||||
match &value.command {
|
||||
Command::PRIVMSG(_channel, message) => Ok(Event {
|
||||
from,
|
||||
message: message.clone(),
|
||||
}),
|
||||
_ => Err("Not a PRIVMSG"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user