feat: Checks only new users configuration

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb 2024-11-16 14:47:00 +03:00
parent 9b533e7ea3
commit f68ce0c5bd
Signed by: awiteb
GPG key ID: 3F6B55640AA6682F
3 changed files with 14 additions and 5 deletions

View file

@ -144,6 +144,9 @@ 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

@ -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());

View file

@ -98,6 +98,7 @@ 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),
@ -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 {