Added regex for future processing of timestamps in youtube videos
This commit is contained in:
parent
4233494649
commit
d4f06c19ff
6
bot.js
6
bot.js
@ -150,6 +150,11 @@ client.on('message', async message => {
|
||||
// Check for youtube play command
|
||||
const ytmatch = message.content.match(/(?<=!play (https?:\/\/)(www\.)?youtu((be\.com\/watch\?v=)|(\.be\/)))[\w-]{11}/);
|
||||
if (ytmatch && message.member.voice.channel) {
|
||||
const timematch = message.content.match(/t=(\d{1,2}h)?(\d{1,2}m)?\d{1,4}s?(?=$)/);
|
||||
var timestamp = '';
|
||||
if (timematch) {
|
||||
timestamp = timematch[0];
|
||||
}
|
||||
console.log(`!play issued for ${ytmatch[0]} by ${message.author.tag} ${message.author.id}`);
|
||||
// Reconstruct a youtu.be url for the supplied video
|
||||
const yturl = `https://youtu.be/${ytmatch[0]}`;
|
||||
@ -157,6 +162,7 @@ client.on('message', async message => {
|
||||
const connection = await message.member.voice.channel.join();
|
||||
// Play the video as requested
|
||||
try {
|
||||
//TODO: process the timestamp with ffmpeg or whatever
|
||||
const dispatcher = connection.play(await ytdl(yturl), { type: 'opus', volume: 0.60 });
|
||||
dispatcher.on('start', () => { console.log(`Playing ${yturl}`); });
|
||||
dispatcher.on('finish', () => { console.log(`Finished ${yturl}`); });
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user