forked from Leafus/misskey-gooner-remover
init
This commit is contained in:
commit
7ed162fb91
2 changed files with 102 additions and 0 deletions
95
main.js
Normal file
95
main.js
Normal file
|
@ -0,0 +1,95 @@
|
|||
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);
|
||||
}
|
||||
|
||||
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();
|
7
package.json
Normal file
7
package.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"axios": "^1.7.8",
|
||||
"dotenv": "^16.4.5",
|
||||
"readline": "^1.3.0"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue