Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement INFO command #128

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 84 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions sable_ircd/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Sable --

Copyright (c) 2021-2024 Sable Development Team
internet-catte marked this conversation as resolved.
Show resolved Hide resolved

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Source code is available at: https://github.com/Libera-Chat/sable

A list of contributors can be found in the git log.

Visit the Sable website at: https://sable.chat/
Visit us on IRC at irc.libera.chat #libera-dev

19 changes: 19 additions & 0 deletions sable_ircd/src/command/handlers/info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use super::*;

#[command_handler("INFO")]
/// Syntax: INFO
fn info_handler(response: &dyn CommandResponse, server: &ClientServer) -> CommandResult {
let node = server.node();
let version = node.version();
let commit_date = node.commit_date();

for line in &server.info_strings.info {
response.numeric(make_numeric!(Info, line));
}
response.numeric(make_numeric!(Info, &format!("Version: {version}")));
response.numeric(make_numeric!(Info, &format!("Commit date: {commit_date}")));
// TODO: send configuration info to opers
// see: https://github.com/solanum-ircd/solanum/blob/main/modules/m_info.c#L788
response.numeric(make_numeric!(EndOfInfo));
Ok(())
}
1 change: 1 addition & 0 deletions sable_ircd/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
mod ban;
mod cap;
mod chathistory;
mod info;
mod invite;
mod join;
mod kick;
Expand Down Expand Up @@ -76,8 +77,8 @@
mod services;

// Dev/test tools
#[cfg(debug)]

Check warning on line 80 in sable_ircd/src/command/mod.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

unexpected `cfg` condition name: `debug`

Check warning on line 80 in sable_ircd/src/command/mod.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

unexpected `cfg` condition name: `debug`
mod async_wait;
#[cfg(debug)]

Check warning on line 82 in sable_ircd/src/command/mod.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

unexpected `cfg` condition name: `debug`

Check warning on line 82 in sable_ircd/src/command/mod.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

unexpected `cfg` condition name: `debug`
mod sping;
}
3 changes: 3 additions & 0 deletions sable_ircd/src/messages/numeric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ define_messages! {

381(YoureOper) => { () => "You are now an IRC operator" },

371(Info) => { (line: &str) => ":{line}" },
374(EndOfInfo) => { () => ":End of /INFO list" },


401(NoSuchTarget) => { (unknown: &str) => "{unknown} :No such nick/channel" },
402(NoSuchServer) => { (server_name: &ServerName) => "{server_name} :No such server" },
Expand Down
5 changes: 5 additions & 0 deletions sable_ircd/src/server/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct RawClientServerConfig {
pub struct ServerInfoStrings {
pub motd: Option<Vec<String>>, // Linewise to not repeatedly split
pub admin_info: Option<AdminInfo>,
pub info: Vec<String>,
}

impl ServerInfoStrings {
Expand All @@ -38,6 +39,10 @@ impl ServerInfoStrings {
motd: Self::get_info(&raw_info.motd, "motd")?
.map(|file| file.lines().map(|v| v.to_string()).collect()),
admin_info: raw_info.admin.clone(),
info: include_str!("../../info.txt")
.lines()
.map(|v| v.to_string())
.collect(),
})
}

Expand Down
4 changes: 2 additions & 2 deletions sable_ircd/src/utils/time_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn format_timestamp(ts: i64) -> String {
}

pub fn parse_timestamp(str: &str) -> Option<i64> {
Utc.datetime_from_str(str, "%+")
.map(|dt| dt.timestamp())
NaiveDateTime::parse_from_str(str, "%+")
.map(|dt| dt.and_utc().timestamp())
.ok()
}
2 changes: 2 additions & 0 deletions sable_network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ debug = []

[build-dependencies]
built = { version = "0.5", features = [ "git2" ] }
git2 = { version = "0.15", default-features = false }
chrono = "0.4"

[dev-dependencies]
tracing-subscriber = "0.3"
Expand Down
Loading
Loading