Compare commits

..

No commits in common. "3664d06d170f264ea1aba908567800a19f7c0a31" and "9b533e7ea37741808e63500e6f7b3273cfcb8e5a" have entirely different histories.

6 changed files with 10 additions and 28 deletions

View file

@ -21,7 +21,7 @@ You can let [cargo](https://doc.rust-lang.org/cargo/) build the binary for you,
> [!TIP]
> This will install the binary in `~/.cargo/bin/forgejo-guardian`. Make sure to add this directory to your `PATH`.
> If you want to update it, rerun the command.
> If you want to update it, run `cargo install ...` again.
```sh
cargo install --git https://git.4rs.nl/awiteb/forgejo-guardian
@ -55,18 +55,17 @@ We use `TOML` format for configuration, the default configuration file is `/app/
### Structure
In our configuration file you can have the following sections and the global section:
In our configuration file you can have the following sections and the global sections:
- `forgejo`: Forgejo instance configuration
- `expressions`: Regular expressions to match against
- `telegram`: Telegram bot configuration
#### Global section
#### Global sections
The global section is the one that doesn't have a name, and it's in the top of the configuration file, with the following fields:
- `dry_run`: If set to `true`, the guardian will not ban the users, but will only alert the admins (default: `false`)
- `only_new_users`: If set to `true`, the guardian will only check the new users, and not the existing ones (default: `false`)
#### `forgejo`

View file

@ -144,9 +144,6 @@ pub struct Config {
/// Dry run, without banning the users
#[serde(default)]
pub dry_run: bool,
/// Only checks new users
#[serde(default)]
pub only_new_users: bool,
/// Configuration for the forgejo guard itself
pub forgejo: Forgejo,
/// Configuration of the telegram bot

View file

@ -14,8 +14,6 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://gnu.org/licenses/agpl.txt>.
use reqwest::StatusCode;
use crate::config::{CONFIG_PATH_ENV, DEFAULT_CONFIG_PATH};
/// Result of the guard
@ -41,7 +39,4 @@ pub enum GuardError {
/// Faild to deserialize the config file
#[error("Failed to deserialize the config: {0}")]
FaildDeserializeConfig(#[from] toml::de::Error),
/// Failed to ban the user
#[error("Failed to ban the user, status code: {0}")]
FailedToBan(StatusCode),
}

View file

@ -16,7 +16,7 @@
use reqwest::Method;
use crate::error::{GuardError, GuardResult};
use crate::error::GuardResult;
/// Ban a user from the instance, purging their data.
pub async fn ban_user(
@ -34,10 +34,7 @@ pub async fn ban_user(
))
.await?;
tracing::debug!("Ban user response: {:?}", &res);
if !res.status().is_success() {
return Err(GuardError::FailedToBan(res.status()));
}
tracing::debug!("Body: {}", res.text().await.unwrap_or_default());
Ok(())
}

View file

@ -44,7 +44,6 @@ async fn try_main() -> error::GuardResult<()> {
tracing::info!("The instance: {}", config.forgejo.instance);
tracing::info!("Dry run: {}", config.dry_run);
tracing::info!("Only new users: {}", config.only_new_users);
tracing::debug!("The config exprs: {:#?}", config.expressions);
rust_i18n::set_locale(config.telegram.lang.as_str());

View file

@ -98,7 +98,6 @@ async fn check_new_users(
sus_sender: Sender<ForgejoUser>,
ban_sender: Sender<ForgejoUser>,
) {
let is_first_fetch = last_user_id.load(Ordering::Relaxed) == 0;
match get_new_users(
&request_client,
last_user_id.load(Ordering::Relaxed),
@ -113,11 +112,7 @@ async fn check_new_users(
if let Some(uid) = new_users.iter().max_by_key(|u| u.id).map(|u| u.id) {
tracing::debug!("New last user id: {uid}");
last_user_id.store(uid, Ordering::Relaxed);
}
if config.only_new_users && is_first_fetch {
return;
last_user_id.store(uid, Ordering::Relaxed)
}
for user in new_users {