summaryrefslogtreecommitdiff
path: root/src/commands/voice/minecraft.ts
diff options
context:
space:
mode:
author8cy <[email protected]>2020-07-23 23:24:17 -0700
committer8cy <[email protected]>2020-07-23 23:24:17 -0700
commitbb511abc03bb66848947e37a999502b813c77269 (patch)
tree612c010fc8317e1cdf11471a18aad0270819d33e /src/commands/voice/minecraft.ts
parentfix: if clear amount equal or over 100, round down to 99 (diff)
downloaddep-core-bb511abc03bb66848947e37a999502b813c77269.tar.xz
dep-core-bb511abc03bb66848947e37a999502b813c77269.zip
goodbye old uwufier :cry:
Diffstat (limited to 'src/commands/voice/minecraft.ts')
-rw-r--r--src/commands/voice/minecraft.ts209
1 files changed, 0 insertions, 209 deletions
diff --git a/src/commands/voice/minecraft.ts b/src/commands/voice/minecraft.ts
deleted file mode 100644
index 742ddde..0000000
--- a/src/commands/voice/minecraft.ts
+++ /dev/null
@@ -1,209 +0,0 @@
-//@ts-nocheck
-import ytdl from 'ytdl-core';
-import { Command, CommandoMessage } from 'discord.js-commando';
-import { MessageEmbed } from 'discord.js';
-import Youtube from 'simple-youtube-api';
-//const { youtubeAPI } = require('../../config.json');
-import config from '../../config.json';
-const youtube = new Youtube(config['yt-api-key']);
-import emoji from 'emoji-random';
-
-module.exports = class MinecraftVoice extends Command {
- constructor(client) {
- super(client, {
- name: 'minecraft',
- aliases: ['minecraftsountrack', 'minecraft-soundtrack', 'mcs', 'mc-s'],
- group: 'voice',
- memberName: 'minecraft',
- description: 'Plays the Minecraft soundtrack.',
- guildOnly: true,
- clientPermissions: ['SPEAK', 'CONNECT', 'SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
- userPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
- examples: [
- 'uwu!minecraft',
- 'uwu!minecraftsountrack',
- 'uwu!minecraft-soundtrack',
- 'uwu!mcs',
- 'uwu!mc-s'
- ],
- throttling: {
- usages: 1,
- duration: 60
- },
- });
- }
- async run(msg: CommandoMessage) {
- const voiceChannel = msg.member.voice.channel;
- if (!voiceChannel) return msg.say('Please join a channel and try again. ' + emoji.random());
-
- const playlist = await youtube.getPlaylist('https://www.youtube.com/watch?v=05UM-i4PuOY&list=PLxOTV5xn7n1i2HcKtRBthP2loWjrBGAIY').catch(function () {
- return msg.say('There was a problem getting the soundtrack. ' + emoji.random());
- });
- // remove the 10 if you removed the queue limit conditions below
- const videosObj = await playlist.getVideos(24).catch(function () {
- return msg.say(
- 'There was a problem getting the soundtrack. ' + emoji.random()
- );
- });
- for (let i = 0; i < videosObj.length; i++) {
- const video = await videosObj[i].fetch();
- // this can be uncommented if you choose to limit the queue
- // if (msg.guild.musicData.queue.length < 10) {
- //
- msg.guild.musicData.queue.push(
- this.constructSongObj(video, voiceChannel)
- );
- // } else {
- // return msg.say(
- // `I can't play the full playlist because there will be more than 10 songs in queue`
- // );
- // }
- }
- if (msg.guild.musicData.isPlaying == false) {
- msg.guild.musicData.isPlaying = true;
- return this.playSong(msg.guild.musicData.queue, msg);
- } else if (msg.guild.musicData.isPlaying == true) {
- return msg.say(
- 'Now playing the Minecraft soundtrack. ' + emoji.random()
- );
- }
-
- 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('Now playing the Minecraft soundtrack. ' + emoji.random());
- }
- })
- .catch(function () {
- if (songEmbed) {
- songEmbed.delete();
- }
- return msg.say(
- 'An error has occured when trying to get the video ID from YouTube. ' + emoji.random()
- );
- });
- });
- }
- playSong(queue, msg: CommandoMessage) {
- 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 = 100 / 100;
- msg.guild.musicData.volume = volume;
- dispatcher.setVolume(msg.guild.musicData.volume);
- const videoEmbed = new MessageEmbed()
- .setThumbnail(queue[0].thumbnail)
- .setColor(0xFFCC4D)
- .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 soundtrack. ' + emoji.random());
- 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