This repository has been archived by the owner on Aug 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (52 loc) · 2.27 KB
/
index.js
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
54
55
56
57
58
59
60
61
62
const https = require('https');
const { Client } = require('@threadsjs/threads.js');
// Define the API endpoint URL
const apiUrl = 'https://api.omg.lol/address/[addresshere]/statuses/latest';
// Clear the console and display a header message
console.clear();
console.log('Status.lol - Threads Integration by Ediz Baha');
// Initialize variables to store previous emoji and content
let previousEmoji = '';
let previousContent = '';
// Define an asynchronous function to check the API and share updates
const checkAndShare = async () => {
try {
// Make an HTTP GET request to the specified API endpoint
const response = await new Promise((resolve, reject) => {
https.get(apiUrl, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
resolve(data);
});
}).on('error', (error) => {
reject(error.message);
});
});
// Parse the JSON response from the API
const responseData = JSON.parse(response);
const emoji = responseData.response.status.emoji;
const content = responseData.response.status.content;
// Check if the emoji or content has changed since the last check
if (emoji !== previousEmoji || content !== previousContent) {
// Create a Threads.js client and login with credentials
const client = new Client();
await client.login('[usernamehere]', '[passwordhere]');
// Create a new post with the updated emoji and content
await client.posts.create(1, { contents: `${emoji} ${content}` });
console.log(`'${emoji} ${content}' shared on Threads.`);
// Update the previousEmoji and previousContent variables
previousEmoji = emoji;
previousContent = content;
} else {
console.log(`'${emoji} ${content}' was already shared on Threads.`);
}
} catch (error) {
console.error('Error:', error);
}
};
// Initial call to checkAndShare function and set up periodic checks
checkAndShare();
setInterval(checkAndShare, 60000); // Repeat the checkAndShare function every 60 seconds