From 4d4ad94bcce25d1f4d0ce105f630689b6577da59 Mon Sep 17 00:00:00 2001 From: PawzyTheJawzy Date: Sat, 18 Jan 2025 10:10:18 +0000 Subject: [PATCH 1/2] Refactor time variable and exclude system users (#1) --- main.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index d6cdc9b..8fe4737 100644 --- a/main.js +++ b/main.js @@ -8,6 +8,8 @@ if (!USER_TOKEN) { process.exit(1); } +const PERIOD = process.env.PERIOD; // Time in days: int + const INSTANCE_URL = process.env.INSTANCE_URL; const API_BASE = `${INSTANCE_URL}/api`; @@ -49,14 +51,16 @@ async function main() { const users = response.data; const now = new Date(); - const fiveDaysAgo = new Date(now - 5 * 24 * 60 * 60 * 1000); + const timeAgo = new Date(now - PERIOD * 24 * 60 * 60 * 1000); const usersToDelete = users.filter(user => { const createdAt = new Date(user.createdAt); const updatedAt = new Date(user.updatedAt); - return user.notesCount === 0 && - createdAt < fiveDaysAgo && - updatedAt < fiveDaysAgo; + const excludedUsers = ['instance.actor', 'relay.actor']; + return user.notesCount === 0 && + createdAt < timeAgo && + updatedAt < timeAgo && + !excludedUsers.includes(user.username) }); console.log(`Found ${usersToDelete.length} users matching criteria (no posts, not updated, and older than 5 days)`); @@ -71,7 +75,7 @@ async function main() { console.log(); const confirmed = await askForConfirmation(`Are you sure you want to delete ${usersToDelete.length} users?`); - + if (!confirmed) { console.log('Operation cancelled by user'); rl.close(); -- 2.45.2 From 1c022477140ca20b22bd701a17d199d5cbe726f8 Mon Sep 17 00:00:00 2001 From: fivesevenblue Date: Sat, 18 Jan 2025 14:49:00 +0000 Subject: [PATCH 2/2] Fix hardcoded string --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index 8fe4737..a6163de 100644 --- a/main.js +++ b/main.js @@ -63,7 +63,7 @@ async function main() { !excludedUsers.includes(user.username) }); - console.log(`Found ${usersToDelete.length} users matching criteria (no posts, not updated, and older than 5 days)`); + console.log(`Found ${usersToDelete.length} users matching criteria (no posts, not updated, and older than ${PERIOD} days)`); console.log('\nUsers to be deleted:'); usersToDelete.forEach(user => { -- 2.45.2