sermo/src/client/commands/privmsg.rs
user0-07161 d3c3cd8292
All checks were successful
build / test-alpine (push) Successful in 51s
build / test-debian (push) Successful in 1m23s
chore: move client-related code into its own directory
2026-02-15 17:47:10 +01:00

40 lines
1 KiB
Rust

use async_trait::async_trait;
use super::{ClientAction, ClientHandler};
use crate::{
messages::{Message, PrivMessage, Receiver},
user::User,
};
pub struct PrivMsg;
#[async_trait]
impl ClientHandler for PrivMsg {
async fn handle(
&self,
command: Vec<String>,
authenticated: bool,
user_state: &mut User,
_server_outgoing_password: String,
_server_incoming_passwords: Vec<String>,
_user_passwords: Vec<String>,
) -> Vec<ClientAction> {
if !authenticated {
return vec![ClientAction::ErrorAuthenticateFirst];
}
let receiver = if command[0].clone().starts_with("#") {
Receiver::ChannelName(command[0].clone())
} else {
Receiver::Username(command[0].clone())
};
let message = PrivMessage {
sender: user_state.clone().unwrap_all(),
receiver,
text: command[1].clone(),
};
vec![ClientAction::SendMessage(Message::PrivMessage(message))]
}
}