{"size": 1235, "ext": "js", "max_stars_repo_path": "Youtube Notification Bot/index.js", "max_stars_repo_name": "Heges69/Tutorials", "max_stars_repo_stars_event_min_datetime": "2022-01-19T11:33:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-19T11:33:45.000Z", "max_issues_repo_path": "Youtube Notification Bot/index.js", "max_issues_repo_name": "Heges69/Tutorials", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Youtube Notification Bot/index.js", "max_forks_repo_name": "Heges69/Tutorials", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.5, "max_line_length": 148, "alphanum_fraction": 0.595951417}
require("dotenv").config();
const { Client, MessageEmbed } = require("discord.js"),
    { GCommands } = require("gcommands"),
    RSSParser = require("rss-parser")

const client = new Client();
client.request = new RSSParser();
client.config = require("./config.json")

client.on("ready", async() => {
    const gc = new GCommands(client, {
        cmdDir: "commands/",
        language: "english",
        slash: {
            slash: true,
            prefix: "."
        }
    })

    gc.on("log", console.log)
    gc.on("debug", console.log)

    setInterval(async() => {
        let ytChannel = client.channels.cache.get(client.config.notificationChannelId)
        let urlRegexp = /(https?:\/\/[^ ]*)/

        let req = (await client.request.parseURL(`https://www.youtube.com/feeds/videos.xml?channel_id=${client.config.youtubeChannelId}`)).items[0]

        let ifAlready = (await ytChannel.messages.fetch({ limit: 1 })).array()[0].content.match(urlRegexp);
        if(ifAlready != null) ifAlready = ifAlready[1]
        if(ifAlready == req.link) return;

        ytChannel.send(`${client.config.newVideoMessage.replace(`{url}`,req.link)}`)
    }, 15000)
})

client.login(process.env.token)
