summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author8cy <[email protected]>2020-04-11 06:22:53 -0700
committer8cy <[email protected]>2020-04-11 06:22:53 -0700
commita80abc36f8a610cc97bd99479a6bbf55782be579 (patch)
tree3ff59dab029435584bc25b8f48978528c955f746
parentreworks, v2.0.5 (diff)
downloads5nical-a80abc36f8a610cc97bd99479a6bbf55782be579.tar.xz
s5nical-a80abc36f8a610cc97bd99479a6bbf55782be579.zip
big portage, v2.1.0
- remove some commenting in app.js - add gay, respect, btc, btcchange - port itemshop, psycho and abee to new play system - bolden important things in message responses
-rw-r--r--app.js4
-rw-r--r--commands/fun/gay.js21
-rw-r--r--commands/fun/respect.js19
-rw-r--r--commands/utility/btc.js28
-rw-r--r--commands/utility/btcchange.js39
-rw-r--r--commands/voice/abee.js194
-rw-r--r--commands/voice/itemshop.js211
-rw-r--r--commands/voice/play.js6
-rw-r--r--commands/voice/psycho.js193
-rw-r--r--commands/voice/volume.js2
-rw-r--r--package.json2
11 files changed, 662 insertions, 57 deletions
diff --git a/app.js b/app.js
index 2b44ed8..c3990c4 100644
--- a/app.js
+++ b/app.js
@@ -47,18 +47,16 @@ client.once('ready', () => {
client.on('error', console.error);
client.on('message', async msg => {
- // When someone uses a command, it console.log's it
+ var msgContent = msg.content.toLowerCase();
function prefixCheck() {
if (msgContent.startsWith('s5n!')) {
return true;
}
}
- var msgContent = msg.content.toLowerCase();
if (prefixCheck()) {
console.log(msg.member.user.tag, 'says', msgContent, 'in #' + msg.channel.name);
}
- // Reacts with ping emoji when @everyone
if (msg.mentions.everyone) {
msg.react(':ArisaPing:695887537390223402');
}
diff --git a/commands/fun/gay.js b/commands/fun/gay.js
new file mode 100644
index 0000000..7d1b65a
--- /dev/null
+++ b/commands/fun/gay.js
@@ -0,0 +1,21 @@
+const { Command } = require('discord.js-commando');
+
+module.exports = class GayFun extends Command {
+ constructor(client) {
+ super(client, {
+ name: 'gay',
+ aliases: ['gayamount', 'gayrange', 'gayrate'],
+ group: 'fun',
+ memberName: 'gay',
+ description: 'tells you your gay-ness amount',
+ });
+ }
+ var gayAmount = Math.floor((Math.random() * 100) + 1);
+ var gayAmountDecimal = Math.floor((Math.random() * 100) + 1);
+
+ msg.reply('scanning..').then(scanningMsg => {
+ scanningMsg.delete()
+ msg.reply('your gay-ness amount is **' + gayAmount + '.' + gayAmountDecimal + '%**');
+ });
+ }
+}; \ No newline at end of file
diff --git a/commands/fun/respect.js b/commands/fun/respect.js
new file mode 100644
index 0000000..75d9707
--- /dev/null
+++ b/commands/fun/respect.js
@@ -0,0 +1,19 @@
+const { Command } = require('discord.js-commando');
+
+module.exports = class RespectFun extends Command {
+ constructor(client) {
+ super(client, {
+ name: 'respect',
+ aliases: ['f'],
+ group: 'fun',
+ memberName: 'respect',
+ description: 'press f to pay respects',
+ });
+ }
+ run(msg) {
+ msg.channel.send('press f to pay respects').then(m => {
+ m.react('🇫');
+ msg.delete();
+ });
+ }
+}; \ No newline at end of file
diff --git a/commands/utility/btc.js b/commands/utility/btc.js
new file mode 100644
index 0000000..caf4e22
--- /dev/null
+++ b/commands/utility/btc.js
@@ -0,0 +1,28 @@
+const { Command } = require('discord.js-commando');
+const btc = require('btc-value');
+btc.setApiKey('a43419ce-fc59-4951-8af9-20c5e36ef73f');
+
+module.exports = class BTCUtility extends Command {
+ constructor(client) {
+ super(client, {
+ name: 'btc',
+ aliases: ['bitcoin', 'crypto'],
+ group: 'utility',
+ memberName: 'btc',
+ description: 'always you to check current bitcoin prices',
+ args: [
+ {
+ key: 'currencyName',
+ prompt: 'what currency u wanna see it in? (usd, aud, cad)',
+ type: 'string'
+ }
+ ]
+ });
+ }
+ run(msg, { currencyName }) {
+ currencyName = currencyName.toUpperCase();
+ btc({ isDecimal: true, currencyCode: currencyName }).then(value => {
+ msg.reply('the current *bitcoin* price in **' + currencyName + '** is **' + value + '**');
+ });
+ }
+}; \ No newline at end of file
diff --git a/commands/utility/btcchange.js b/commands/utility/btcchange.js
new file mode 100644
index 0000000..3abcf7b
--- /dev/null
+++ b/commands/utility/btcchange.js
@@ -0,0 +1,39 @@
+const { Command } = require('discord.js-commando');
+const btc = require('btc-value');
+btc.setApiKey('a43419ce-fc59-4951-8af9-20c5e36ef73f');
+
+module.exports = class BTCChangeUtility extends Command {
+ constructor(client) {
+ super(client, {
+ name: 'btcchange',
+ aliases: ['bitcoinchange', 'cryptochange', 'btcc'],
+ group: 'utility',
+ memberName: 'btcchange',
+ description: 'always you to check the fluctuation in bitcoin prices in a specified amount of time',
+ args: [
+ {
+ key: 'timeAmount',
+ prompt: 'what time range do you want to check the fluction amount in? (day, hour, week)',
+ type: 'string'
+ }
+ ]
+ });
+ }
+ run(msg, { timeAmount }) {
+ if (timeAmount == 'day') {
+ btc.getPercentageChangeLastDay().then(percentage => {
+ msg.reply('the fluction amount of *bitcoin* in the last **' + timeAmount + '** is **' + percentage + '%**');
+ });
+ } else if (timeAmount == 'hour') {
+ btc.getPercentageChangeLastHour().then(percentage => {
+ msg.reply('the fluction amount of *bitcoin* in the last **' + timeAmount + '** is **' + percentage + '%**');
+ });
+ } else if (timeAmount == 'week') {
+ btc.getPercentageChangeLastWeek().then(percentage => {
+ msg.reply('the fluction amount of *bitcoin* in the last **' + timeAmount + '** is **' + percentage + '%**');
+ });
+ } else {
+ msg.reply('*' + timeAmount + '* is not a valid range lol');
+ }
+ }
+}; \ No newline at end of file
diff --git a/commands/voice/abee.js b/commands/voice/abee.js
index 80f9df9..014ba74 100644
--- a/commands/voice/abee.js
+++ b/commands/voice/abee.js
@@ -1,5 +1,10 @@
const ytdl = require('ytdl-core');
const { Command } = require('discord.js-commando');
+const { MessageEmbed } = require('discord.js');
+const Youtube = require('simple-youtube-api');
+const { youtubeAPI } = require('../../config.json');
+const youtube = new Youtube('AIzaSyB9xJENORzZt-GmOGx4WsNCPgKSIxhJcds');
+const emoji = require('emoji-random');
module.exports = class ABeeVoice extends Command {
constructor(client) {
@@ -9,24 +14,183 @@ module.exports = class ABeeVoice extends Command {
group: 'voice',
memberName: 'abee',
description: 'a bee :D 🐝',
- guildOnly: true
+ guildOnly: true,
+ clientPermissions: ['SPEAK', 'CONNECT'],
});
}
- async run(msg) {
- if (msg.member.voice.channel && !msg.guild.voice) {
- const connection = await msg.member.voice.channel.join();
- const stream = ytdl('https://www.youtube.com/watch?v=lvdnhWhQBdo', {
- filter: 'audioonly'
- });
- const dispatcher = connection.play(stream);
+ async run(msg, { query }) {
+ const voiceChannel = msg.member.voice.channel;
+ if (!voiceChannel) return msg.say('join a channel and try again');
- dispatcher.on('finish', () => {
- connection.disconnect();
- });
- } else if (msg.guild.voice) {
- msg.reply('i\'m already playing that lol');
- } else {
- msg.reply('you need to join a voice channel first silly');
+ const id = 'lvdnhWhQBdo';
+ const video = await youtube.getVideoByID(id).catch(function () {
+ return msg.say(
+ 'there was a problem getting the video you provided'
+ );
+ });
+ // // can be uncommented if you don't want the bot to play live streams
+ // if (video.raw.snippet.liveBroadcastContent === 'live') {
+ // return msg.say("I don't support live streams!");
+ // }
+ // // can be uncommented if you don't want the bot to play videos longer than 1 hour
+ // if (video.duration.hours !== 0) {
+ // return msg.say('I cannot play videos longer than 1 hour');
+ // }
+ // // can be uncommented if you want to limit the queue
+ // if (msg.guild.musicData.queue.length > 10) {
+ // return msg.say(
+ // 'There are too many songs in the queue already, skip or wait a bit'
+ // );
+ // }
+ msg.guild.musicData.queue.push(
+ this.constructSongObj(video, voiceChannel)
+ );
+ if (
+ msg.guild.musicData.isPlaying == false ||
+ typeof msg.guild.musicData.isPlaying == 'undefined'
+ ) {
+ msg.guild.musicData.isPlaying = true;
+ return this.playSong(msg.guild.musicData.queue, msg);
+ } else if (msg.guild.musicData.isPlaying == true) {
+ return msg.say(`${video.title} added to queue`);
}
+
+ var that = this;
+ msg.channel
+ .awaitMessages(
+ function (msg) {
+ return (msg.content > 0 && msg.content < 6) || msg.content === 'exit';
+ }, {
+ max: 1,
+ time: 60000,
+ errors: ['time']
+ }
+ )
+ .then(function (response) {
+ const videoIndex = parseInt(response.first().content);
+ if (response.first().content === 'exit') return songEmbed.delete();
+ youtube
+ .getVideoByID(videos[videoIndex - 1].id)
+ .then(function (video) {
+ // // can be uncommented if you don't want the bot to play live streams
+ // if (video.raw.snippet.liveBroadcastContent === 'live') {
+ // songEmbed.delete();
+ // return msg.say("I don't support live streams!");
+ // }
+
+ // // can be uncommented if you don't want the bot to play videos longer than 1 hour
+ // if (video.duration.hours !== 0) {
+ // songEmbed.delete();
+ // return msg.say('I cannot play videos longer than 1 hour');
+ // }
+
+ // // can be uncommented if you don't want to limit the queue
+ // if (msg.guild.musicData.queue.length > 10) {
+ // songEmbed.delete();
+ // return msg.say(
+ // 'There are too many songs in the queue already, skip or wait a bit'
+ // );
+ // }
+ msg.guild.musicData.queue.push(
+ that.constructSongObj(video, voiceChannel)
+ );
+ if (msg.guild.musicData.isPlaying == false) {
+ msg.guild.musicData.isPlaying = true;
+ if (songEmbed) {
+ songEmbed.delete();
+ }
+ that.playSong(msg.guild.musicData.queue, msg);
+ } else if (msg.guild.musicData.isPlaying == true) {
+ if (songEmbed) {
+ songEmbed.delete();
+ }
+ return msg.say(`${video.title} added to queue`);
+ }
+ })
+ .catch(function () {
+ if (songEmbed) {
+ songEmbed.delete();
+ }
+ return msg.say(
+ 'an error has occured when trying to get the video id from youtube'
+ );
+ });
+ });
+ }
+ playSong(queue, msg) {
+ const classThis = this; // use classThis instead of 'this' because of lexical scope below
+ queue[0].voiceChannel
+ .join()
+ .then(function (connection) {
+ const dispatcher = connection
+ .play(
+ ytdl(queue[0].url, {
+ quality: 'highestaudio',
+ highWaterMark: 1024 * 1024 * 10
+ })
+ )
+ .on('start', function () {
+ msg.guild.musicData.songDispatcher = dispatcher;
+ const volume = 10 / 100;
+ msg.guild.musicData.volume = volume;
+ dispatcher.setVolume(msg.guild.musicData.volume);
+ const videoEmbed = new MessageEmbed()
+ .setThumbnail(queue[0].thumbnail)
+ .setColor(0xF97DAE)
+ .addField('now playing:', queue[0].title)
+ .addField('duration:', queue[0].duration);
+ if (queue[1]) videoEmbed.addField('next song:', queue[1].title);
+ msg.say(videoEmbed);
+ msg.guild.musicData.nowPlaying = queue[0];
+ return queue.shift();
+ })
+ .on('finish', function () {
+ if (queue.length >= 1) {
+ return classThis.playSong(queue, msg);
+ } else {
+ msg.guild.musicData.isPlaying = false;
+ msg.guild.musicData.nowPlaying = null;
+ msg.guild.musicData.songDispatcher = null;
+ return msg.guild.me.voice.channel.leave();
+ }
+ })
+ .on('error', function (e) {
+ msg.say('can\'t play song');
+ console.error(e);
+ msg.guild.musicData.queue.length = 0;
+ msg.guild.musicData.isPlaying = false;
+ msg.guild.musicData.nowPlaying = null;
+ msg.guild.musicData.songDispatcher = null;
+ return msg.guild.me.voice.channel.leave();
+ });
+ })
+ .catch(function (e) {
+ console.error(e);
+ return msg.guild.me.voice.channel.leave();
+ });
+ }
+ constructSongObj(video, voiceChannel) {
+ let duration = this.formatDuration(video.duration);
+ if (duration == '00:00') duration = 'live stream';
+ return {
+ url: `https://www.youtube.com/watch?v=${video.raw.id}`,
+ title: video.title,
+ duration,
+ thumbnail: video.thumbnails.high.url,
+ voiceChannel
+ };
+ }
+ // prettier-ignore
+ formatDuration(durationObj) {
+ const duration = `${durationObj.hours ? (durationObj.hours + ':') : ''}${
+ durationObj.minutes ? durationObj.minutes : '00'
+ }:${
+ (durationObj.seconds < 10)
+ ? ('0' + durationObj.seconds)
+ : (durationObj.seconds
+ ? durationObj.seconds
+ : '00')
+ }`;
+ return duration;
}
}; \ No newline at end of file
diff --git a/commands/voice/itemshop.js b/commands/voice/itemshop.js
index 1466758..874bf7c 100644
--- a/commands/voice/itemshop.js
+++ b/commands/voice/itemshop.js
@@ -1,8 +1,12 @@
const ytdl = require('ytdl-core');
const { Command } = require('discord.js-commando');
+const { MessageEmbed } = require('discord.js');
+const Youtube = require('simple-youtube-api');
+const { youtubeAPI } = require('../../config.json');
+const youtube = new Youtube('AIzaSyB9xJENORzZt-GmOGx4WsNCPgKSIxhJcds');
const emoji = require('emoji-random');
-module.exports = class ItemShopVoice extends Command {
+module.exports = class ABeeVoice extends Command {
constructor(client) {
super(client, {
name: 'itemshop',
@@ -10,28 +14,197 @@ module.exports = class ItemShopVoice extends Command {
group: 'voice',
memberName: 'itemshop',
description: 'use code frozen in the itemshop',
- guildOnly: true
+ guildOnly: true,
+ clientPermissions: ['SPEAK', 'CONNECT'],
});
}
- async run(msg) {
- if (msg.member.voice.channel && !msg.guild.voice) {
- const connection = await msg.member.voice.channel.join();
- const stream = ytdl('https://www.youtube.com/watch?v=pBiI1hTwU7E', {
- filter: 'audioonly'
- });
- const dispatcher = connection.play(stream);
+ async run(msg, { query }) {
+ const voiceChannel = msg.member.voice.channel;
+ if (!voiceChannel) return msg.say('join a channel and try again');
+
+ const id = 'pBiI1hTwU7E';
+ const video = await youtube.getVideoByID(id).catch(function () {
+ return msg.say(
+ 'there was a problem getting the video you provided'
+ );
+ });
+ // // can be uncommented if you don't want the bot to play live streams
+ // if (video.raw.snippet.liveBroadcastContent === 'live') {
+ // return msg.say("I don't support live streams!");
+ // }
+ // // can be uncommented if you don't want the bot to play videos longer than 1 hour
+ // if (video.duration.hours !== 0) {
+ // return msg.say('I cannot play videos longer than 1 hour');
+ // }
+ // // can be uncommented if you want to limit the queue
+ // if (msg.guild.musicData.queue.length > 10) {
+ // return msg.say(
+ // 'There are too many songs in the queue already, skip or wait a bit'
+ // );
+ // }
+ msg.guild.musicData.queue.push(
+ this.constructSongObj(video, voiceChannel)
+ );
+ if (
+ msg.guild.musicData.isPlaying == false ||
+ typeof msg.guild.musicData.isPlaying == 'undefined'
+ ) {
+ msg.guild.musicData.isPlaying = true;
+ return this.playSong(msg.guild.musicData.queue, msg);
+ } else if (msg.guild.musicData.isPlaying == true) {
msg.reply('USE CODE FROZEN IN THE FORTNITE ITEM SHOP!!! ' + emoji.random());
+ msg.say(`${video.title} added to queue`);
+ return;
+ }
- function timeCheck() {
- if (dispatcher.streamTime >= 6000) {
- connection.disconnect();
+ var that = this;
+ msg.channel
+ .awaitMessages(
+ function (msg) {
+ return (msg.content > 0 && msg.content < 6) || msg.content === 'exit';
+ }, {
+ max: 1,
+ time: 60000,
+ errors: ['time']
}
- }
- setInterval(timeCheck, 500);
- } else if (msg.guild.voice) {
- msg.reply('i\'m already playing that lol');
- } else {
- msg.reply('you need to join a voice channel first silly');
- }
+ )
+ .then(function (response) {
+ const videoIndex = parseInt(response.first().content);
+ if (response.first().content === 'exit') return songEmbed.delete();
+ youtube
+ .getVideoByID(videos[videoIndex - 1].id)
+ .then(function (video) {
+ // // can be uncommented if you don't want the bot to play live streams
+ // if (video.raw.snippet.liveBroadcastContent === 'live') {
+ // songEmbed.delete();
+ // return msg.say("I don't support live streams!");
+ // }
+
+ // // can be uncommented if you don't want the bot to play videos longer than 1 hour
+ // if (video.duration.hours !== 0) {
+ // songEmbed.delete();
+ // return msg.say('I cannot play videos longer than 1 hour');
+ // }
+
+ // // can be uncommented if you don't want to limit the queue
+ // if (msg.guild.musicData.queue.length > 10) {
+ // songEmbed.delete();
+ // return msg.say(
+ // 'There are too many songs in the queue already, skip or wait a bit'
+ // );
+ // }
+ msg.guild.musicData.queue.push(
+ that.constructSongObj(video, voiceChannel)
+ );
+ if (msg.guild.musicData.isPlaying == false) {
+ msg.guild.musicData.isPlaying = true;
+ if (songEmbed) {
+ songEmbed.delete();
+ }
+ that.playSong(msg.guild.musicData.queue, msg);
+ } else if (msg.guild.musicData.isPlaying == true) {
+ if (songEmbed) {
+ songEmbed.delete();
+ }
+ msg.reply('USE CODE FROZEN IN THE FORTNITE ITEM SHOP!!! ' + emoji.random());
+ msg.say(`${video.title} added to queue`);
+ return;
+ }
+ })
+ .catch(function () {
+ if (songEmbed) {
+ songEmbed.delete();
+ }
+ return msg.say(
+ 'an error has occured when trying to get the video id from youtube'
+ );
+ });
+ });
+ }
+ playSong(queue, msg) {
+ const classThis = this; // use classThis instead of 'this' because of lexical scope below
+ queue[0].voiceChannel
+ .join()
+ .then(function (connection) {
+ const dispatcher = connection
+ .play(
+ ytdl(queue[0].url, {
+ quality: 'highestaudio',
+ highWaterMark: 1024 * 1024 * 10
+ })
+
+ )
+ .on('start', function () {
+ msg.guild.musicData.songDispatcher = dispatcher;
+ const volume = 10 / 100;
+ msg.guild.musicData.volume = volume;
+ dispatcher.setVolume(msg.guild.musicData.volume);
+ const videoEmbed = new MessageEmbed()
+ .setThumbnail(queue[0].thumbnail)
+ .setColor(0xF97DAE)
+ .addField('now playing:', queue[0].title)
+ .addField('duration:', queue[0].duration);
+ if (queue[1]) videoEmbed.addField('next song:', queue[1].title);
+ msg.say(videoEmbed);
+ msg.reply('USE CODE FROZEN IN THE FORTNITE ITEM SHOP!!! ' + emoji.random());
+ msg.guild.musicData.nowPlaying = queue[0];
+ return queue.shift();
+ })
+ .on('finish', function () {
+ if (queue.length >= 1) {
+ return classThis.playSong(queue, msg);
+ } else {
+ msg.guild.musicData.isPlaying = false;
+ msg.guild.musicData.nowPlaying = null;
+ msg.guild.musicData.songDispatcher = null;
+ return msg.guild.me.voice.channel.leave();
+ }
+ })
+ .on('error', function (e) {
+ msg.say('can\'t play song');
+ console.error(e);
+ msg.guild.musicData.queue.length = 0;
+ msg.guild.musicData.isPlaying = false;
+ msg.guild.musicData.nowPlaying = null;
+ msg.guild.musicData.songDispatcher = null;
+ return msg.guild.me.voice.channel.leave();
+ });
+ function timeCheck() {
+ if (dispatcher.streamTime >= 6000) {
+ msg.guild.musicData.isPlaying = false;
+ msg.guild.musicData.nowPlaying = null;
+ msg.guild.musicData.songDispatcher = null;
+ }
+ }
+ setInterval(timeCheck, 500);
+ })
+ .catch(function (e) {
+ console.error(e);
+ return msg.guild.me.voice.channel.leave();
+ });
+ }
+ constructSongObj(video, voiceChannel) {
+ let duration = this.formatDuration(video.duration);
+ if (duration == '00:00') duration = 'live stream';
+ return {
+ url: `https://www.youtube.com/watch?v=${video.raw.id}`,
+ title: video.title,
+ duration,
+ thumbnail: video.thumbnails.high.url,
+ voiceChannel
+ };
+ }
+ // prettier-ignore
+ formatDuration(durationObj) {
+ const duration = `${durationObj.hours ? (durationObj.hours + ':') : ''}${
+ durationObj.minutes ? durationObj.minutes : '00'
+ }:${
+ (durationObj.seconds < 10)
+ ? ('0' + durationObj.seconds)
+ : (durationObj.seconds
+ ? durationObj.seconds
+ : '00')
+ }`;
+ return duration;
}
}; \ No newline at end of file
diff --git a/commands/voice/play.js b/commands/voice/play.js
index 8cbd9cd..28fbae8 100644
--- a/commands/voice/play.js
+++ b/commands/voice/play.js
@@ -3,7 +3,7 @@ const { Command } = require('discord.js-commando');
const { MessageEmbed } = require('discord.js');
const Youtube = require('simple-youtube-api');
const { youtubeAPI } = require('../../config.json');
-const youtube = new Youtube('AIzaSyB9xJENORzZt-GmOGx4WsNCPgKSIxhJcds'); // AIzaSyB9xJENORzZt-GmOGx4WsNCPgKSIxhJcds
+const youtube = new Youtube('AIzaSyB9xJENORzZt-GmOGx4WsNCPgKSIxhJcds');
const emoji = require('emoji-random');
module.exports = class PlayVoice extends Command {
@@ -28,9 +28,7 @@ module.exports = class PlayVoice extends Command {
]
});
}
- async run(msg, {
- query
- }) {
+ async run(msg, { query }) {
const voiceChannel = msg.member.voice.channel;
if (!voiceChannel) return msg.say('join a channel and try again');
diff --git a/commands/voice/psycho.js b/commands/voice/psycho.js
index 9e84be0..905a7b7 100644
--- a/commands/voice/psycho.js
+++ b/commands/voice/psycho.js
@@ -1,5 +1,9 @@
const ytdl = require('ytdl-core');
const { Command } = require('discord.js-commando');
+const { MessageEmbed } = require('discord.js');
+const Youtube = require('simple-youtube-api');
+const { youtubeAPI } = require('../../config.json');
+const youtube = new Youtube('AIzaSyB9xJENORzZt-GmOGx4WsNCPgKSIxhJcds');
const emoji = require('emoji-random');
module.exports = class PsychoVoice extends Command {
@@ -9,24 +13,183 @@ module.exports = class PsychoVoice extends Command {
group: 'voice',
memberName: 'psycho',
description: 'plays the psycho by mase',
- guildOnly: true
+ guildOnly: true,
+ clientPermissions: ['SPEAK', 'CONNECT'],
});
}
- async run(msg) {
- if (msg.member.voice.channel && !msg.guild.voice) {
- const connection = await msg.member.voice.channel.join();
- const stream = ytdl('https://www.youtube.com/watch?v=fnd_HSmAODs', {
- filter: 'audioonly'
- });
- const dispatcher = connection.play(stream);
+ async run(msg, { query }) {
+ const voiceChannel = msg.member.voice.channel;
+ if (!voiceChannel) return msg.say('join a channel and try again');
- dispatcher.on('finish', () => {
- connection.disconnect();
- });
- } else if (msg.guild.voice) {
- msg.reply('i\'m already playing that lol');
- } else {
- msg.reply('you need to join a voice channel first silly');
+ const id = 'fnd_HSmAODs';
+ const video = await youtube.getVideoByID(id).catch(function () {
+ return msg.say(
+ 'there was a problem getting the video you provided'
+ );
+ });
+ // // can be uncommented if you don't want the bot to play live streams
+ // if (video.raw.snippet.liveBroadcastContent === 'live') {
+ // return msg.say("I don't support live streams!");
+ // }
+ // // can be uncommented if you don't want the bot to play videos longer than 1 hour
+ // if (video.duration.hours !== 0) {
+ // return msg.say('I cannot play videos longer than 1 hour');
+ // }
+ // // can be uncommented if you want to limit the queue
+ // if (msg.guild.musicData.queue.length > 10) {
+ // return msg.say(
+ // 'There are too many songs in the queue already, skip or wait a bit'
+ // );
+ // }
+ msg.guild.musicData.queue.push(
+ this.constructSongObj(video, voiceChannel)
+ );
+ if (
+ msg.guild.musicData.isPlaying == false ||
+ typeof msg.guild.musicData.isPlaying == 'undefined'
+ ) {
+ msg.guild.musicData.isPlaying = true;
+ return this.playSong(msg.guild.musicData.queue, msg);
+ } else if (msg.guild.musicData.isPlaying == true) {
+ return msg.say(`${video.title} added to queue`);
}
+
+ var that = this;
+ msg.channel
+ .awaitMessages(
+ function (msg) {
+ return (msg.content > 0 && msg.content < 6) || msg.content === 'exit';
+ }, {
+ max: 1,
+ time: 60000,
+ errors: ['time']
+ }
+ )
+ .then(function (response) {
+ const videoIndex = parseInt(response.first().content);
+ if (response.first().content === 'exit') return songEmbed.delete();
+ youtube
+ .getVideoByID(videos[videoIndex - 1].id)
+ .then(function (video) {
+ // // can be uncommented if you don't want the bot to play live streams
+ // if (video.raw.snippet.liveBroadcastContent === 'live') {
+ // songEmbed.delete();
+ // return msg.say("I don't support live streams!");
+ // }
+
+ // // can be uncommented if you don't want the bot to play videos longer than 1 hour
+ // if (video.duration.hours !== 0) {
+ // songEmbed.delete();
+ // return msg.say('I cannot play videos longer than 1 hour');
+ // }
+
+ // // can be uncommented if you don't want to limit the queue
+ // if (msg.guild.musicData.queue.length > 10) {
+ // songEmbed.delete();
+ // return msg.say(
+ // 'There are too many songs in the queue already, skip or wait a bit'
+ // );
+ // }
+ msg.guild.musicData.queue.push(
+ that.constructSongObj(video, voiceChannel)
+ );
+ if (msg.guild.musicData.isPlaying == false) {
+ msg.guild.musicData.isPlaying = true;
+ if (songEmbed) {
+ songEmbed.delete();
+ }
+ that.playSong(msg.guild.musicData.queue, msg);
+ } else if (msg.guild.musicData.isPlaying == true) {
+ if (songEmbed) {
+ songEmbed.delete();
+ }
+ return msg.say(`${video.title} added to queue`);
+ }
+ })
+ .catch(function () {
+ if (songEmbed) {
+ songEmbed.delete();
+ }
+ return msg.say(
+ 'an error has occured when trying to get the video id from youtube'
+ );
+ });
+ });
+ }
+ playSong(queue, msg) {
+ const classThis = this; // use classThis instead of 'this' because of lexical scope below
+ queue[0].voiceChannel
+ .join()
+ .then(function (connection) {
+ const dispatcher = connection
+ .play(
+ ytdl(queue[0].url, {
+ quality: 'highestaudio',
+ highWaterMark: 1024 * 1024 * 10
+ })
+ )
+ .on('start', function () {
+ msg.guild.musicData.songDispatcher = dispatcher;
+ const volume = 10 / 100;
+ msg.guild.musicData.volume = volume;
+ dispatcher.setVolume(msg.guild.musicData.volume);
+ const videoEmbed = new MessageEmbed()
+ .setThumbnail(queue[0].thumbnail)
+ .setColor(0xF97DAE)
+ .addField('now playing:', queue[0].title)
+ .addField('duration:', queue[0].duration);
+ if (queue[1]) videoEmbed.addField('next song:', queue[1].title);
+ msg.say(videoEmbed);
+ msg.guild.musicData.nowPlaying = queue[0];
+ return queue.shift();
+ })
+ .on('finish', function () {
+ if (queue.length >= 1) {
+ return classThis.playSong(queue, msg);
+ } else {
+ msg.guild.musicData.isPlaying = false;
+ msg.guild.musicData.nowPlaying = null;
+ msg.guild.musicData.songDispatcher = null;
+ return msg.guild.me.voice.channel.leave();
+ }
+ })
+ .on('error', function (e) {
+ msg.say('can\'t play song');
+ console.error(e);
+ msg.guild.musicData.queue.length = 0;
+ msg.guild.musicData.isPlaying = false;
+ msg.guild.musicData.nowPlaying = null;
+ msg.guild.musicData.songDispatcher = null;
+ return msg.guild.me.voice.channel.leave();
+ });
+ })
+ .catch(function (e) {
+ console.error(e);
+ return msg.guild.me.voice.channel.leave();
+ });
+ }
+ constructSongObj(video, voiceChannel) {
+ let duration = this.formatDuration(video.duration);
+ if (duration == '00:00') duration = 'live stream';
+ return {
+ url: `https://www.youtube.com/watch?v=${video.raw.id}`,
+ title: video.title,
+ duration,
+ thumbnail: video.thumbnails.high.url,
+ voiceChannel
+ };
+ }
+ // prettier-ignore
+ formatDuration(durationObj) {
+ const duration = `${durationObj.hours ? (durationObj.hours + ':') : ''}${
+ durationObj.minutes ? durationObj.minutes : '00'
+ }:${
+ (durationObj.seconds < 10)
+ ? ('0' + durationObj.seconds)
+ : (durationObj.seconds
+ ? durationObj.seconds
+ : '00')
+ }`;
+ return duration;
}
}; \ No newline at end of file
diff --git a/commands/voice/volume.js b/commands/voice/volume.js
index 3a6f8bf..bebcf61 100644
--- a/commands/voice/volume.js
+++ b/commands/voice/volume.js
@@ -34,6 +34,6 @@ module.exports = class VolumeVoice extends Command {
const volume = wantedVol / 100;
msg.guild.musicData.volume = volume;
msg.guild.musicData.songDispatcher.setVolume(volume);
- msg.reply(`volume is now: ${wantedVol}% ` + emoji.random());
+ msg.reply(`volume is now: **${wantedVol}%** ` + emoji.random());
}
}; \ No newline at end of file
diff --git a/package.json b/package.json
index da8417c..cde9cdb 100644
--- a/package.json
+++ b/package.json
@@ -11,11 +11,13 @@
"dependencies": {
"@discordjs/opus": "^0.1.0",
"at-quotes": "^1.3.3",
+ "btc-value": "^3.0.1",
"demojijs": "^1.2.0",
"discord.js": "github:discordjs/discord.js",
"discord.js-commando": "github:discordjs/Commando",
"emoji-random": "^0.1.2",
"ffmpeg-static": "^4.1.0",
+ "figlet": "^1.3.0",
"is-image-url": "^1.1.8",
"moment": "^2.24.0",
"moment-duration-format": "^2.3.2",