From 0c8d53dd25b55bd7959ed579363370f048799e6c Mon Sep 17 00:00:00 2001 From: Gavin Isgar Date: Fri, 13 Jul 2018 01:13:09 -0400 Subject: [PATCH] Add new '/ratz laststream' command Added new '/ratz laststream' command that gives information of the last stream's VOD. --- commands.json | 6 ++++-- main.js | 35 ++++++++++++++++++++++++++++++++++- package-lock.json | 2 +- package.json | 2 +- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/commands.json b/commands.json index f566be0..2a2d497 100644 --- a/commands.json +++ b/commands.json @@ -9,7 +9,8 @@ "/ratz play + YouTube URL", "/ratz stop", "/ratz btcinfo", - "/ratz ratcoininfo + Twitch Username" + "/ratz ratcoininfo + Twitch Username", + "/ratz laststream" ], "definitions": [ "Shows all commands for ratzBot", @@ -21,6 +22,7 @@ "Plays YouTube video audio", "Stops YouTube video audio", "Shows information about Bitcoin", - "Shows the amount of RTC a user has on Twitch" + "Shows the amount of RTC a user has on Twitch", + "Shows last stream VOD and VOD information" ] } \ No newline at end of file diff --git a/main.js b/main.js index 85bce95..d89fec4 100644 --- a/main.js +++ b/main.js @@ -202,7 +202,7 @@ bot.on('message', (message) => { } }) } - // -----STREAMLABS INTEGRATION + // -----STREAMLABS INTEGRATION----- if (message.content.startsWith("/ratz ratcoininfo ")) { var result = message.content.slice(18); var getRTCInfo = { @@ -224,6 +224,39 @@ bot.on('message', (message) => { } }) } + // -----TWITCH NEW API----- + if (message.content.toString() == "/ratz laststream") { + var getStreamVOD = { + method: 'GET', + url: `https://api.twitch.tv/helix/videos?user_id=157901049&first=1`, + headers: { + "Client-ID": `${tokens.twitchapiclientid}` + } + } + request(getStreamVOD, (error, response, body) => { + try { + if (!error & response.statusCode == 200) { + var stats = JSON.parse(body); + const embed = new Discord.RichEmbed() + .setTitle("Last Stream VOD from ratzDoll") + .setThumbnail(bot.user.avatarURL) + .setColor(0xcb00ff) + .setURL(stats.data[0].url) + .addField("Title", "" + stats.data[0].title) + .addField("Published At", "" + stats.data[0].published_at) + .addField("Duration", "" + stats.data[0].duration) + .addField("View Count", stats.data[0].view_count) + message.channel.send(embed); + } + else { + message.channel.send(`${message.author}, an error occured during the process. Try again later.`); + } + } + catch (err) { + message.channel.send(`${message.author}, an error occured during the process. Try again later.`); + } + }) + } // -----VOICE CHANNELS----- if (message.content.startsWith("/ratz play ")) { var result = message.content.slice(11); diff --git a/package-lock.json b/package-lock.json index aadc6f1..bc235f6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ratzbot", - "version": "2.5.0", + "version": "2.5.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index b2c4deb..40b5828 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ratzbot", - "version": "2.5.0", + "version": "2.5.1", "description": "Discord bot for Twitch streamer ratzDoll", "main": "main.js", "scripts": {