-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
113 lines (94 loc) · 2.67 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import express from "express";
import dotenv from "dotenv";
import http from "http";
import {Server} from "socket.io";
import {stream_info, send_whisper} from "./modules/index.js";
import {send_tweet} from "./modules/tweets/index.js";
import fs from "fs";
dotenv.config()
const app = express();
const server = http.createServer(app);
const io = new Server(server, {
cors: {
origin: "*"
}
});
const port = process.env.PORT || 3000
/*
false = Stream is Offline
true = Stream is Online
*/
let yfl = {
youngmulti: false,
xmerghani: false,
mrdzinold: false,
banduracartel: false,
mork: false,
xspeedyq: false,
xkaleson: false,
adrian1g__: false,
youngmulti_game: 'Just Chatting',
xmerghani_game: 'Just Chatting',
mrdzinold_game: 'Just Chatting',
banduracartel_game: 'Just Chatting',
xkaleson_game: 'Just Chatting',
mork_game: 'Just Chatting'
}
app.set('json spaces', 2);
app.use(express.json());
app.get('/', function (req, res) {
res.json({"message": "wss://wss.yfl.es"})
})
app.post("/send/whisper", async (req, res) => {
if (!req.body) {
return res.status(400).send({
message: "Content can not be empty!"
});
}
if(req.headers.id !== process.env.BOT_ID && req.headers.token !== process.env.TOKEN){
return res.status(401).send({
message: "Unauthorized. Invalid token!"
});
}
const { to, message } = req.body;
res.status(200).send({
message: "Success"
});
await send_whisper(to, message);
});
io.on('connection', (socket) => {
//console.log('a user connected');
socket.emit('channels', yfl);
socket.on('refresh channels', (data) => {
socket.emit('channels', yfl);
});
socket.on('disconnect', () => {
//console.log('user disconnected');
});
});
setInterval(() => {
stream_analyzing(yfl)
}, 60 * 1000);
async function stream_analyzing(crew){
const streams = await stream_info(crew);
if(streams.error) return;
yfl = streams.channels;
if (streams.list.length === 0) return;
streams.list.map(function(x) {
sendNoti({
nickname: x.nickname,
title: x.title,
thumbnail: x.thumbnail
})
});
}
function sendNoti(i){
io.sockets.emit('live notification', i);
if(i.nickname.toLowerCase() === "xspeedyq" || i.nickname.toLowerCase() === "adrian1g__") return;
send_tweet(i)
// console.log(i)
}
server.listen(port, () => {
console.log(process.env.TWITCH_CLIENT_ID ? ("SYSTEM: env is working"):("SYSTEM: env is not working"), '- YFL - listening on *:'+port);
yfl = JSON.parse(fs.readFileSync("crew.json", "utf8"))
});