From 50560c6dab936f10bc500e4ffa521414ccb01227 Mon Sep 17 00:00:00 2001 From: namekinggamerboy <53903319+namekinggamerboy@users.noreply.github.com> Date: Sun, 5 Apr 2020 13:33:34 +0530 Subject: [PATCH 1/4] Rename config.sample.json to config.json --- config.sample.json => config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename config.sample.json => config.json (99%) diff --git a/config.sample.json b/config.json similarity index 99% rename from config.sample.json rename to config.json index c48f49c..c9fef76 100644 --- a/config.sample.json +++ b/config.json @@ -8,4 +8,4 @@ "https://www.youtube.com/channel/UCNuYih-JMtLxOlsjeIos4ZA" ], "youtubeKey": "your http://console.developer.google.com youtube v3 api key" -} \ No newline at end of file +} From c6e89415b5f3a187547aa2aedb714f3ca0793739 Mon Sep 17 00:00:00 2001 From: namekinggamerboy <53903319+namekinggamerboy@users.noreply.github.com> Date: Fri, 1 May 2020 11:08:36 +0530 Subject: [PATCH 2/4] Update package.json --- package.json | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 711adbf..affff52 100644 --- a/package.json +++ b/package.json @@ -1,23 +1,15 @@ { - "name": "discordyoutubenotifier", - "version": "1.0.0", + "name": "ytnoti", + "version": "1.0.0-dev", "description": "Be notified when one of your favorite youtubers posts a video! ", "main": "index.js", - "scripts": { + "scripts": { + "start": "node index.js", "test": "node index.js" }, - "repository": { - "type": "git", - "url": "git+https://github.com/Androz2091/DiscordYoutubeNotifier.git" - }, - "author": "Androz2091", + "author": "namekinggamerboy", "license": "ISC", - "bugs": { - "url": "https://github.com/Androz2091/DiscordYoutubeNotifier/issues" - }, - "homepage": "https://github.com/Androz2091/DiscordYoutubeNotifier#readme", "dependencies": { - "discord.js": "^11.5.1", "rss-parser": "^3.7.2", "simple-youtube-api": "^5.2.1" } From d9df374b2497f62fbabb3f950b7ebe5fce8e26b6 Mon Sep 17 00:00:00 2001 From: namekinggamerboy <53903319+namekinggamerboy@users.noreply.github.com> Date: Fri, 1 May 2020 11:25:27 +0530 Subject: [PATCH 3/4] Update index.js --- index.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 6c2d30d..70ff8bd 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,16 @@ -const config = require("./config.json"), -Discord = require("discord.js"), +class list { +constructor(client, token) { +this.token = token; +this.client = client; +this.client.on("ready", () => { +this.apiPost(); +}); +} + +async apiPost() { + +if(!this.client) return console.log("make sure check out your code and install client"); +const Discord = require("discordjs"), Parser = require("rss-parser"), parser = new Parser(), Youtube = require("simple-youtube-api"), @@ -8,13 +19,12 @@ youtube = new Youtube(config.youtubeKey); const startAt = Date.now(); const lastVideos = {}; -const client = new Discord.Client(); -client.login(config.token).catch(console.log); +const client = this.client; client.on("ready", () => { console.log(`[!] Ready to listen ${config.youtubers.length} youtubers!`); check(); - setInterval(check, 20*1000); + setInterval(check, 30); }); /** @@ -127,3 +137,6 @@ async function check(){ lastVideos[channelInfos.raw.snippet.title] = video; }); } + +} +module.exports = list; From 6b94324ba141f45d7d126d1da0ffd22e3862e48e Mon Sep 17 00:00:00 2001 From: "Glitch (namekinggamerboy-ytupdate-bot)" Date: Sat, 16 May 2020 02:20:43 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=93=BC=E2=9B=84=EF=B8=8F=20Updated=20?= =?UTF-8?q?with=20NAME=20BOY=20Sir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 --- index.js | 50 +++++++++++++++++++++++-------------------- shrinkwrap.yaml | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 26 deletions(-) delete mode 100644 .gitignore create mode 100644 shrinkwrap.yaml diff --git a/.gitignore b/.gitignore deleted file mode 100644 index a059ff4..0000000 --- a/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -node_modules/* -config.json - diff --git a/index.js b/index.js index 70ff8bd..dff23ec 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,16 @@ +const Parser = require("rss-parser"), +parser = new Parser(), +Youtube = require("simple-youtube-api"); + class list { constructor(client, token) { -this.token = token; +this.token = token.youtubekey; +this.channel = token.channel; +this.dischannel = token.discordchannel; +this.msg = token.discordmsg; this.client = client; this.client.on("ready", () => { +console.log("🎉[yt update notification now ready]🎉"); this.apiPost(); }); } @@ -10,11 +18,7 @@ this.apiPost(); async apiPost() { if(!this.client) return console.log("make sure check out your code and install client"); -const Discord = require("discordjs"), -Parser = require("rss-parser"), -parser = new Parser(), -Youtube = require("simple-youtube-api"), -youtube = new Youtube(config.youtubeKey); +const youtube = new Youtube(this.token); const startAt = Date.now(); const lastVideos = {}; @@ -22,7 +26,7 @@ const lastVideos = {}; const client = this.client; client.on("ready", () => { - console.log(`[!] Ready to listen ${config.youtubers.length} youtubers!`); + //console.log(`[!] Ready to listen ${this.channel.length} youtubers!`); check(); setInterval(check, 30); }); @@ -44,15 +48,15 @@ function formatDate(date) { * @returns The last video of the youtuber */ async function getLastVideo(youtubeChannelName, rssURL){ - console.log(`[${youtubeChannelName}] | Getting videos...`); + //console.log(`[${youtubeChannelName}] | Getting videos...`); let content = await parser.parseURL(rssURL); - console.log(`[${youtubeChannelName}] | ${content.items.length} videos found`); + // console.log(`[${youtubeChannelName}] | ${content.items.length} videos found`); let tLastVideos = content.items.sort((a, b) => { let aPubDate = new Date(a.pubDate || 0).getTime(); let bPubDate = new Date(b.pubDate || 0).getTime(); return bPubDate - aPubDate; }); - console.log(`[${youtubeChannelName}] | The last video is "${tLastVideos[0] ? tLastVideos[0].title : "err"}"`); + // console.log(`[${youtubeChannelName}] | The last video is "${tLastVideos[0] ? tLastVideos[0].title : "err"}"`); return tLastVideos[0]; } @@ -63,15 +67,15 @@ async function getLastVideo(youtubeChannelName, rssURL){ * @returns The video || null */ async function checkVideos(youtubeChannelName, rssURL){ - console.log(`[${youtubeChannelName}] | Get the last video..`); + // console.log(`[${youtubeChannelName}] | Get the last video..`); let lastVideo = await getLastVideo(youtubeChannelName, rssURL); // If there isn't any video in the youtube channel, return - if(!lastVideo) return console.log("[ERR] | No video found for "+lastVideo); + // if(!lastVideo) return console.log("[ERR] | No video found for "+lastVideo); // If the date of the last uploaded video is older than the date of the bot starts, return - if(new Date(lastVideo.pubDate).getTime() < startAt) return console.log(`[${youtubeChannelName}] | Last video was uploaded before the bot starts`); + if(new Date(lastVideo.pubDate).getTime() < startAt) return; //console.log(`[${youtubeChannelName}] | Last video was uploaded before the bot starts`); let lastSavedVideo = lastVideos[youtubeChannelName]; // If the last video is the same as the last saved, return - if(lastSavedVideo && (lastSavedVideo.id === lastVideo.id)) return console.log(`[${youtubeChannelName}] | Last video is the same as the last saved`); + if(lastSavedVideo && (lastSavedVideo.id === lastVideo.id)) //console.log(`[${youtubeChannelName}] | Last video is the same as the last saved`); return lastVideo; } @@ -117,26 +121,26 @@ async function getYoutubeChannelInfos(name){ * Check for new videos */ async function check(){ - console.log("Checking..."); - config.youtubers.forEach(async (youtuber) => { + // console.log("Checking..."); + this.channel.forEach(async (youtuber) => { console.log(`[${youtuber.length >= 10 ? youtuber.slice(0, 10)+"..." : youtuber}] | Start checking...`); let channelInfos = await getYoutubeChannelInfos(youtuber); - if(!channelInfos) return console.log("[ERR] | Invalid youtuber provided: "+youtuber); + if(!channelInfos) return ;//console.log("[ERR] | Invalid youtuber provided: "+youtuber); let video = await checkVideos(channelInfos.raw.snippet.title, "https://www.youtube.com/feeds/videos.xml?channel_id="+channelInfos.id); - if(!video) return console.log(`[${channelInfos.raw.snippet.title}] | No notification`); - let channel = client.channels.get(config.channel); - if(!channel) return console.log("[ERR] | Channel not found"); + if(!video) return;//console.log(`[${channelInfos.raw.snippet.title}] | No notification`); + let channel = client.channels.get(this.dischannel); + if(!channel) return;//console.log("[ERR] | Channel not found"); channel.send( - config.message + this.msg .replace("{videoURL}", video.link) .replace("{videoAuthorName}", video.author) .replace("{videoTitle}", video.title) .replace("{videoPubDate}", formatDate(new Date(video.pubDate))) ); - console.log("Notification sent !"); + console.log("Notification sent!"); lastVideos[channelInfos.raw.snippet.title] = video; }); } - +} } module.exports = list; diff --git a/shrinkwrap.yaml b/shrinkwrap.yaml new file mode 100644 index 0000000..49c0bb6 --- /dev/null +++ b/shrinkwrap.yaml @@ -0,0 +1,57 @@ +dependencies: + rss-parser: 3.8.0 + simple-youtube-api: 5.2.1 +packages: + /entities/1.1.2: + dev: false + resolution: + integrity: sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w== + /iso8601-duration/1.2.0: + dev: false + resolution: + integrity: sha512-ErTBd++b17E8nmWII1K1uZtBgD1E8RjyvwmxlCjPHNqHMD7gmcMHOw0E8Ro/6+QT4PhHRSnnMo7bxa1vFPkwhg== + /node-fetch/2.6.0: + dev: false + engines: + node: 4.x || >=6.0.0 + resolution: + integrity: sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA== + /rss-parser/3.8.0: + dependencies: + entities: 1.1.2 + xml2js: 0.4.23 + dev: false + resolution: + integrity: sha512-EvjM0r3IymXnk+SCUawLhdH36D2WQCwpEfIyvu4hpPswYuMSk/jlCLOcg24OvXwVdcJcEocAlTZVjGNjOOSJXg== + /sax/1.2.4: + dev: false + resolution: + integrity: sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw== + /simple-youtube-api/5.2.1: + dependencies: + iso8601-duration: 1.2.0 + node-fetch: 2.6.0 + dev: false + resolution: + integrity: sha512-vmndP9Bkh35tifn2OwY+th2imSsfYtmDqczgdOW5yEARFzvSoR8VSQFsivJnctfV5QHQUL6VrOpNdbmDRLh9Bg== + /xml2js/0.4.23: + dependencies: + sax: 1.2.4 + xmlbuilder: 11.0.1 + dev: false + engines: + node: '>=4.0.0' + resolution: + integrity: sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug== + /xmlbuilder/11.0.1: + dev: false + engines: + node: '>=4.0' + resolution: + integrity: sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA== +registry: 'https://registry.npmjs.org/' +shrinkwrapMinorVersion: 9 +shrinkwrapVersion: 3 +specifiers: + rss-parser: ^3.7.2 + simple-youtube-api: ^5.2.1