Added support for seeking when playing youtube videos.
This commit is contained in:
parent
d4f06c19ff
commit
ea1c62b5b6
6
bot.js
6
bot.js
@ -7,6 +7,8 @@ const fs = require('fs');
|
||||
const ytdl = require('ytdl-core-discord');
|
||||
// Include our local auth key, so that we don't leak keys
|
||||
const auth = require('./auth.json');
|
||||
// Volume for playback (fraction)
|
||||
var volume = 0.6;
|
||||
|
||||
// **** PROGRAM START ****
|
||||
// This program is 2 lines of code, the rest is callback function definition, wherein the bot magic happens
|
||||
@ -151,7 +153,7 @@ client.on('message', async message => {
|
||||
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 = '';
|
||||
var timestamp = '0';
|
||||
if (timematch) {
|
||||
timestamp = timematch[0];
|
||||
}
|
||||
@ -163,7 +165,7 @@ client.on('message', async message => {
|
||||
// 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 });
|
||||
const dispatcher = connection.play(await ytdl(yturl), { type: 'opus', volume: 0.60, begin: timestamp});
|
||||
dispatcher.on('start', () => { console.log(`Playing ${yturl}`); });
|
||||
dispatcher.on('finish', () => { console.log(`Finished ${yturl}`); });
|
||||
dispatcher.on('error', console.error);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user