-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathx-delete.mjs
More file actions
53 lines (46 loc) · 1.34 KB
/
Copy pathx-delete.mjs
File metadata and controls
53 lines (46 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env node
import { TwitterApi } from 'twitter-api-v2';
import {
getCredentialHelpText,
getDeleteHelpText,
loadCredentials,
parseDeleteArgs,
} from './lib/x-cli-common.mjs';
const parsed = parseDeleteArgs(process.argv.slice(2));
if (parsed.help) {
console.log(getDeleteHelpText());
process.exit(0);
}
if (parsed.error) {
console.error(`❌ ${parsed.error}`);
console.error(getDeleteHelpText());
process.exit(1);
}
const credentialState = loadCredentials({ configPath: parsed.configPath });
if (!credentialState.credentials) {
console.error(`❌ ${credentialState.error}`);
console.error(getCredentialHelpText(credentialState.searchedPaths));
process.exit(1);
}
const client = new TwitterApi({
appKey: credentialState.credentials.consumerKey,
appSecret: credentialState.credentials.consumerSecret,
accessToken: credentialState.credentials.accessToken,
accessSecret: credentialState.credentials.accessTokenSecret,
});
let hasFailures = false;
for (const tweetId of parsed.tweetIds) {
try {
await client.v2.deleteTweet(tweetId);
console.log(`✅ Deleted: ${tweetId}`);
} catch (error) {
hasFailures = true;
console.error(`❌ Failed to delete ${tweetId}: ${error.message}`);
if (error.data) {
console.error(JSON.stringify(error.data, null, 2));
}
}
}
if (hasFailures) {
process.exit(1);
}