forked from Leafus/misskey-gooner-remover
Compare commits
5 commits
Author | SHA1 | Date | |
---|---|---|---|
f9a8d22a5f | |||
7c08cf12d4 | |||
1c02247714 | |||
f89c825357 | |||
4d4ad94bcc |
2 changed files with 31 additions and 12 deletions
27
README.md
27
README.md
|
@ -1,13 +1,28 @@
|
||||||
# misskey gooner remover 3000
|
# misskey gooner remover 3000
|
||||||
|
|
||||||
simple nodejs script to remove inactive accounts on sharkey / misskey fediverse instances
|
Simple nodejs script to remove inactive accounts on sharkey / misskey fediverse instances
|
||||||
|
|
||||||
## installation
|
## Installation
|
||||||
|
|
||||||
```
|
1. Install bun and run:
|
||||||
bun install
|
|
||||||
node main.js
|
|
||||||
|
|
||||||
```
|
```text
|
||||||
|
bun install
|
||||||
|
node main.js
|
||||||
|
```
|
||||||
|
|
||||||
|
## Create env file
|
||||||
|
|
||||||
|
1. Create an API key with the permissions
|
||||||
|
- Delete user account
|
||||||
|
- View private user info
|
||||||
|
|
||||||
|
2. Create a `.env` file in the current directory with:
|
||||||
|
|
||||||
|
```env
|
||||||
|
USER_TOKEN=token
|
||||||
|
INSTANCE_URL=https://example.com
|
||||||
|
PERIOD=int // Time in days
|
||||||
|
```
|
||||||
|
|
||||||
License: MIT
|
License: MIT
|
||||||
|
|
16
main.js
16
main.js
|
@ -8,6 +8,8 @@ if (!USER_TOKEN) {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PERIOD = process.env.PERIOD; // Time in days: int
|
||||||
|
|
||||||
const INSTANCE_URL = process.env.INSTANCE_URL;
|
const INSTANCE_URL = process.env.INSTANCE_URL;
|
||||||
const API_BASE = `${INSTANCE_URL}/api`;
|
const API_BASE = `${INSTANCE_URL}/api`;
|
||||||
|
|
||||||
|
@ -49,17 +51,19 @@ async function main() {
|
||||||
|
|
||||||
const users = response.data;
|
const users = response.data;
|
||||||
const now = new Date();
|
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 usersToDelete = users.filter(user => {
|
||||||
const createdAt = new Date(user.createdAt);
|
const createdAt = new Date(user.createdAt);
|
||||||
const updatedAt = new Date(user.updatedAt);
|
const updatedAt = new Date(user.updatedAt);
|
||||||
return user.notesCount === 0 &&
|
const excludedUsers = ['instance.actor', 'relay.actor'];
|
||||||
createdAt < fiveDaysAgo &&
|
return user.notesCount === 0 &&
|
||||||
updatedAt < fiveDaysAgo;
|
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)`);
|
console.log(`Found ${usersToDelete.length} users matching criteria (no posts, not updated, and older than ${PERIOD} days)`);
|
||||||
|
|
||||||
console.log('\nUsers to be deleted:');
|
console.log('\nUsers to be deleted:');
|
||||||
usersToDelete.forEach(user => {
|
usersToDelete.forEach(user => {
|
||||||
|
@ -71,7 +75,7 @@ async function main() {
|
||||||
console.log();
|
console.log();
|
||||||
|
|
||||||
const confirmed = await askForConfirmation(`Are you sure you want to delete ${usersToDelete.length} users?`);
|
const confirmed = await askForConfirmation(`Are you sure you want to delete ${usersToDelete.length} users?`);
|
||||||
|
|
||||||
if (!confirmed) {
|
if (!confirmed) {
|
||||||
console.log('Operation cancelled by user');
|
console.log('Operation cancelled by user');
|
||||||
rl.close();
|
rl.close();
|
||||||
|
|
Loading…
Reference in a new issue