From d28bfdfaf3129d6d07dd1282c5aaf226e6e9d6ae Mon Sep 17 00:00:00 2001 From: Wolowit Date: Tue, 22 Jun 2021 22:14:11 +0700 Subject: [PATCH] still bug [fent/node-ytdl-core#923](https://github.com/fent/node-ytdl-core/issues/923) --- commands/play.js | 74 +++++++++++++++---------------------------- routes/countRoutes.js | 2 +- routes/postRoutes.js | 2 +- routes/queueRoutes.js | 2 +- 4 files changed, 29 insertions(+), 51 deletions(-) diff --git a/commands/play.js b/commands/play.js index 9f5e49f..ef98fd3 100644 --- a/commands/play.js +++ b/commands/play.js @@ -1,4 +1,5 @@ const ytdl = require('ytdl-core') +// const ytdl = require('discord-ytdl-core') const { prefix } = require('../config/config') const Queue = require('../models/queueModels') const Count = require('../models/countModels') @@ -8,12 +9,27 @@ module.exports = { description: 'Play a song in your channel!', async execute(msg, bot_status) { try { + // let stream = ytdl('https://www.youtube.com/watch?v=QnL5P0tFkwM', { + // filter: 'audioonly', + // opusEncoded: false, + // fmt: 'mp3', + // encoderArgs: ['-af', 'bass=g=10,dynaudnorm=f=200'], + // }) + + // msg.member.voice.channel.join().then((connection) => { + // let dispatcher = connection + // .play(stream, { + // type: 'unknown', + // }) + // .on('finish', () => { + // console.log('end') + // msg.guild.me.voice.channel.leave() + // }) + // }) + const args = msg.content.slice(prefix.length).trim().split(/ +/) const queue = msg.client.queue const serverQueue = msg.client.queue.get(msg.guild.id) - // console.log(msg) - // console.log(bot_status) - console.log(args) const voiceChannel = msg.member.voice.channel if (bot_status === 'off') { @@ -26,50 +42,34 @@ module.exports = { return msg.channel.send('I need the permissions to do that dude') } - const songInfo = await ytdl.getInfo(args[1]) + // const songInfo = await ytdl.getInfo(args[1]) const song = { - title: songInfo.videoDetails.title, - url: songInfo.videoDetails.video_url, - // textChannel: msg.channel, - // voiceChannel: voiceChannel, - - //connection: null, - //playing: true, + // title: songInfo.videoDetails.title, + // url: songInfo.videoDetails.video_url, + title: 'test', + url: args[1], count: 1, } - // console.log(serverQueue) // info queueFromDB = await Queue.find().exec() console.log(queueFromDB.length === 0) - // if(!serverQueue) if (queueFromDB.length === 0) { const queueContruct = { //textChannel: msg.channel, //voiceChannel: voiceChannel, connection: null, - //songs: [], - //volume: 5, playing: true, } queue.set(msg.guild.id, queueContruct) - // let songFromDB = await Queue.find().exec() - //queue.set(msg.guild.id, songFromDB) - //queueContruct.songs.push(song) console.log('song is', song) var addSong = await new Queue(song).save() - // addSong.save(async (err) => { - // if (err) return handleError(err) - // }) this.countFunction(song) try { var connection = await voiceChannel.join() queueContruct.connection = connection - // upDateConnection = await Queue.findByIdAndUpdate(addSong._id, { - // connection: true, - // }) songFromDB = await Queue.find().exec() songDB = songFromDB[0] @@ -82,15 +82,8 @@ module.exports = { return msg.channel.send(err) } } else { - //serverQueue.songs.push(song) - - var pushSong = await new Queue(song, {}).save() - // pushSong.save(function (err) { - // if (err) return handleError(err) - // }) - + var pushSong = await new Queue(song).save() this.countFunction(song) - return msg.channel.send(`${song.title} has been added to the queue!`) } } catch (error) { @@ -105,17 +98,14 @@ module.exports = { haveSongYet = findCount.some(async (inCount) => { inCount.title === song.title }) - //console.log('check have song yet = ', haveSongYet) if (!haveSongYet) { var addCountSong = await new Count(song, {}) addCountSong.save(function (err) { if (err) return handleError(err) - //console.log('new song count!!') }) } findCount.map(async (inCount) => { - //console.log('find Count = ', inCount.title === song.title && haveSongYet) if (inCount.title === song.title && haveSongYet) { Count.findByIdAndUpdate( inCount._id, @@ -124,7 +114,6 @@ module.exports = { }, function (err, howmuch) { if (err) return handleError(err) - console.log('count on!!') } ) } @@ -157,30 +146,19 @@ module.exports = { type: 'unknown', }) .on('finish', async () => { + console.log('end') let checkIfData = await Queue.find().exec() console.log(checkIfData.length) if (checkIfData.length !== 0) { let deletedSong = await Queue.findByIdAndDelete(song._id).exec() console.log('deleted', deletedSong) - // if (songFromDBx.length !== 0) { - // let songDBx = songFromDBx[0] - // //console.log('next', songDBx.title) - // //serverQueue.songs.shift() - // this.play(msg, songDBx) - // }else { - // this.play(msg, songDBx) - // } } let songFromDBx = await Queue.find().exec() let songDBx = songFromDBx[0] if (songDBx) { console.log(true) } - //serverQueue.songs.shift() this.play(msg, songDBx) - - //serverQueue.songs.shift() - // this.play(msg, serverQueue.songs[0]) }) }) .catch((e) => { diff --git a/routes/countRoutes.js b/routes/countRoutes.js index 5a8a55a..7c58dc1 100644 --- a/routes/countRoutes.js +++ b/routes/countRoutes.js @@ -12,7 +12,7 @@ router router .route('/:id') .get(countControllers.getOneCount) - .delete(protect, countControllers.deleteOneCount) + .delete(countControllers.deleteOneCount) .patch(countControllers.updateCount) module.exports = router diff --git a/routes/postRoutes.js b/routes/postRoutes.js index 0266474..3053191 100644 --- a/routes/postRoutes.js +++ b/routes/postRoutes.js @@ -13,7 +13,7 @@ router router .route('/:id') .get(postControllers.getOnePost) - .delete(protect, postControllers.deleteOnePost) + .delete(postControllers.deleteOnePost) .patch(postControllers.updatePost) module.exports = router diff --git a/routes/queueRoutes.js b/routes/queueRoutes.js index 307ef34..1d98f08 100644 --- a/routes/queueRoutes.js +++ b/routes/queueRoutes.js @@ -13,7 +13,7 @@ router router .route('/:id') .get(queueControllers.getOneQueue) - .delete(protect, queueControllers.deleteOneQueue) + .delete(queueControllers.deleteOneQueue) .patch(queueControllers.updateQueue) module.exports = router