Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneExile committed Jun 22, 2021
1 parent 6ea288a commit d28bfdf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 51 deletions.
74 changes: 26 additions & 48 deletions commands/play.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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') {
Expand All @@ -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]
Expand All @@ -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) {
Expand All @@ -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,
Expand All @@ -124,7 +114,6 @@ module.exports = {
},
function (err, howmuch) {
if (err) return handleError(err)
console.log('count on!!')
}
)
}
Expand Down Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion routes/countRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ router
router
.route('/:id')
.get(countControllers.getOneCount)
.delete(protect, countControllers.deleteOneCount)
.delete(countControllers.deleteOneCount)
.patch(countControllers.updateCount)

module.exports = router
2 changes: 1 addition & 1 deletion routes/postRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ router
router
.route('/:id')
.get(postControllers.getOnePost)
.delete(protect, postControllers.deleteOnePost)
.delete(postControllers.deleteOnePost)
.patch(postControllers.updatePost)

module.exports = router
2 changes: 1 addition & 1 deletion routes/queueRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ router
router
.route('/:id')
.get(queueControllers.getOneQueue)
.delete(protect, queueControllers.deleteOneQueue)
.delete(queueControllers.deleteOneQueue)
.patch(queueControllers.updateQueue)

module.exports = router

0 comments on commit d28bfdf

Please sign in to comment.