modules: port antirandom, restrictcommands, restrictmsg, blockamsg, connectban
This commit is contained in:
parent
131471e245
commit
a48b48e46f
7 changed files with 766 additions and 0 deletions
59
src/modules/restrictmsg.rs
Normal file
59
src/modules/restrictmsg.rs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
//! restrictmsg — stop ordinary users from private-messaging each other. A PM
|
||||
//! between two users is allowed only when the sender is an oper, the target is an
|
||||
//! oper, or the target is a service/bot (so users can still reach NickServ etc.).
|
||||
//! Channel messages are never affected. Off unless `restrictmsg = yes` — read
|
||||
//! straight from the config, nothing on `Server`.
|
||||
//!
|
||||
//! Behaviour reference: InspIRCd's `m_restrictmsg`. Original native Rust.
|
||||
|
||||
use crate::module::{ModResult, Module};
|
||||
use crate::numeric::ERR_CANTSENDTOUSER;
|
||||
use crate::server::Server;
|
||||
use crate::Uid;
|
||||
|
||||
pub struct RestrictMsg;
|
||||
|
||||
impl Module for RestrictMsg {
|
||||
fn name(&self) -> &'static str {
|
||||
"restrictmsg"
|
||||
}
|
||||
|
||||
fn on_pre_message(
|
||||
&mut self,
|
||||
srv: &mut Server,
|
||||
uid: Uid,
|
||||
target: &str,
|
||||
_text: &str,
|
||||
) -> ModResult {
|
||||
if !srv.conf_bool("restrictmsg", false) {
|
||||
return ModResult::Passthru;
|
||||
}
|
||||
// channels are unaffected
|
||||
if target.starts_with('#') {
|
||||
return ModResult::Passthru;
|
||||
}
|
||||
// sender opers may message anyone
|
||||
if srv.is_oper(uid) {
|
||||
return ModResult::Passthru;
|
||||
}
|
||||
let Some(tuid) = srv.find_nick(target) else {
|
||||
return ModResult::Passthru; // let the core answer "no such nick"
|
||||
};
|
||||
// allow messaging opers and services/bots
|
||||
let target_privileged = srv
|
||||
.users
|
||||
.get(&tuid)
|
||||
.map(|u| u.flags.oper || u.flags.bot)
|
||||
.unwrap_or(false);
|
||||
if target_privileged {
|
||||
return ModResult::Passthru;
|
||||
}
|
||||
|
||||
srv.numeric(
|
||||
uid,
|
||||
ERR_CANTSENDTOUSER,
|
||||
&format!("{target} :You cannot send messages to this user."),
|
||||
);
|
||||
ModResult::Deny
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue