- Make NWRplay use new GWES icecast server!
This commit is contained in:
parent
662e0e775c
commit
d48fe3085a
41
index.js
41
index.js
|
@ -7,7 +7,7 @@ const blacklist = require("./data/blacklist.json");
|
|||
const events = require("./data/events.json");
|
||||
const outlookURLs = require("./data/outlook.json");
|
||||
const sattelites = require("./data/sattelites.json");
|
||||
const nwrstreams = require("./data/nwrstreams.json")
|
||||
const nwrstreams = {callsigns:{}};
|
||||
const Jimp = require("jimp");
|
||||
const { client, xml } = require("@xmpp/client");
|
||||
const fetch = require("node-fetch");
|
||||
|
@ -264,6 +264,24 @@ var errCount = 0;
|
|||
const curUUID = generateUUID();
|
||||
|
||||
|
||||
// nwrstreams setup
|
||||
// get icecast json data http://ingest.wxr.gwes-cdn.net/status-json.xsl
|
||||
const fetchNWRstreams = () => {
|
||||
fetch("http://ingest.wxr.gwes-cdn.net/status-json.xsl").then((res) => {
|
||||
res.json().then((json) => {
|
||||
json.icestats.source.forEach((source) => {
|
||||
nwrstreams.callsigns[source.server_name] = source.listenurl;
|
||||
});
|
||||
});
|
||||
console.log(`${colors.cyan("[INFO]")} Fetched NWR streams`);
|
||||
}).catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
|
||||
fetchNWRstreams();
|
||||
setInterval(fetchNWRstreams, 5 * 60 * 1000); // Every 5 minutes
|
||||
|
||||
const xmpp = client({
|
||||
service: "xmpp://conference.weather.im",
|
||||
domain: "weather.im",
|
||||
|
@ -693,16 +711,10 @@ discord.on('ready', async () => {
|
|||
"description": "The URL of the stream to play",
|
||||
"type": 3,
|
||||
"required": true,
|
||||
"choices": []
|
||||
"autocomplete": true
|
||||
}
|
||||
]
|
||||
}
|
||||
for (const key in nwrstreams.callsigns) {
|
||||
nwrplayCommand.options[0].choices.push({
|
||||
"name": key,
|
||||
"value": key
|
||||
});
|
||||
}
|
||||
commands.push(nwrplayCommand);
|
||||
}
|
||||
await (async () => {
|
||||
|
@ -1448,6 +1460,19 @@ discord.on("interactionCreate", async (interaction) => {
|
|||
}
|
||||
break;
|
||||
|
||||
case Discord.InteractionType.ApplicationCommandAutocomplete:
|
||||
//map nwrstreams
|
||||
if (interaction.commandName === "nwrplay") {
|
||||
let callsignSearch = interaction.options.getString("callsign");
|
||||
let callsigns = Object.keys(nwrstreams.callsigns);
|
||||
let results = callsigns.filter((callsign) => callsign.toLowerCase().includes(callsignSearch.toLowerCase()));
|
||||
if (results.length > 25) {
|
||||
results = results.slice(0, 25);
|
||||
}
|
||||
interaction.respond(results.map((callsign) => ({ name: callsign, value: callsign })));
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue