From 2e726c0365d01503fa2ec2daa85b0a82c50fdd6d Mon Sep 17 00:00:00 2001 From: Dave R Date: Fri, 6 Oct 2017 10:25:57 +0100 Subject: [PATCH 1/3] Important Changes Changes: -sendMessage changed to send as sendMessage is deprecated in the API -Added :x: emoji to errors o.O --- server.js | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/server.js b/server.js index 10ccfac..6b5eebd 100644 --- a/server.js +++ b/server.js @@ -7,39 +7,39 @@ let queue = {}; const commands = { 'play': (msg) => { - if (queue[msg.guild.id] === undefined) return msg.channel.sendMessage(`Add some songs to the queue first with ${tokens.prefix}add`); + if (queue[msg.guild.id] === undefined) return msg.channel.send(':x: Add some songs to the queue first with ${tokens.prefix}add`); if (!msg.guild.voiceConnection) return commands.join(msg).then(() => commands.play(msg)); - if (queue[msg.guild.id].playing) return msg.channel.sendMessage('Already Playing'); + if (queue[msg.guild.id].playing) return msg.channel.send(':x: Already Playing'); let dispatcher; queue[msg.guild.id].playing = true; console.log(queue); (function play(song) { console.log(song); - if (song === undefined) return msg.channel.sendMessage('Queue is empty').then(() => { + if (song === undefined) return msg.channel.send('Queue is empty').then(() => { queue[msg.guild.id].playing = false; msg.member.voiceChannel.leave(); }); - msg.channel.sendMessage(`Playing: **${song.title}** as requested by: **${song.requester}**`); + msg.channel.send(`Playing: **${song.title}** as requested by: **${song.requester}**`); dispatcher = msg.guild.voiceConnection.playStream(yt(song.url, { audioonly: true }), { passes : tokens.passes }); let collector = msg.channel.createCollector(m => m); collector.on('message', m => { if (m.content.startsWith(tokens.prefix + 'pause')) { - msg.channel.sendMessage('paused').then(() => {dispatcher.pause();}); + msg.channel.send('paused').then(() => {dispatcher.pause();}); } else if (m.content.startsWith(tokens.prefix + 'resume')){ - msg.channel.sendMessage('resumed').then(() => {dispatcher.resume();}); + msg.channel.send('resumed').then(() => {dispatcher.resume();}); } else if (m.content.startsWith(tokens.prefix + 'skip')){ - msg.channel.sendMessage('skipped').then(() => {dispatcher.end();}); + msg.channel.send('skipped').then(() => {dispatcher.end();}); } else if (m.content.startsWith('volume+')){ - if (Math.round(dispatcher.volume*50) >= 100) return msg.channel.sendMessage(`Volume: ${Math.round(dispatcher.volume*50)}%`); + if (Math.round(dispatcher.volume*50) >= 100) return msg.channel.send(`Volume: ${Math.round(dispatcher.volume*50)}%`); dispatcher.setVolume(Math.min((dispatcher.volume*50 + (2*(m.content.split('+').length-1)))/50,2)); - msg.channel.sendMessage(`Volume: ${Math.round(dispatcher.volume*50)}%`); + msg.channel.send(`Volume: ${Math.round(dispatcher.volume*50)}%`); } else if (m.content.startsWith('volume-')){ - if (Math.round(dispatcher.volume*50) <= 0) return msg.channel.sendMessage(`Volume: ${Math.round(dispatcher.volume*50)}%`); + if (Math.round(dispatcher.volume*50) <= 0) return msg.channel.send(`Volume: ${Math.round(dispatcher.volume*50)}%`); dispatcher.setVolume(Math.max((dispatcher.volume*50 - (2*(m.content.split('-').length-1)))/50,0)); - msg.channel.sendMessage(`Volume: ${Math.round(dispatcher.volume*50)}%`); + msg.channel.send(`Volume: ${Math.round(dispatcher.volume*50)}%`); } else if (m.content.startsWith(tokens.prefix + 'time')){ - msg.channel.sendMessage(`time: ${Math.floor(dispatcher.time / 60000)}:${Math.floor((dispatcher.time % 60000)/1000) <10 ? '0'+Math.floor((dispatcher.time % 60000)/1000) : Math.floor((dispatcher.time % 60000)/1000)}`); + msg.channel.send(`time: ${Math.floor(dispatcher.time / 60000)}:${Math.floor((dispatcher.time % 60000)/1000) <10 ? '0'+Math.floor((dispatcher.time % 60000)/1000) : Math.floor((dispatcher.time % 60000)/1000)}`); } }); dispatcher.on('end', () => { @@ -47,7 +47,7 @@ const commands = { play(queue[msg.guild.id].songs.shift()); }); dispatcher.on('error', (err) => { - return msg.channel.sendMessage('error: ' + err).then(() => { + return msg.channel.send('error: ' + err).then(() => { collector.stop(); play(queue[msg.guild.id].songs.shift()); }); @@ -57,29 +57,29 @@ const commands = { 'join': (msg) => { return new Promise((resolve, reject) => { const voiceChannel = msg.member.voiceChannel; - if (!voiceChannel || voiceChannel.type !== 'voice') return msg.reply('I couldn\'t connect to your voice channel...'); + if (!voiceChannel || voiceChannel.type !== 'voice') return msg.reply(':x: I couldn\'t connect to your voice channel...'); voiceChannel.join().then(connection => resolve(connection)).catch(err => reject(err)); }); }, 'add': (msg) => { let url = msg.content.split(' ')[1]; - if (url == '' || url === undefined) return msg.channel.sendMessage(`You must add a YouTube video url, or id after ${tokens.prefix}add`); + if (url == '' || url === undefined) return msg.channel.send(`:x: You must add a YouTube video url, or id after ${tokens.prefix}add`); yt.getInfo(url, (err, info) => { - if(err) return msg.channel.sendMessage('Invalid YouTube Link: ' + err); + if(err) return msg.channel.send('Invalid YouTube Link: ' + err); if (!queue.hasOwnProperty(msg.guild.id)) queue[msg.guild.id] = {}, queue[msg.guild.id].playing = false, queue[msg.guild.id].songs = []; queue[msg.guild.id].songs.push({url: url, title: info.title, requester: msg.author.username}); - msg.channel.sendMessage(`added **${info.title}** to the queue`); + msg.channel.send(`added **${info.title}** to the queue`); }); }, 'queue': (msg) => { - if (queue[msg.guild.id] === undefined) return msg.channel.sendMessage(`Add some songs to the queue first with ${tokens.prefix}add`); + if (queue[msg.guild.id] === undefined) return msg.channel.send(`:x: Add some songs to the queue first with ${tokens.prefix}add`); let tosend = []; queue[msg.guild.id].songs.forEach((song, i) => { tosend.push(`${i+1}. ${song.title} - Requested by: ${song.requester}`);}); - msg.channel.sendMessage(`__**${msg.guild.name}'s Music Queue:**__ Currently **${tosend.length}** songs queued ${(tosend.length > 15 ? '*[Only next 15 shown]*' : '')}\n\`\`\`${tosend.slice(0,15).join('\n')}\`\`\``); + msg.channel.send(`__**${msg.guild.name}'s Music Queue:**__ Currently **${tosend.length}** songs queued ${(tosend.length > 15 ? '*[Only next 15 shown]*' : '')}\n\`\`\`${tosend.slice(0,15).join('\n')}\`\`\``); }, 'help': (msg) => { let tosend = ['```xl', tokens.prefix + 'join : "Join Voice channel of msg sender"', tokens.prefix + 'add : "Add a valid youtube link to the queue"', tokens.prefix + 'queue : "Shows the current queue, up to 15 songs shown."', tokens.prefix + 'play : "Play the music queue if already joined to a voice channel"', '', 'the following commands only function while the play command is running:'.toUpperCase(), tokens.prefix + 'pause : "pauses the music"', tokens.prefix + 'resume : "resumes the music"', tokens.prefix + 'skip : "skips the playing song"', tokens.prefix + 'time : "Shows the playtime of the song."', 'volume+(+++) : "increases volume by 2%/+"', 'volume-(---) : "decreases volume by 2%/-"', '```']; - msg.channel.sendMessage(tosend.join('\n')); + msg.channel.send(tosend.join('\n')); }, 'reboot': (msg) => { if (msg.author.id == tokens.adminID) process.exit(); //Requires a node module like Forever to work. @@ -87,7 +87,7 @@ const commands = { }; client.on('ready', () => { - console.log('ready!'); + console.log('Ready!'); }); client.on('message', msg => { From 7ebb6b87fd8c36e71c079a3b1c3b8820f7288d89 Mon Sep 17 00:00:00 2001 From: Dave R <14052956+ohlookitsderpy@users.noreply.github.com> Date: Sat, 10 Mar 2018 22:37:13 +0000 Subject: [PATCH 2/3] updated stuff --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 976e794..f22c8b8 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,9 @@ "start": "node server.js" }, "dependencies": { - "discord.js" : "11.0.0", - "ytdl-core" : "github:fent/node-ytdl-core#master", - "node-opus" : "^0.2.1" + "discord.js" : "11.3.2", + "ytdl-core" : "0.20.2", + "node-opus" : "0.2.7" }, "author": "BDISTIN", "license": "MIT" From 100251df102a88671b0998d8686a344bb7aef7b8 Mon Sep 17 00:00:00 2001 From: Dave R <14052956+ohlookitsderpy@users.noreply.github.com> Date: Tue, 13 Mar 2018 17:21:13 +0000 Subject: [PATCH 3/3] fix also now 90 lines --- server.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/server.js b/server.js index 6b5eebd..98a6453 100644 --- a/server.js +++ b/server.js @@ -2,17 +2,14 @@ const { Client } = require('discord.js'); const yt = require('ytdl-core'); const tokens = require('./tokens.json'); const client = new Client(); - let queue = {}; - const commands = { 'play': (msg) => { - if (queue[msg.guild.id] === undefined) return msg.channel.send(':x: Add some songs to the queue first with ${tokens.prefix}add`); + if (queue[msg.guild.id] === undefined) return msg.channel.send(`:x: Add some songs to the queue first with ${tokens.prefix}add`); if (!msg.guild.voiceConnection) return commands.join(msg).then(() => commands.play(msg)); if (queue[msg.guild.id].playing) return msg.channel.send(':x: Already Playing'); let dispatcher; queue[msg.guild.id].playing = true; - console.log(queue); (function play(song) { console.log(song); @@ -81,14 +78,10 @@ const commands = { let tosend = ['```xl', tokens.prefix + 'join : "Join Voice channel of msg sender"', tokens.prefix + 'add : "Add a valid youtube link to the queue"', tokens.prefix + 'queue : "Shows the current queue, up to 15 songs shown."', tokens.prefix + 'play : "Play the music queue if already joined to a voice channel"', '', 'the following commands only function while the play command is running:'.toUpperCase(), tokens.prefix + 'pause : "pauses the music"', tokens.prefix + 'resume : "resumes the music"', tokens.prefix + 'skip : "skips the playing song"', tokens.prefix + 'time : "Shows the playtime of the song."', 'volume+(+++) : "increases volume by 2%/+"', 'volume-(---) : "decreases volume by 2%/-"', '```']; msg.channel.send(tosend.join('\n')); }, - 'reboot': (msg) => { - if (msg.author.id == tokens.adminID) process.exit(); //Requires a node module like Forever to work. - } + 'reboot': (msg) => { if (msg.author.id == tokens.adminID) process.exit(); } //Requires a node module like Forever to work. }; -client.on('ready', () => { - console.log('Ready!'); -}); +client.on('ready', () => { console.log('Ready!'); }); client.on('message', msg => { if (!msg.content.startsWith(tokens.prefix)) return;