Implemented Medal alert system for cloaky smh
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
.env
|
||||||
+109
-7
@@ -1,19 +1,29 @@
|
|||||||
const express = require('express');
|
const app = require('express')();
|
||||||
|
const { static } = require('express');
|
||||||
const bodyParser = require('body-parser');
|
const bodyParser = require('body-parser');
|
||||||
const http = require('http');
|
|
||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
const morgan = require('morgan');
|
const morgan = require('morgan');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
|
const http = require('http').Server(app);
|
||||||
|
const io = require('socket.io')(http);
|
||||||
|
const puppeteer = require('puppeteer');
|
||||||
|
const dom = require('jsdom');
|
||||||
|
const NodeCache = require('node-cache');
|
||||||
|
const math = require('mathjs')
|
||||||
|
require('dotenv').config();
|
||||||
|
|
||||||
const app = express();
|
const cache = new NodeCache();
|
||||||
|
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.use(morgan('dev'));
|
app.use(morgan('dev'));
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
|
app.use(static(__dirname + '/public'));
|
||||||
app.use(bodyParser.urlencoded({
|
app.use(bodyParser.urlencoded({
|
||||||
extended: true
|
extended: true
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
timer = false;
|
||||||
|
global = {}
|
||||||
|
|
||||||
app.get('/', (req, res) => {
|
app.get('/', (req, res) => {
|
||||||
res.send({ "status": 200 })
|
res.send({ "status": 200 })
|
||||||
})
|
})
|
||||||
@@ -99,7 +109,99 @@ app.post(`/tools/mcw/clip`, async (req, res) => {
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const httpServer = http.createServer(app);
|
app.get('/browser/medal', (req, res) => {
|
||||||
httpServer.listen(process.env.PORT || 3000, () => {
|
return res.sendFile(__dirname + '/public/index.html')
|
||||||
console.log('on!')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
io.on('connection', (socket) => {
|
||||||
|
socket.on('event', msg => {
|
||||||
|
io.emit('event', msg);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post(`/browser/medal/alert`, async (req, res) => {
|
||||||
|
const header = req.header(`secret`)
|
||||||
|
|
||||||
|
if(header === `${process.env.access}`) {
|
||||||
|
timer = true;
|
||||||
|
res.send({ "status": 200, "message": "Started listening to Medal's API." })
|
||||||
|
|
||||||
|
interval = setInterval(async function() {
|
||||||
|
var medalApiData = await fetch(`${process.env.medalapi}/24378`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: { 'x-authentication': `${process.env.medalauth}` }
|
||||||
|
}).then(response => response.json());
|
||||||
|
|
||||||
|
try {
|
||||||
|
if(cache.has('uniqueKey')) {
|
||||||
|
if (medalApiData.followers === cache.get('uniqueKey')) {
|
||||||
|
return console.log(`User hasn't gained followers, not firing.` + `\nCache: ${cache.get('uniqueKey')} & Medal API: ${medalApiData.followers}.`);
|
||||||
|
} else if (medalApiData.followers > cache.get('uniqueKey')) {
|
||||||
|
console.log(`More followers than before`, `${medalApiData.followers} vs ${cache.get('uniqueKey')}`)
|
||||||
|
var arrayNum = math.subtract(medalApiData.followers, 13)
|
||||||
|
obj = Object.keys(medalApiData.userFollowers)[arrayNum]
|
||||||
|
await getFollowerInfo(obj)
|
||||||
|
io.emit('event', global.follower);
|
||||||
|
return cache.set('uniqueKey', medalApiData.followers)
|
||||||
|
} else if (medalApiData.followers < cache.get('uniqueKey')) {
|
||||||
|
console.log(`User lost followers.`, `Cache: ${cache.get('uniqueKey')} & Medal API: ${medalApiData.followers}.`)
|
||||||
|
return cache.set('uniqueKey', medalApiData.followers)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log(`User wasn't cached at all.`)
|
||||||
|
return cache.set(`uniqueKey`, medalApiData.followers)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
console.log(err)
|
||||||
|
}
|
||||||
|
}, 10*60000)
|
||||||
|
} else {
|
||||||
|
return res.status(401).send({ "status": 401, "message": "401 Not Authorized. Access Token Header missing" })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
app.get(`/browser/medal/test`, (req, res) => {
|
||||||
|
var header = req.query.secret
|
||||||
|
|
||||||
|
if(header === `${process.env.access}`) {
|
||||||
|
const follower = `poggers`
|
||||||
|
io.emit('event', follower);
|
||||||
|
|
||||||
|
return res.send({ "status": 200, "message": "Event successfully emitted" })
|
||||||
|
} else {
|
||||||
|
return res.status(401).send({ "status": 401, "message": "401 Not Authorized. Access Token Header missing" })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
app.get(`/browser/medal/stop`, (req, res) => {
|
||||||
|
var header = req.header(`secret`)
|
||||||
|
if(header === `${process.env.access}`) {
|
||||||
|
clearInterval(interval)
|
||||||
|
return res.send({ "status": 200, "message": "Interval successfully cleared" })
|
||||||
|
} else {
|
||||||
|
return res.status(401).send({ "status": 401, "message": "401 Not Authorized. Access Token Header missing" })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
app.get('/browser/medal/activity', (req, res) => {
|
||||||
|
if (timer === true) {
|
||||||
|
return res.status(200).send({ "status": 200, "active": true, "message": "The Medal API Check Timer is ACTIVE." })
|
||||||
|
} else if (timer === false) {
|
||||||
|
return res.status(200).send({ "status": 200, "active": false, "message": "The Medal API Check Timer is NOT ACTIVE."})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
async function getFollowerInfo(follower) {
|
||||||
|
|
||||||
|
var follower = await fetch(`${process.env.medalapi}/${follower}`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: { 'x-authentication': `${process.env.medalauth}` }
|
||||||
|
}).then(response => response.json());
|
||||||
|
|
||||||
|
global.follower = follower.userName
|
||||||
|
}
|
||||||
|
|
||||||
|
http.listen(process.env.PORT, () => {
|
||||||
|
console.log(`Socket.IO server running at https://api.awexxx.xyz`);
|
||||||
|
});
|
||||||
|
|||||||
Generated
+3062
-1
File diff suppressed because it is too large
Load Diff
+7
-2
@@ -6,12 +6,17 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"body-parser": "^1.19.0",
|
"body-parser": "^1.19.0",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
|
"dotenv": "^10.0.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"http": "^0.0.1-security",
|
"http": "^0.0.1-security",
|
||||||
|
"jsdom": "^17.0.0",
|
||||||
|
"mathjs": "^9.4.4",
|
||||||
"morgan": "^1.10.0",
|
"morgan": "^1.10.0",
|
||||||
"node-fetch": "^2.6.1"
|
"node-cache": "^5.1.2",
|
||||||
|
"node-fetch": "^2.6.1",
|
||||||
|
"puppeteer": "^10.2.0",
|
||||||
|
"socket.io": "^4.1.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {},
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
body {
|
||||||
|
font-family: 'Teko', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3{
|
||||||
|
color:gray;
|
||||||
|
}
|
||||||
|
|
||||||
|
.center {
|
||||||
|
display: block;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
width: 40%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#container {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#img {
|
||||||
|
padding-top:20px;
|
||||||
|
animation: fadeIn 1s;
|
||||||
|
-webkit-animation: fadeIn 1s;
|
||||||
|
-moz-animation: fadeIn 1s;
|
||||||
|
-o-animation: fadeIn 1s;
|
||||||
|
-ms-animation: fadeIn 1s;
|
||||||
|
}
|
||||||
|
@keyframes fadeIn {
|
||||||
|
0% {opacity:0;}
|
||||||
|
100% {opacity:1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
@-moz-keyframes fadeIn {
|
||||||
|
0% {opacity:0;}
|
||||||
|
100% {opacity:1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
@-webkit-keyframes fadeIn {
|
||||||
|
0% {opacity:0;}
|
||||||
|
100% {opacity:1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
@-o-keyframes fadeIn {
|
||||||
|
0% {opacity:0;}
|
||||||
|
100% {opacity:1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
@-ms-keyframes fadeIn {
|
||||||
|
0% {opacity:0;}
|
||||||
|
100% {opacity:1;}
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 7.2 MiB |
Binary file not shown.
@@ -0,0 +1,20 @@
|
|||||||
|
async function recievedAlert(follower) {
|
||||||
|
var audio = document.getElementById('audio');
|
||||||
|
|
||||||
|
// Play the Medal intro audio & gif
|
||||||
|
setTimeout(function() {
|
||||||
|
var gif = document.getElementById(`gif`)
|
||||||
|
var img = document.getElementById(`img`)
|
||||||
|
img.style.display = `block`;
|
||||||
|
gif.setAttribute(`width`, `350`)
|
||||||
|
gif.setAttribute(`src`, `assets/img/medal-gif.gif`)
|
||||||
|
var text = document.getElementById(`text`);
|
||||||
|
text.innerText = `CloakyBrokey was followed by ${follower} on Medal.tv!`
|
||||||
|
audio.play();
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
document.getElementById(`img`).innerHTML = ``;
|
||||||
|
}, 15000)
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" href="/assets/css/main.css">
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Teko:wght@500&display=swap" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id="container" style="text-align:center;">
|
||||||
|
<div id="img">
|
||||||
|
<img class="center" width="350" id="gif" src="/assets/img/medal-gif.gif">
|
||||||
|
<h3 id="text" style="font-size:50px;"></h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<audio src="/assets/img/medal-novideo.mp3" id="audio"></audio>
|
||||||
|
|
||||||
|
<script src="/socket.io/socket.io.js"></script>
|
||||||
|
<script>
|
||||||
|
var socket = io();
|
||||||
|
|
||||||
|
socket.on('event', function(msg) {
|
||||||
|
var audio = document.getElementById('audio');
|
||||||
|
|
||||||
|
// Play the Medal intro audio & gif
|
||||||
|
setTimeout(function() {
|
||||||
|
document.getElementById(`container`).style.display = `block`;
|
||||||
|
text.innerText = `CloakyBrokey was followed by ${msg} on Medal.tv!`
|
||||||
|
console.log(msg)
|
||||||
|
audio.play();
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
document.getElementById(`container`).style.display = `none`;
|
||||||
|
}, 9000)
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user