From f68ce0c5bd86e1a637736219f0e952831fe8cc7b Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Sat, 16 Nov 2024 14:47:00 +0300
Subject: [PATCH] feat: Checks only new users configuration
Signed-off-by: Awiteb
---
src/config.rs | 11 +++++++----
src/main.rs | 1 +
src/users_fetcher.rs | 7 ++++++-
3 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/src/config.rs b/src/config.rs
index 3045ba3..1d8baae 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -143,12 +143,15 @@ pub struct Exprs {
pub struct Config {
/// Dry run, without banning the users
#[serde(default)]
- pub dry_run: bool,
+ pub dry_run: bool,
+ /// Only checks new users
+ #[serde(default)]
+ pub only_new_users: bool,
/// Configuration for the forgejo guard itself
- pub forgejo: Forgejo,
+ pub forgejo: Forgejo,
/// Configuration of the telegram bot
- pub telegram: Telegram,
+ pub telegram: Telegram,
/// The expressions, which are used to determine the actions
#[serde(default)]
- pub expressions: Exprs,
+ pub expressions: Exprs,
}
diff --git a/src/main.rs b/src/main.rs
index b72e9c8..adc4a94 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -44,6 +44,7 @@ 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());
diff --git a/src/users_fetcher.rs b/src/users_fetcher.rs
index f116aab..d61538b 100644
--- a/src/users_fetcher.rs
+++ b/src/users_fetcher.rs
@@ -98,6 +98,7 @@ async fn check_new_users(
sus_sender: Sender,
ban_sender: Sender,
) {
+ let is_first_fetch = last_user_id.load(Ordering::Relaxed) == 0;
match get_new_users(
&request_client,
last_user_id.load(Ordering::Relaxed),
@@ -112,7 +113,11 @@ 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)
+ last_user_id.store(uid, Ordering::Relaxed);
+ }
+
+ if config.only_new_users && is_first_fetch {
+ return;
}
for user in new_users {