First working version

This commit is contained in:
Wizzard 2024-03-02 14:57:32 -05:00
commit 2ed93d3e93
5 changed files with 245 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/node_modules
.env

2
EXAMPLE.env Normal file
View File

@ -0,0 +1,2 @@
OBS_PASSWORD=4444
tokenAddress=1287981y925hjskklsjatkls

99
main.js Normal file
View File

@ -0,0 +1,99 @@
require('dotenv').config();
const axios = require('axios');
const WebSocket = require('ws');
const crypto = require('crypto');
const obsWebSocketUrl = 'ws://localhost:4444';
const password = process.env.OBS_PASSWORD;
const ws = new WebSocket(obsWebSocketUrl);
ws.on('open', () => {
console.log('Connected to OBS WebSocket server.');
ws.send(JSON.stringify({
'request-type': 'GetAuthRequired',
'message-id': 'authRequired'
}));
});
ws.on('message', (data) => {
const message = JSON.parse(data.toString());
if (message['message-id'] === 'authRequired') {
if (message.authRequired) {
const auth = generateAuth(password, message.salt, message.challenge);
ws.send(JSON.stringify({
'request-type': 'Authenticate',
'message-id': 'authenticate',
'auth': auth
}));
} else {
setInterval(updateOBSTextVisibility, 60000);
}
} else if (message['message-id'] === 'authenticate') {
if (message.status === 'ok') {
setInterval(updateOBSTextVisibility, 5000);
} else {
console.error('Authentication failed:', message.error);
}
} else if (message['message-id'] === 'setText') {
if (message.status === 'ok') {
console.log('Text updated successfully in OBS.');
} else {
console.error('Failed to update text in OBS:', message.error);
}
}
});
ws.on('error', (error) => {
console.error('WebSocket error:', error);
});
const setSourceVisibility = (sourceName, visible) => {
const message = {
'request-type': 'SetSourceRender',
'source': sourceName,
'render': visible,
'message-id': 'setSourceVisibility'
};
ws.send(JSON.stringify(message));
};
const updateOBSTextVisibility = (makingMoney) => {
setSourceVisibility("TextGreen", makingMoney);
setSourceVisibility("TextRed", !makingMoney);
};
const checkStatusAndUpdateOBS = () => {
const tokenAddress = process.env.tokenAddress;
axios.get(`https://api.dexscreener.com/latest/dex/tokens/${tokenAddress}`)
.then((response) => {
const pairs = response.data.pairs;
if (pairs && pairs.length > 0) {
const priceChange = pairs[0].priceChange.m5;
const makingMoney = priceChange > 0;
console.log(`Price Change (Last 5 Minutes): ${priceChange}%`);
console.log('Making Money:', makingMoney);
setSourceVisibility("TextGreen", makingMoney);
setSourceVisibility("TextRed", !makingMoney);
} else {
console.log('No pairs data found for the token address');
}
})
.catch((error) => {
console.error('Error fetching data:', error);
});
};
function generateAuth(password, salt, challenge) {
const secret = crypto.createHash('sha256').update(password + salt).digest('base64');
const authResponse = crypto.createHash('sha256').update(secret + challenge).digest('base64');
return authResponse;
}
setInterval(checkStatusAndUpdateOBS, 5000);

135
package-lock.json generated Normal file
View File

@ -0,0 +1,135 @@
{
"name": "dexscreener-obs",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"axios": "^1.6.7",
"dotenv": "^16.4.5",
"ws": "^8.16.0"
}
},
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
},
"node_modules/axios": {
"version": "1.6.7",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.6.7.tgz",
"integrity": "sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA==",
"dependencies": {
"follow-redirects": "^1.15.4",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
}
},
"node_modules/combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"dependencies": {
"delayed-stream": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/dotenv": {
"version": "16.4.5",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz",
"integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/follow-redirects": {
"version": "1.15.5",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz",
"integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/form-data": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"dependencies": {
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
},
"node_modules/ws": {
"version": "8.16.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.16.0.tgz",
"integrity": "sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": ">=5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
}
}
}

7
package.json Normal file
View File

@ -0,0 +1,7 @@
{
"dependencies": {
"axios": "^1.6.7",
"dotenv": "^16.4.5",
"ws": "^8.16.0"
}
}