misskey-gooner-creator/main.js

97 lines
2.9 KiB
JavaScript
Raw Normal View History

2024-12-15 18:12:27 +01:00
require('dotenv').config();
const axios = require('axios');
const readline = require('readline');
const USER_TOKEN = process.env.USER_TOKEN;
if (!USER_TOKEN) {
console.error('USER_TOKEN not found in .env file');
process.exit(1);
}
2025-01-05 16:30:29 +01:00
console.log("Spierdalaj");
2024-12-15 18:12:27 +01:00
const INSTANCE_URL = process.env.INSTANCE_URL;
const API_BASE = `${INSTANCE_URL}/api`;
async function deleteUser(userId) {
try {
await axios.post(`${API_BASE}/admin/accounts/delete`, {
i: USER_TOKEN,
userId: userId,
soft: false
});
console.log(`Successfully deleted user: ${userId}`);
} catch (error) {
console.error(`Failed to delete user ${userId}:`, error.response?.data || error.message);
}
}
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function askForConfirmation(message) {
return new Promise((resolve) => {
rl.question(message + ' (yes/no): ', (answer) => {
resolve(answer.toLowerCase() === 'yes');
});
});
}
async function main() {
try {
const response = await axios.post(`${API_BASE}/admin/show-users`, {
limit: 100,
i: USER_TOKEN,
origin: 'local',
state: 'all',
sort: '-createdAt',
});
const users = response.data;
const now = new Date();
const fiveDaysAgo = new Date(now - 5 * 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;
});
console.log(`Found ${usersToDelete.length} users matching criteria (no posts, not updated, and older than 5 days)`);
console.log('\nUsers to be deleted:');
usersToDelete.forEach(user => {
console.log(`- @${user.username}
Created: ${new Date(user.createdAt).toLocaleDateString()},
Last Updated: ${new Date(user.updatedAt).toLocaleDateString()},
Notes: ${user.notesCount}`);
});
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();
return;
}
for (const user of usersToDelete) {
console.log(`Processing user: ${user.username} (created: ${user.createdAt}, notes: ${user.notesCount})`);
await deleteUser(user.id);
await new Promise(resolve => setTimeout(resolve, 1000));
}
console.log('Finished processing users');
rl.close();
} catch (error) {
console.error('Error:', error.response?.data || error.message);
rl.close();
}
}
main();