-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
139 lines (115 loc) · 4.55 KB
/
app.js
File metadata and controls
139 lines (115 loc) · 4.55 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Impprts
var express = require('express');
var app = express();
const bodyParser = require('body-parser');
const RPC = require('discord-rpc')
const client = new RPC.Client({ transport: 'ipc' })
const activity = {}
const assets = {}
const fetch = require('node-fetch');
// Set the view engine to ejs & add bodyparser
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({ extended: true }));
// Render Index Page
app.get('/', function(req, res) {
res.render('index');
});
// ChillWav Preset
app.get('/chillwav', (req, res) => {
assets.large_image = 'logo';
assets.large_text = 'ChillWav Radio';
activity.buttons = [
{
"label": "Website",
"url": "https://chillwavradio.com"
},
{
"label": "Discord",
"url": "https://discord.gg/QcMG4EyrzM"
}
];
activity.assets = assets;
async function loadFileAndDoStuff(url) {
try {
const response = await fetch(url);
const data = await response.json();
console.log(data[0].now_playing.song.title + " Is the name of the song!");
console.log(data[0].now_playing.song.artist + " Is the name of the artist!")
var presenter = 'abc';
var myarr = data[0].now_playing.song.text.split("-");
var streamer = data[0].now_playing.streamer;
if (data[0].now_playing.streamer == "") {
console.log("Auto DJ")
var presenter = 'Otto'
} else {
console.log('Real DJ')
var presenter = data[0].now_playing.streamer
}
activity.state = `Presenter: ${presenter}`;
activity.details = `Song: ${myarr[1]}`;
client.on('ready', () => {
client.request('SET_ACTIVITY', {
pid: process.pid,
activity: activity
})
});
console.log('Presence Sent')
client.login({ clientId: '826874981828132905' })
console.log()
var obj = JSON.stringify(data)
} catch (err) {
console.error(err);
}
}
setInterval(a => {
loadFileAndDoStuff('https://radio.chillwavradio.com/api/nowplaying');
}, 60000)
console.log('status set')
res.sendStatus(200);
});
// Custom Status
app.post('/custom', (req, res) => {
console.log('Got body from custom: ', req.body);
activity.state = req.body.sl;
activity.details = req.body.fl;
assets.large_image = req.body.li;
assets.small_image = req.body.si;
if (req.body.btncnt == '1') {
activity.buttons = [
{
"label": req.body.btnatxt,
"url": req.body.btnaurl
}
];
}
else if (req.body.btncnt == '2') {
activity.buttons = [
{
"label": req.body.btnatxt,
"url": req.body.btnaurl
},
{
"label": req.body.btnbtxt,
"url": req.body.btnburl
}
];
} else if (req.body.btncnt > 2) {
console.log('We all wish Discord supported more than 2 buttons. I have set the button count to 0.')
} else if (isNaN(req.body.btncnt)) {
console.log(req.body.btncnt + ' doesnt appear to be a number. I have set the button count to 0.')
}
activity.assets = assets;
client.on('ready', () => {
client.request('SET_ACTIVITY', {
pid: process.pid,
activity: activity
})});
console.log('Presence Sent')
client.login({ clientId: req.body.ID })
console.log('status set')
res.render('response');
});
// Start the webserver on port 8080
app.listen(8080);
// Output the copyright and port to the console
console.log('Listening on port: 8080\n© ' + new Date().getFullYear() + ' NeonDevelopment, SkepSickomode');