This SNIPPET IS DECOMISSIONED PLEASE USE: https://autocode.com/app/akanixon/yatb/
// authenticates you with the API standard library
// type `await lib.` to display API autocomplete
const lib = require('lib')({ token: process.env.STDLIB_SECRET_TOKEN });
let debug = false; //turns off kv check
//Enter the streamers names here
let streamers = ['StreamerName'];
let mentionRoleID = "mentionRoleID";
let channelName = "🔊-twitch";
let streamerID = await lib.twitch.users['@0.0.3'].list({
login: streamers,
});
console.log(streamerID.data.length);
for (let i = 0; i < streamerID.data.length; i++) {
console.log(
`${streamerID.data[i].broadcaster_type} ${streamerID.data[i].display_name}`
);
let stream = await lib.twitch.streams['@0.0.0'].list({
user_id: `${streamerID.data[i].id}`,
});
let state = await lib.utils.kv['@0.1.16'].get({
key: `${streamerID.data[i].id}`,
defaultValue: `offline`,
});
try {
console.log(`${streamerID.data[i].display_name}: ${state} ${stream.data[0].type}`);
}catch(e){console.log(`${streamerID.data[i].display_name}: ${state} UNDEFINED`);}
if (!(typeof stream.data[0] === 'undefined') && (state != stream.data[0].type || debug)) {
if (stream.data[0].type == 'live') {
let thumbnail = stream.data[0].thumbnail_url.replace("{height}","1080");
thumbnail = thumbnail.replace("{width}","1920");
//sends going live message - feel free to edit this part as you like
console.log(thumbnail);
await lib.discord.channels['@0.2.0'].messages.create({
channel_name: `${channelName}`,
content: `<@&${mentionRoleID}>`,
tts: false,
allowed_mentions: {
parse: []
},
components: [
{
type: 1,
components: [
{
style: 5,
label: `Watch`,
url: `https://twitch.tv/${streamerID.data[i].display_name}`,
disabled: false,
emoji: {
id: null,
name: `▶`,
},
type: 2,
},
],
},
],
embeds: [
{
type: 'rich',
title: `${streamerID.data[i].display_name} just went live`,
description: `Streaming ${stream.data[0].game_name}: ${stream.data[0].title}`,
color: 0xb300ff,
url: `https://twitch.tv/${streamerID.data[i].display_name}`,
thumbnail: {
url: streamerID.data[i].profile_image_url,
height: 0,
width: 0,
},
image:{
url: thumbnail,
proxy_url: `https://twitch.tv/${streamerID.data[i].display_name}`,
height: 1920,
width: 1080,
}
},
],
});
}
}
try {
await lib.utils.kv['@0.1.16'].set({
key: `${streamerID.data[i].id}`,
value: `${stream.data[0].type}`,
});
} catch (e) {
await lib.utils.kv['@0.1.16'].set({
key: `${streamerID.data[i].id}`,
value: `offline`,
});
}
}
};