2023-05-27 17:07:52 +02:00

125 lines
2.7 KiB
JavaScript

// https://api.fynn.ai/events
// https://vps.anotherfoxguy.com/dl/fur-events.json
const axios = require("axios").default;
const moment = require("moment");
const ical = require("ical-generator").default;
const config = require("./config.json");
//let events_data
async function main() {
//events_data = (await axios("https://vps.anotherfoxguy.com/dl/fur-events.json")).data;
events_data = (await axios("https://api.fynn.ai/v1/events")).data;
//GenDiscord();
GenIcal();
}
function GenDiscord() {
let min = moment().add(1, "minutes"); // minutes
let max = moment().add(61, "minutes");
// let max = moment().add(8, "hours");
//console.log(dat.data)
let data = events_data.filter((event) => event.type != "Lobby");
const events = data.filter((event) =>
moment.unix(event.start).isBetween(min, max)
);
evembeds = [];
events.forEach((event) => {
console.log(event.name);
switch (event.subType) {
case "Meetup":
colour = 1293056;
break;
case "Dance":
colour = 16711922;
break;
case "Panel":
colour = 16752128;
break;
default:
colour = 34047;
}
let embed = {
title: event.name, //`${event.name} will start in <t:${event.start}:R>`,// <t:1636124400:R>
description: event.description.replace(/\\n/gm, "\n"),
timestamp: moment.unix(event.start),
url: `https://furality.org/schedule#${event.id}`,
color: colour,
fields: [
{
name: "Starts",
value: `<t:${event.start}:R>`,
inline: true,
},
{
name: "Ends",
value: `<t:${event.end}:R>`,
inline: true,
},
],
};
if (event.image_url != "missing") {
embed.image = {
url: event.image_url,
};
}
evembeds.push(embed);
});
if (evembeds.length > 0) {
axios
.post(config.webhookurl, {
embeds: evembeds,
})
.catch(function (error) {
console.error(error);
});
// console.log(
// JSON.stringify({
// embeds: evembeds,
// })
// );
}
//let event = data[1];
}
function GenIcal() {
const calendar = ical({
name: 'Furality Schedule',
description: 'Unofficial Furality Schedule created by AnotherFoxGuy',
source: 'https://furality.anotherfoxguy.com/calendar.ical',
ttl: 3600
});
events_data.forEach((event) => {
calendar.createEvent({
id: event.id,
start: moment.unix(event.start),
end: moment.unix(event.end),
summary: event.name,
description: event.description,
url: `https://furality.org/schedule#${event.id}`,
attachments: [
event.imageUrl
]
});
});
calendar.save('./public/calendar.ical');
}
main();