rpc: add server/stats/ban/message/whowas/spamfilter providers; fix REHASH to reload raw_config
This commit is contained in:
parent
ee445396eb
commit
89f508aca9
10 changed files with 408 additions and 11 deletions
35
src/modules/rpc/whowas.rs
Normal file
35
src/modules/rpc/whowas.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
//! rpc whowas provider — `whowas.get`. InspIRCd's `m_rpc_whowas`. Returns the
|
||||
//! recent-nick-history entries the ircd keeps for `WHOWAS`.
|
||||
|
||||
use super::json::{self, obj, qstr};
|
||||
use super::RpcError;
|
||||
use crate::server::Server;
|
||||
|
||||
pub fn handle(s: &mut Server, action: &str, params: &str) -> Result<String, RpcError> {
|
||||
match action {
|
||||
"get" => {
|
||||
let nick = json::get_str(params, "nick")
|
||||
.ok_or_else(|| RpcError::invalid_params("missing 'nick'"))?;
|
||||
let entries: Vec<String> = s
|
||||
.whowas
|
||||
.iter()
|
||||
.filter(|e| e.nick.eq_ignore_ascii_case(&nick))
|
||||
.map(|e| {
|
||||
let mut fields = vec![
|
||||
("nick", qstr(&e.nick)),
|
||||
("ident", qstr(&e.ident)),
|
||||
("host", qstr(&e.host)),
|
||||
("realname", qstr(&e.realname)),
|
||||
("signon", e.ts.to_string()),
|
||||
];
|
||||
if let Some(acct) = &e.account {
|
||||
fields.push(("account", qstr(acct)));
|
||||
}
|
||||
obj(&fields)
|
||||
})
|
||||
.collect();
|
||||
Ok(obj(&[("entries", format!("[{}]", entries.join(",")))]))
|
||||
}
|
||||
other => Err(RpcError::method_not_found(&format!("whowas.{other}"))),
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue