@livecord/notify
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -16,2 +16,2 @@ const { YouTube } = require('../src/index'); | ||
console.log('Youtube uploaded video'); | ||
}) | ||
}); |
@@ -1,1 +0,1 @@ | ||
["yt:video:YvrtiAp5JD0"] | ||
{"videos":["yt:video:YvrtiAp5JD0"],"channels":["UCaZGQt419Ptsdk_lh2mz9lQ"]} |
{ | ||
"name": "@livecord/notify", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Notifier for Youtube and Twitch.", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -64,2 +64,5 @@ # [@livecord/notify](https://npmjs.com/package/@livecord/notify) | ||
youtube.subscribe('UCaZGQt419Ptsdk_lh2mz9lQ'); // Subscribe to a another channel | ||
// For multiple: youtube.subscribe(['UCaZGQt419Ptsdk_lh2mz9lQ', 'UCaZGQt419Ptsdk_lh2mz9lQ']); | ||
youtube.on('ready', (ready) => { | ||
@@ -66,0 +69,0 @@ console.log('Youtube connected at: ', ready); |
@@ -27,14 +27,18 @@ const EventEmitter = require('events'); | ||
this.postedVideos = postedVideos; | ||
this.useDatabase = useDatabase; | ||
global.this = this; | ||
if (useDatabase) { | ||
if (fs.existsSync('./livecord.json')) { | ||
let db = JSON.parse(fs.readFileSync('livecord.json')); | ||
db?.videos?.forEach(video => { | ||
if (!this.postedVideos.includes(video)) this.postedVideos.push(video); | ||
}); | ||
db?.channels?.forEach(channel => { | ||
if (!this.channels.includes(channel)) this.channels.push(channel); | ||
}); | ||
} else { | ||
fs.writeFileSync('livecord.json', JSON.stringify({ videos: [], channels: [] })); | ||
} | ||
} | ||
this.ws.on('open', () => { | ||
if (useDatabase) { | ||
if (fs.existsSync('./livecord.json')) { | ||
JSON.parse(fs.readFileSync('livecord.json')).forEach(video => { | ||
if (!this.postedVideos.includes(video)) this.postedVideos.push(video); | ||
}); | ||
} else { | ||
fs.writeFileSync('livecord.json', JSON.stringify([])); | ||
} | ||
} | ||
this.emit('ready', Date.now()); | ||
@@ -48,6 +52,11 @@ setInterval(() => { | ||
if (postedVideos.includes($.id)) return; | ||
fs.writeFileSync('livecord.json', JSON.stringify([ | ||
...JSON.parse(fs.readFileSync('livecord.json')), | ||
$.id | ||
])); | ||
fs.writeFileSync('livecord.json', JSON.stringify({ | ||
videos: [ | ||
...JSON.parse(fs.readFileSync('livecord.json'))?.videos, | ||
$.id | ||
], | ||
channels: [ | ||
...JSON.parse(fs.readFileSync('livecord.json'))?.channels, | ||
] | ||
})); | ||
this.postedVideos.push($.id); | ||
@@ -72,6 +81,36 @@ return this.emit('upload', $); | ||
if (typeof channel === 'string') { | ||
this.channels.push(channel); | ||
if (this.channels.includes(channel)) return; | ||
if (this.useDatabase) { | ||
fs.writeFileSync('livecord.json', JSON.stringify({ | ||
videos: [ | ||
...JSON.parse(fs.readFileSync('livecord.json'))?.videos, | ||
], | ||
channels: [ | ||
...JSON.parse(fs.readFileSync('livecord.json'))?.channels, | ||
channel | ||
] | ||
})); | ||
this.channels.push(channel); | ||
return this.ws.emit('newChannel', channel); | ||
} else { | ||
this.channels.push(channel); | ||
return this.ws.emit('newChannel', channel); | ||
} | ||
} else if (Array.isArray(channel)) { | ||
channel.forEach(c => { | ||
this.channels.push(c); | ||
if (this.channels.includes(c)) return; | ||
if (this.useDatabase) { | ||
fs.writeFileSync('livecord.json', JSON.stringify({ | ||
videos: [ | ||
...JSON.parse(fs.readFileSync('livecord.json'))?.videos, | ||
], | ||
channels: [ | ||
...JSON.parse(fs.readFileSync('livecord.json'))?.channels, | ||
c | ||
] | ||
})); | ||
return this.channels.push(c); | ||
} else { | ||
return this.channels.push(c); | ||
} | ||
}) | ||
@@ -78,0 +117,0 @@ } else { |
13183
212
77