From 3733f7575faba8a06cc65c8eaf3612f80f46a44b Mon Sep 17 00:00:00 2001 From: 8cy <50817549+8cy@users.noreply.github.com> Date: Mon, 13 Apr 2020 03:54:31 -0700 Subject: test --- bot.js | 124 ++++++++++++++++++++-------- bot.ts | 64 +++++++++++++++ commands/utility/help.cjs | 29 +++++++ commands/utility/help.js | 29 ------- commands/utility/uptime.cjs | 28 +++++++ commands/utility/uptime.js | 28 ------- commands/voice/join.cjs | 26 ++++++ commands/voice/join.js | 26 ------ commands/voice/leave.cjs | 30 +++++++ commands/voice/leave.js | 30 ------- commands/voice/loop.js | 32 -------- commands/voice/loopc.js | 32 ++++++++ commands/voice/pause.cjs | 30 +++++++ commands/voice/pause.js | 30 ------- commands/voice/play.cjs | 196 ++++++++++++++++++++++++++++++++++++++++++++ commands/voice/play.js | 196 -------------------------------------------- commands/voice/queue.js | 51 ------------ commands/voice/queuec.js | 51 ++++++++++++ commands/voice/remove.cjs | 39 +++++++++ commands/voice/remove.js | 39 --------- commands/voice/resume.cjs | 31 +++++++ commands/voice/resume.js | 31 ------- commands/voice/shuffle.cjs | 52 ++++++++++++ commands/voice/shuffle.js | 52 ------------ commands/voice/skip.cjs | 27 ++++++ commands/voice/skip.js | 27 ------ commands/voice/skipall.js | 42 ---------- commands/voice/skipallc.js | 42 ++++++++++ commands/voice/skipto.cjs | 41 +++++++++ commands/voice/skipto.js | 41 --------- commands/voice/volume.cjs | 44 ++++++++++ commands/voice/volume.js | 44 ---------- package.json | 1 + tsconfig.json | 67 +++++++++++++++ 34 files changed, 920 insertions(+), 732 deletions(-) create mode 100644 bot.ts create mode 100644 commands/utility/help.cjs delete mode 100644 commands/utility/help.js create mode 100644 commands/utility/uptime.cjs delete mode 100644 commands/utility/uptime.js create mode 100644 commands/voice/join.cjs delete mode 100644 commands/voice/join.js create mode 100644 commands/voice/leave.cjs delete mode 100644 commands/voice/leave.js delete mode 100644 commands/voice/loop.js create mode 100644 commands/voice/loopc.js create mode 100644 commands/voice/pause.cjs delete mode 100644 commands/voice/pause.js create mode 100644 commands/voice/play.cjs delete mode 100644 commands/voice/play.js delete mode 100644 commands/voice/queue.js create mode 100644 commands/voice/queuec.js create mode 100644 commands/voice/remove.cjs delete mode 100644 commands/voice/remove.js create mode 100644 commands/voice/resume.cjs delete mode 100644 commands/voice/resume.js create mode 100644 commands/voice/shuffle.cjs delete mode 100644 commands/voice/shuffle.js create mode 100644 commands/voice/skip.cjs delete mode 100644 commands/voice/skip.js delete mode 100644 commands/voice/skipall.js create mode 100644 commands/voice/skipallc.js create mode 100644 commands/voice/skipto.cjs delete mode 100644 commands/voice/skipto.js create mode 100644 commands/voice/volume.cjs delete mode 100644 commands/voice/volume.js create mode 100644 tsconfig.json diff --git a/bot.js b/bot.js index d844105..3635f34 100644 --- a/bot.js +++ b/bot.js @@ -1,64 +1,120 @@ -const config = require('./config.json'); -const { CommandoClient } = require('discord.js-commando'); -const path = require('path'); -const { Structures } = require('discord.js'); -Structures.extend('Guild', Guild => { - class MusicGuild extends Guild { - constructor(client, data) { - super(client, data); - this.musicData = { +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var config = require('./config.json'); +var CommandoClient = require('discord.js-commando').CommandoClient; +var path_1 = __importDefault(require("path")); +var Structures = require('discord.js').Structures; +Structures.extend('Guild', function (Guild) { + var MusicGuild = /** @class */ (function (_super) { + __extends(MusicGuild, _super); + function MusicGuild(client, data) { + var _this = _super.call(this, client, data) || this; + _this.musicData = { queue: [], isPlaying: false, volume: 1, songDispatcher: null }; + return _this; } - } + return MusicGuild; + }(Guild)); return MusicGuild; }); - -const client = new CommandoClient({ +var client = new CommandoClient({ commandPrefix: 'msb!', owner: '217348698294714370' }); - client.registry .registerDefaultTypes() .registerGroups([ - ['voice', 'Voice Command Group'], - ['utility', 'Utility Command Group'] - ]) + ['voice', 'Voice Command Group'], + ['utility', 'Utility Command Group'] +]) .registerDefaultGroups() .registerDefaultCommands({ - help: false - }) - .registerCommandsIn(path.join(__dirname, 'commands')); - -client.once('ready', () => { - console.log(`Started bot: ${client.user.tag} (ID: ${client.user.id})\nCurrently running on ${client.guilds.cache.size} server(s).`); + help: false +}) + .registerCommandsIn(path_1.default.join(__dirname, 'commands')); +client.once('ready', function () { + console.log("Started bot: " + client.user.tag + " (ID: " + client.user.id + ")\nCurrently running on " + client.guilds.cache.size + " server(s)."); client.user.setActivity('msb!h | v1.1.1', { type: 'LISTENING' }); //client.channels.cache.get('600773421525237781').send('bot started up'); }); - client.on('error', console.error); client.on('debug', console.debug); - -client.on('message', async msg => { - var msgContent = msg.content.toLowerCase(); +client.on('message', function (msg) { return __awaiter(void 0, void 0, void 0, function () { function prefixCheck() { if (msgContent.startsWith('msb!')) { return true; } } - if (prefixCheck()) { - if (msg.channel.type == 'dm') { - console.log(msg.author.tag, 'says', msgContent, 'in a DM'); - } else { - console.log(msg.member.user.tag, 'says', msgContent, 'in #' + msg.channel.name); + var msgContent; + return __generator(this, function (_a) { + msgContent = msg.content.toLowerCase(); + if (prefixCheck()) { + if (msg.channel.type == 'dm') { + console.log(msg.author.tag, 'says', msgContent, 'in a DM'); + } + else { + console.log(msg.member.user.tag, 'says', msgContent, 'in #' + msg.channel.name); + } } - } -}); - + return [2 /*return*/]; + }); +}); }); client.login(config['secret']); diff --git a/bot.ts b/bot.ts new file mode 100644 index 0000000..285f22a --- /dev/null +++ b/bot.ts @@ -0,0 +1,64 @@ +const config = require('./config.json'); +const { CommandoClient } = require('discord.js-commando'); +import path from 'path'; +const { Structures } = require('discord.js'); +Structures.extend('Guild', Guild => { + class MusicGuild extends Guild { + constructor(client, data) { + super(client, data); + this.musicData = { + queue: [], + isPlaying: false, + volume: 1, + songDispatcher: null + }; + } + } + return MusicGuild; +}); + +const client = new CommandoClient({ + commandPrefix: 'msb!', + owner: '217348698294714370' +}); + +client.registry + .registerDefaultTypes() + .registerGroups([ + ['voice', 'Voice Command Group'], + ['utility', 'Utility Command Group'] + ]) + .registerDefaultGroups() + .registerDefaultCommands({ + help: false + }) + .registerCommandsIn(path.join(__dirname, 'commands')); + +client.once('ready', () => { + console.log(`Started bot: ${client.user.tag} (ID: ${client.user.id})\nCurrently running on ${client.guilds.cache.size} server(s).`); + client.user.setActivity('msb!h | v1.1.1', { + type: 'LISTENING' + }); + //client.channels.cache.get('600773421525237781').send('bot started up'); +}); + +client.on('error', console.error); +client.on('debug', console.debug); + +client.on('message', async msg => { + var msgContent = msg.content.toLowerCase(); + function prefixCheck() { + if (msgContent.startsWith('msb!')) { + return true; + } + } + if (prefixCheck()) { + if (msg.channel.type == 'dm') { + console.log(msg.author.tag, 'says', msgContent, 'in a DM'); + } else { + console.log(msg.member.user.tag, 'says', msgContent, 'in #' + msg.channel.name); + } + } +}); + +client.login(config['secret']); diff --git a/commands/utility/help.cjs b/commands/utility/help.cjs new file mode 100644 index 0000000..5b7174f --- /dev/null +++ b/commands/utility/help.cjs @@ -0,0 +1,29 @@ +const { Command } = require('discord.js-commando'); +const emoji = require('emoji-random'); +const { MessageEmbed } = require('discord.js'); + +module.exports = class HelpUtility extends Command { + constructor(client) { + super(client, { + name: 'help', + aliases: ['h'], + group: 'utility', + memberName: 'help', + description: 'Help.', + throttling: { + usages: 2, + duration: 5 + }, + guildOnly: true, + examples: ['msb!help', 'msb!h'] + }); + } + run(msg) { + let embed = new MessageEmbed() + .setColor(0x529B30) + .setTitle('MinecraftSoundtrackBot - Help') + .addField('Normal Commands', '**msb!join** - Joins your current voice channel.\n**msb!leave** - Leaves the voice channel and ends playback.\n**msb!loop** - Loops the soundtrack.\n**msb!pause** - Pauses soundtrack playback if playing.\n**msb!play** - Plays the Minecraft soundtrack.\n**msb!queue** - Displays the song queue\n**msb!remove** - Remove a certain song from the soundtrack queue.\n**msb!resume** - Resumes the soundtrack if paused.\n**msb!shuffle** - Shuffles the soundtrack queue.\n**msb!skip** - Skips one song ahead in the soundtrack queue.\n**msb!skipall** - Skips all the songs in the soundtrack queue.\n**msb!skipto** - Skip to a certain song in the soundtrack queue.\n**msb!volume** - Changes the volume of playback.') + .setFooter(`Bot developed and administrated by sin#1337.`, this.client.users.cache.get('217348698294714370').avatarURL()); + msg.say(embed); + } +}; \ No newline at end of file diff --git a/commands/utility/help.js b/commands/utility/help.js deleted file mode 100644 index 5b7174f..0000000 --- a/commands/utility/help.js +++ /dev/null @@ -1,29 +0,0 @@ -const { Command } = require('discord.js-commando'); -const emoji = require('emoji-random'); -const { MessageEmbed } = require('discord.js'); - -module.exports = class HelpUtility extends Command { - constructor(client) { - super(client, { - name: 'help', - aliases: ['h'], - group: 'utility', - memberName: 'help', - description: 'Help.', - throttling: { - usages: 2, - duration: 5 - }, - guildOnly: true, - examples: ['msb!help', 'msb!h'] - }); - } - run(msg) { - let embed = new MessageEmbed() - .setColor(0x529B30) - .setTitle('MinecraftSoundtrackBot - Help') - .addField('Normal Commands', '**msb!join** - Joins your current voice channel.\n**msb!leave** - Leaves the voice channel and ends playback.\n**msb!loop** - Loops the soundtrack.\n**msb!pause** - Pauses soundtrack playback if playing.\n**msb!play** - Plays the Minecraft soundtrack.\n**msb!queue** - Displays the song queue\n**msb!remove** - Remove a certain song from the soundtrack queue.\n**msb!resume** - Resumes the soundtrack if paused.\n**msb!shuffle** - Shuffles the soundtrack queue.\n**msb!skip** - Skips one song ahead in the soundtrack queue.\n**msb!skipall** - Skips all the songs in the soundtrack queue.\n**msb!skipto** - Skip to a certain song in the soundtrack queue.\n**msb!volume** - Changes the volume of playback.') - .setFooter(`Bot developed and administrated by sin#1337.`, this.client.users.cache.get('217348698294714370').avatarURL()); - msg.say(embed); - } -}; \ No newline at end of file diff --git a/commands/utility/uptime.cjs b/commands/utility/uptime.cjs new file mode 100644 index 0000000..34b073c --- /dev/null +++ b/commands/utility/uptime.cjs @@ -0,0 +1,28 @@ +const { Command } = require('discord.js-commando'); +const upTime = require('moment'); +require('moment-duration-format'); +const emoji = require('emoji-random'); + +module.exports = class UptimeUtility extends Command { + constructor(client) { + super(client, { + name: 'uptime', + aliases: ['ut'], + group: 'utility', + memberName: 'uptime', + description: 'Tells you how long the bot has been online.', + throttling: { + usages: 5, + duration: 30 + }, + examples: [ + 'msb!uptime', + 'msb!ut' + ] + }); + } + run(msg) { + const duration = upTime.duration(this.client.uptime).format(" D [days], H [hrs], m [mins], s [secs]"); + msg.reply(duration + ' ' + emoji.random()); + } +}; \ No newline at end of file diff --git a/commands/utility/uptime.js b/commands/utility/uptime.js deleted file mode 100644 index 34b073c..0000000 --- a/commands/utility/uptime.js +++ /dev/null @@ -1,28 +0,0 @@ -const { Command } = require('discord.js-commando'); -const upTime = require('moment'); -require('moment-duration-format'); -const emoji = require('emoji-random'); - -module.exports = class UptimeUtility extends Command { - constructor(client) { - super(client, { - name: 'uptime', - aliases: ['ut'], - group: 'utility', - memberName: 'uptime', - description: 'Tells you how long the bot has been online.', - throttling: { - usages: 5, - duration: 30 - }, - examples: [ - 'msb!uptime', - 'msb!ut' - ] - }); - } - run(msg) { - const duration = upTime.duration(this.client.uptime).format(" D [days], H [hrs], m [mins], s [secs]"); - msg.reply(duration + ' ' + emoji.random()); - } -}; \ No newline at end of file diff --git a/commands/voice/join.cjs b/commands/voice/join.cjs new file mode 100644 index 0000000..cac5e50 --- /dev/null +++ b/commands/voice/join.cjs @@ -0,0 +1,26 @@ +const { Command } = require('discord.js-commando'); +const emoji = require('emoji-random'); + +module.exports = class JoinVoice extends Command { + constructor(client) { + super(client, { + name: 'join', + aliases: ['j'], + group: 'voice', + memberName: 'join', + description: 'Joins your current voice channel.', + guildOnly: true, + examples: ['msb!join', 'msb!j'] + }); + } + run(msg) { + if (msg.guild.musicData.isPlaying == false && msg.member.voice.channel) { + msg.member.voice.channel.join(); + msg.reply('Succesfully joined your voice channel. ' + emoji.random()); + } else if (msg.guild.musicData.isPlaying == false) { + msg.reply('I\'m already in voice channel. ' + emoji.random()); + } else if (!msg.member.voice.channel) { + msg.reply('You\'re not in a voice channel. ' + emoji.random()); + } + } +}; \ No newline at end of file diff --git a/commands/voice/join.js b/commands/voice/join.js deleted file mode 100644 index cac5e50..0000000 --- a/commands/voice/join.js +++ /dev/null @@ -1,26 +0,0 @@ -const { Command } = require('discord.js-commando'); -const emoji = require('emoji-random'); - -module.exports = class JoinVoice extends Command { - constructor(client) { - super(client, { - name: 'join', - aliases: ['j'], - group: 'voice', - memberName: 'join', - description: 'Joins your current voice channel.', - guildOnly: true, - examples: ['msb!join', 'msb!j'] - }); - } - run(msg) { - if (msg.guild.musicData.isPlaying == false && msg.member.voice.channel) { - msg.member.voice.channel.join(); - msg.reply('Succesfully joined your voice channel. ' + emoji.random()); - } else if (msg.guild.musicData.isPlaying == false) { - msg.reply('I\'m already in voice channel. ' + emoji.random()); - } else if (!msg.member.voice.channel) { - msg.reply('You\'re not in a voice channel. ' + emoji.random()); - } - } -}; \ No newline at end of file diff --git a/commands/voice/leave.cjs b/commands/voice/leave.cjs new file mode 100644 index 0000000..ba48594 --- /dev/null +++ b/commands/voice/leave.cjs @@ -0,0 +1,30 @@ +const { Command } = require('discord.js-commando'); +const emoji = require('emoji-random'); + +module.exports = class LeaveVoice extends Command { + constructor(client) { + super(client, { + name: 'leave', + aliases: ['end', 'stop', 'l'], + group: 'voice', + memberName: 'leave', + description: 'Leaves the voice channel and ends playback.', + guildOnly: true, + examples: ['msb!leave', 'msb!end', 'msb!stop', 'msb!l'] + }); + } + run(msg) { + var voiceChannel = msg.member.voice.channel; + if (!voiceChannel) return msg.reply('Join a voice channel and try again. ' + emoji.random()); + + if ( + typeof msg.guild.musicData.songDispatcher == 'undefined' || + msg.guild.musicData.songDispatcher == null + ) { + return msg.reply('The soundtrack isn\'t playing right now. ' + emoji.random()); + } + msg.guild.musicData.songDispatcher.end(); + msg.guild.musicData.queue.length = 0; + return; + } +}; \ No newline at end of file diff --git a/commands/voice/leave.js b/commands/voice/leave.js deleted file mode 100644 index ba48594..0000000 --- a/commands/voice/leave.js +++ /dev/null @@ -1,30 +0,0 @@ -const { Command } = require('discord.js-commando'); -const emoji = require('emoji-random'); - -module.exports = class LeaveVoice extends Command { - constructor(client) { - super(client, { - name: 'leave', - aliases: ['end', 'stop', 'l'], - group: 'voice', - memberName: 'leave', - description: 'Leaves the voice channel and ends playback.', - guildOnly: true, - examples: ['msb!leave', 'msb!end', 'msb!stop', 'msb!l'] - }); - } - run(msg) { - var voiceChannel = msg.member.voice.channel; - if (!voiceChannel) return msg.reply('Join a voice channel and try again. ' + emoji.random()); - - if ( - typeof msg.guild.musicData.songDispatcher == 'undefined' || - msg.guild.musicData.songDispatcher == null - ) { - return msg.reply('The soundtrack isn\'t playing right now. ' + emoji.random()); - } - msg.guild.musicData.songDispatcher.end(); - msg.guild.musicData.queue.length = 0; - return; - } -}; \ No newline at end of file diff --git a/commands/voice/loop.js b/commands/voice/loop.js deleted file mode 100644 index 507b424..0000000 --- a/commands/voice/loop.js +++ /dev/null @@ -1,32 +0,0 @@ -const { Command } = require('discord.js-commando'); -const emoji = require('emoji-random'); - -module.exports = class LoopVoice extends Command { - constructor(client) { - super(client, { - name: 'loop', - aliases: ['repeat'], - group: 'voice', - memberName: 'loop', - description: 'Loops the soundtrack.', - guildOnly: true, - examples: ['msb!loop', 'msb!repeat'] - }); - } - run(msg) { - var voiceChannel = msg.member.voice.channel; - if (!voiceChannel) return msg.reply('Join a voice channel and try again. ' + emoji.random()); - - if ( - typeof msg.guild.musicData.songDispatcher == 'undefined' || - msg.guild.musicData.songDispatcher == null - ) { - return msg.reply('The soundtrack isn\'t playing right now. ' + emoji.random()); - } - msg.channel.send( - 'Looping the soundtrack ' + emoji.random() - ); - msg.guild.musicData.queue.unshift(msg.guild.musicData.nowPlaying); - return; - } -}; \ No newline at end of file diff --git a/commands/voice/loopc.js b/commands/voice/loopc.js new file mode 100644 index 0000000..507b424 --- /dev/null +++ b/commands/voice/loopc.js @@ -0,0 +1,32 @@ +const { Command } = require('discord.js-commando'); +const emoji = require('emoji-random'); + +module.exports = class LoopVoice extends Command { + constructor(client) { + super(client, { + name: 'loop', + aliases: ['repeat'], + group: 'voice', + memberName: 'loop', + description: 'Loops the soundtrack.', + guildOnly: true, + examples: ['msb!loop', 'msb!repeat'] + }); + } + run(msg) { + var voiceChannel = msg.member.voice.channel; + if (!voiceChannel) return msg.reply('Join a voice channel and try again. ' + emoji.random()); + + if ( + typeof msg.guild.musicData.songDispatcher == 'undefined' || + msg.guild.musicData.songDispatcher == null + ) { + return msg.reply('The soundtrack isn\'t playing right now. ' + emoji.random()); + } + msg.channel.send( + 'Looping the soundtrack ' + emoji.random() + ); + msg.guild.musicData.queue.unshift(msg.guild.musicData.nowPlaying); + return; + } +}; \ No newline at end of file diff --git a/commands/voice/pause.cjs b/commands/voice/pause.cjs new file mode 100644 index 0000000..20d4254 --- /dev/null +++ b/commands/voice/pause.cjs @@ -0,0 +1,30 @@ +const { Command } = require('discord.js-commando'); +const emoji = require('emoji-random'); + +module.exports = class PauseVoice extends Command { + constructor(client) { + super(client, { + name: 'pause', + group: 'voice', + memberName: 'pause', + description: 'Pauses soundtrack playback if playing.', + guildOnly: true, + examples: ['msb!pause'] + }); + } + run(msg) { + var voiceChannel = msg.member.voice.channel; + if (!voiceChannel) return msg.reply('Join a channel and try again. ' + emoji.random()); + + if ( + typeof msg.guild.musicData.songDispatcher == 'undefined' || + msg.guild.musicData.songDispatcher == null + ) { + return msg.reply('The soundtrack isn\'t playing right now. ' + emoji.random()); + } + + msg.say('Soundtrack paused :pause_button:'); + + msg.guild.musicData.songDispatcher.pause(); + } +}; \ No newline at end of file diff --git a/commands/voice/pause.js b/commands/voice/pause.js deleted file mode 100644 index 20d4254..0000000 --- a/commands/voice/pause.js +++ /dev/null @@ -1,30 +0,0 @@ -const { Command } = require('discord.js-commando'); -const emoji = require('emoji-random'); - -module.exports = class PauseVoice extends Command { - constructor(client) { - super(client, { - name: 'pause', - group: 'voice', - memberName: 'pause', - description: 'Pauses soundtrack playback if playing.', - guildOnly: true, - examples: ['msb!pause'] - }); - } - run(msg) { - var voiceChannel = msg.member.voice.channel; - if (!voiceChannel) return msg.reply('Join a channel and try again. ' + emoji.random()); - - if ( - typeof msg.guild.musicData.songDispatcher == 'undefined' || - msg.guild.musicData.songDispatcher == null - ) { - return msg.reply('The soundtrack isn\'t playing right now. ' + emoji.random()); - } - - msg.say('Soundtrack paused :pause_button:'); - - msg.guild.musicData.songDispatcher.pause(); - } -}; \ No newline at end of file diff --git a/commands/voice/play.cjs b/commands/voice/play.cjs new file mode 100644 index 0000000..8797593 --- /dev/null +++ b/commands/voice/play.cjs @@ -0,0 +1,196 @@ +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 PlayVoice extends Command { + constructor(client) { + super(client, { + name: 'play', + aliases: ['p'], + group: 'voice', + memberName: 'play', + description: 'Plays the Minecraft soundtrack.', + guildOnly: true, + clientPermissions: ['SPEAK', 'CONNECT'], + examples: ['msb!play', 'msb!p'] + }); + } + async run(msg) { + const voiceChannel = msg.member.voice.channel; + if (!voiceChannel) return msg.say('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) { + 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(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 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 diff --git a/commands/voice/play.js b/commands/voice/play.js deleted file mode 100644 index 8797593..0000000 --- a/commands/voice/play.js +++ /dev/null @@ -1,196 +0,0 @@ -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 PlayVoice extends Command { - constructor(client) { - super(client, { - name: 'play', - aliases: ['p'], - group: 'voice', - memberName: 'play', - description: 'Plays the Minecraft soundtrack.', - guildOnly: true, - clientPermissions: ['SPEAK', 'CONNECT'], - examples: ['msb!play', 'msb!p'] - }); - } - async run(msg) { - const voiceChannel = msg.member.voice.channel; - if (!voiceChannel) return msg.say('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) { - 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(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 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 diff --git a/commands/voice/queue.js b/commands/voice/queue.js deleted file mode 100644 index ac9c236..0000000 --- a/commands/voice/queue.js +++ /dev/null @@ -1,51 +0,0 @@ -const { Command } = require('discord.js-commando'); -const { MessageEmbed } = require('discord.js'); -const emoji = require('emoji-random'); - -module.exports = class QueueVoice extends Command { - constructor(client) { - super(client, { - name: 'queue', - aliases: [ - 'q', - 'song-list', - 'next-songs', - 'songlist', - 'nextsongs', - 'nextsong', - 'next-song' - ], - group: 'voice', - memberName: 'queue', - description: 'Displays the song queue.', - guildOnly: true, - examples: [ - 'msb!queue', - 'msb!q', - 'msb!songlist', - 'msb!song-list', - 'msb!nextsong', - 'msb!next-song', - 'msb!nextsongs', - 'msb!next-songs' - ] - }); - } - run(msg) { - if (msg.guild.musicData.queue.length == 0) - return msg.say('The soundtrack is not queued. ' + emoji.random()); - const titleArray = []; - msg.guild.musicData.queue.map(obj => { - titleArray.push(obj.title); - }); - let queueEmbed = new MessageEmbed() - .setColor(0xF97DAE) - .setTitle('Soundtrack Queue ' + emoji.random()); - for (let i = 0; i < titleArray.length; i++) { - queueEmbed - .addField(`‎`, `**${i + 1}**: ` + `${titleArray[i]}`) - .setFooter(`Bot developed and administrated by sin#1337.`, this.client.users.cache.get('217348698294714370').avatarURL()); - } - return msg.say(queueEmbed); - } -}; \ No newline at end of file diff --git a/commands/voice/queuec.js b/commands/voice/queuec.js new file mode 100644 index 0000000..ac9c236 --- /dev/null +++ b/commands/voice/queuec.js @@ -0,0 +1,51 @@ +const { Command } = require('discord.js-commando'); +const { MessageEmbed } = require('discord.js'); +const emoji = require('emoji-random'); + +module.exports = class QueueVoice extends Command { + constructor(client) { + super(client, { + name: 'queue', + aliases: [ + 'q', + 'song-list', + 'next-songs', + 'songlist', + 'nextsongs', + 'nextsong', + 'next-song' + ], + group: 'voice', + memberName: 'queue', + description: 'Displays the song queue.', + guildOnly: true, + examples: [ + 'msb!queue', + 'msb!q', + 'msb!songlist', + 'msb!song-list', + 'msb!nextsong', + 'msb!next-song', + 'msb!nextsongs', + 'msb!next-songs' + ] + }); + } + run(msg) { + if (msg.guild.musicData.queue.length == 0) + return msg.say('The soundtrack is not queued. ' + emoji.random()); + const titleArray = []; + msg.guild.musicData.queue.map(obj => { + titleArray.push(obj.title); + }); + let queueEmbed = new MessageEmbed() + .setColor(0xF97DAE) + .setTitle('Soundtrack Queue ' + emoji.random()); + for (let i = 0; i < titleArray.length; i++) { + queueEmbed + .addField(`‎`, `**${i + 1}**: ` + `${titleArray[i]}`) + .setFooter(`Bot developed and administrated by sin#1337.`, this.client.users.cache.get('217348698294714370').avatarURL()); + } + return msg.say(queueEmbed); + } +}; \ No newline at end of file diff --git a/commands/voice/remove.cjs b/commands/voice/remove.cjs new file mode 100644 index 0000000..edcb948 --- /dev/null +++ b/commands/voice/remove.cjs @@ -0,0 +1,39 @@ +const { Command } = require('discord.js-commando'); +const emoji = require('emoji-random'); + +module.exports = class RemoveVoice extends Command { + constructor(client) { + super(client, { + name: 'remove', + group: 'voice', + memberName: 'remove', + description: 'Remove a certain song from the soundtrack queue.', + guildOnly: true, + args: [ + { + key: 'songNumber', + prompt: 'What song would you like the remove?', + type: 'integer' + } + ], + examples: ['msb!remove 2'] + }); + } + run(msg, { songNumber }) { + if (songNumber < 1 && songNumber >= msg.guild.musicData.queue.length) { + return msg.reply('Please enter a valid song number. ' + emoji.random()); + } + var voiceChannel = msg.member.voice.channel; + if (!voiceChannel) return msg.reply('Join a voice channel and try again. ' + emoji.random()); + + if ( + typeof msg.guild.musicData.songDispatcher == 'undefined' || + msg.guild.musicData.songDispatcher == null + ) { + return msg.reply('The soundtrack isn\'t playing right now. ' + emoji.random()); + } + + msg.guild.musicData.queue.splice(songNumber - 1, 1); + return msg.say(`Removed song **#${songNumber}** from soundtrack queue. ` + emoji.random()); + } +}; \ No newline at end of file diff --git a/commands/voice/remove.js b/commands/voice/remove.js deleted file mode 100644 index edcb948..0000000 --- a/commands/voice/remove.js +++ /dev/null @@ -1,39 +0,0 @@ -const { Command } = require('discord.js-commando'); -const emoji = require('emoji-random'); - -module.exports = class RemoveVoice extends Command { - constructor(client) { - super(client, { - name: 'remove', - group: 'voice', - memberName: 'remove', - description: 'Remove a certain song from the soundtrack queue.', - guildOnly: true, - args: [ - { - key: 'songNumber', - prompt: 'What song would you like the remove?', - type: 'integer' - } - ], - examples: ['msb!remove 2'] - }); - } - run(msg, { songNumber }) { - if (songNumber < 1 && songNumber >= msg.guild.musicData.queue.length) { - return msg.reply('Please enter a valid song number. ' + emoji.random()); - } - var voiceChannel = msg.member.voice.channel; - if (!voiceChannel) return msg.reply('Join a voice channel and try again. ' + emoji.random()); - - if ( - typeof msg.guild.musicData.songDispatcher == 'undefined' || - msg.guild.musicData.songDispatcher == null - ) { - return msg.reply('The soundtrack isn\'t playing right now. ' + emoji.random()); - } - - msg.guild.musicData.queue.splice(songNumber - 1, 1); - return msg.say(`Removed song **#${songNumber}** from soundtrack queue. ` + emoji.random()); - } -}; \ No newline at end of file diff --git a/commands/voice/resume.cjs b/commands/voice/resume.cjs new file mode 100644 index 0000000..a3f32ce --- /dev/null +++ b/commands/voice/resume.cjs @@ -0,0 +1,31 @@ +const { Command } = require('discord.js-commando'); +const emoji = require('emoji-random'); + +module.exports = class ResumeVoice extends Command { + constructor(client) { + super(client, { + name: 'resume', + aliases: ['unpause'], + group: 'voice', + memberName: 'resume', + description: 'Resumes the soundtrack if paused.', + guildOnly: true, + examples: ['msb!resume', 'msb!unpause'] + }); + } + run(msg) { + var voiceChannel = msg.member.voice.channel; + if (!voiceChannel) return msg.reply('Join a channel and try again. ' + emoji.random()); + + if ( + typeof msg.guild.musicData.songDispatcher == 'undefined' || + msg.guild.musicData.songDispatcher == null + ) { + return msg.reply('The soundtrack isn\'t playing right now. ' + emoji.random()); + } + + msg.say('Soundtrack resumed :play_pause:'); + + msg.guild.musicData.songDispatcher.resume(); + } +}; \ No newline at end of file diff --git a/commands/voice/resume.js b/commands/voice/resume.js deleted file mode 100644 index a3f32ce..0000000 --- a/commands/voice/resume.js +++ /dev/null @@ -1,31 +0,0 @@ -const { Command } = require('discord.js-commando'); -const emoji = require('emoji-random'); - -module.exports = class ResumeVoice extends Command { - constructor(client) { - super(client, { - name: 'resume', - aliases: ['unpause'], - group: 'voice', - memberName: 'resume', - description: 'Resumes the soundtrack if paused.', - guildOnly: true, - examples: ['msb!resume', 'msb!unpause'] - }); - } - run(msg) { - var voiceChannel = msg.member.voice.channel; - if (!voiceChannel) return msg.reply('Join a channel and try again. ' + emoji.random()); - - if ( - typeof msg.guild.musicData.songDispatcher == 'undefined' || - msg.guild.musicData.songDispatcher == null - ) { - return msg.reply('The soundtrack isn\'t playing right now. ' + emoji.random()); - } - - msg.say('Soundtrack resumed :play_pause:'); - - msg.guild.musicData.songDispatcher.resume(); - } -}; \ No newline at end of file diff --git a/commands/voice/shuffle.cjs b/commands/voice/shuffle.cjs new file mode 100644 index 0000000..a6251ca --- /dev/null +++ b/commands/voice/shuffle.cjs @@ -0,0 +1,52 @@ +const { Command } = require('discord.js-commando'); +const { MessageEmbed } = require('discord.js'); +const emoji = require('emoji-random'); + +module.exports = class ShuffleVoice extends Command { + constructor(client) { + super(client, { + name: 'shuffle', + group: 'voice', + memberName: 'shuffle', + description: 'Shuffles the soundtrack queue.', + guildOnly: true, + examples: ['msb!shuffle'] + }); + } + run(msg) { + var voiceChannel = msg.member.voice.channel; + if (!voiceChannel) return msg.reply('Join a channel and try again. ' + emoji.random()); + + if ( + typeof msg.guild.musicData.songDispatcher == 'undefined' || + msg.guild.musicData.songDispatcher == null + ) { + return msg.reply('The soundtrack isn\'t playing right now. ' + emoji.random()); + } + + if (msg.guild.musicData.queue.length < 1) + return msg.say('This is the only song in the soundtrack queue. ' + emoji.random()); + + shuffleQueue(msg.guild.musicData.queue); + + const titleArray = []; + msg.guild.musicData.queue.map(obj => { + titleArray.push(obj.title); + }); + var queueEmbed = new MessageEmbed() + .setColor(0xF97DAE) + .setTitle('New Soundtrack Queue ' + emoji.random()) + .setFooter(`Bot developed and administrated by sin#1337.`, this.client.users.cache.get('217348698294714370').avatarURL()); + for (let i = 0; i < titleArray.length; i++) { + queueEmbed.addField(`${i + 1}:`, `${titleArray[i]}`); + } + return msg.say(queueEmbed); + } +}; + +function shuffleQueue(queue) { + for (let i = queue.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [queue[i], queue[j]] = [queue[j], queue[i]]; + } +} \ No newline at end of file diff --git a/commands/voice/shuffle.js b/commands/voice/shuffle.js deleted file mode 100644 index a6251ca..0000000 --- a/commands/voice/shuffle.js +++ /dev/null @@ -1,52 +0,0 @@ -const { Command } = require('discord.js-commando'); -const { MessageEmbed } = require('discord.js'); -const emoji = require('emoji-random'); - -module.exports = class ShuffleVoice extends Command { - constructor(client) { - super(client, { - name: 'shuffle', - group: 'voice', - memberName: 'shuffle', - description: 'Shuffles the soundtrack queue.', - guildOnly: true, - examples: ['msb!shuffle'] - }); - } - run(msg) { - var voiceChannel = msg.member.voice.channel; - if (!voiceChannel) return msg.reply('Join a channel and try again. ' + emoji.random()); - - if ( - typeof msg.guild.musicData.songDispatcher == 'undefined' || - msg.guild.musicData.songDispatcher == null - ) { - return msg.reply('The soundtrack isn\'t playing right now. ' + emoji.random()); - } - - if (msg.guild.musicData.queue.length < 1) - return msg.say('This is the only song in the soundtrack queue. ' + emoji.random()); - - shuffleQueue(msg.guild.musicData.queue); - - const titleArray = []; - msg.guild.musicData.queue.map(obj => { - titleArray.push(obj.title); - }); - var queueEmbed = new MessageEmbed() - .setColor(0xF97DAE) - .setTitle('New Soundtrack Queue ' + emoji.random()) - .setFooter(`Bot developed and administrated by sin#1337.`, this.client.users.cache.get('217348698294714370').avatarURL()); - for (let i = 0; i < titleArray.length; i++) { - queueEmbed.addField(`${i + 1}:`, `${titleArray[i]}`); - } - return msg.say(queueEmbed); - } -}; - -function shuffleQueue(queue) { - for (let i = queue.length - 1; i > 0; i--) { - const j = Math.floor(Math.random() * (i + 1)); - [queue[i], queue[j]] = [queue[j], queue[i]]; - } -} \ No newline at end of file diff --git a/commands/voice/skip.cjs b/commands/voice/skip.cjs new file mode 100644 index 0000000..9cac14c --- /dev/null +++ b/commands/voice/skip.cjs @@ -0,0 +1,27 @@ +const { Command } = require('discord.js-commando'); +const emoji = require('emoji-random'); + +module.exports = class SkipVoice extends Command { + constructor(client) { + super(client, { + name: 'skip', + group: 'voice', + memberName: 'skip', + description: 'Skips one song ahead in the soundtrack queue.', + guildOnly: true, + examples: ['msb!skip'] + }); + } + run(msg) { + const voiceChannel = msg.member.voice.channel; + if (!voiceChannel) return msg.reply('Join a channel and try again. ' + emoji.random()); + + if ( + typeof msg.guild.musicData.songDispatcher == 'undefined' || + msg.guild.musicData.songDispatcher == null + ) { + return msg.reply('The soundtrack isn\'t playing right now. ' + emoji.random()); + } + msg.guild.musicData.songDispatcher.end(); + } +}; \ No newline at end of file diff --git a/commands/voice/skip.js b/commands/voice/skip.js deleted file mode 100644 index 9cac14c..0000000 --- a/commands/voice/skip.js +++ /dev/null @@ -1,27 +0,0 @@ -const { Command } = require('discord.js-commando'); -const emoji = require('emoji-random'); - -module.exports = class SkipVoice extends Command { - constructor(client) { - super(client, { - name: 'skip', - group: 'voice', - memberName: 'skip', - description: 'Skips one song ahead in the soundtrack queue.', - guildOnly: true, - examples: ['msb!skip'] - }); - } - run(msg) { - const voiceChannel = msg.member.voice.channel; - if (!voiceChannel) return msg.reply('Join a channel and try again. ' + emoji.random()); - - if ( - typeof msg.guild.musicData.songDispatcher == 'undefined' || - msg.guild.musicData.songDispatcher == null - ) { - return msg.reply('The soundtrack isn\'t playing right now. ' + emoji.random()); - } - msg.guild.musicData.songDispatcher.end(); - } -}; \ No newline at end of file diff --git a/commands/voice/skipall.js b/commands/voice/skipall.js deleted file mode 100644 index 32800b1..0000000 --- a/commands/voice/skipall.js +++ /dev/null @@ -1,42 +0,0 @@ -const { Command } = require('discord.js-commando'); -const emoji = require('emoji-random'); - -module.exports = class SkipAllVoice extends Command { - constructor(client) { - super(client, { - name: 'skipall', - aliases: [ - 'endqueue', - 'endq', - 'skipqueue', - 'skipq' - ], - group: 'voice', - memberName: 'skipall', - description: 'Skips all the songs in the soundtrack queue.', - guildOnly: true, - examples: [ - 'msb!endqueue', - 'msb!endq', - 'msb!skipqueue', - 'msb!skipq' - ] - }); - } - run(msg) { - var voiceChannel = msg.member.voice.channel; - if (!voiceChannel) return msg.reply('Join a channel and try again. ' + emoji.random()); - - if ( - typeof msg.guild.musicData.songDispatcher == 'undefined' || - msg.guild.musicData.songDispatcher == null - ) { - return msg.reply('The soundtrack isn\'t playing right now. ' + emoji.random()); - } - if (!msg.guild.musicData.queue) - return msg.say('This is the only song in the soundtrack queue. ' + emoji.random()); - msg.guild.musicData.songDispatcher.end(); - msg.guild.musicData.queue.length = 0; // clear queue - return; - } -}; \ No newline at end of file diff --git a/commands/voice/skipallc.js b/commands/voice/skipallc.js new file mode 100644 index 0000000..32800b1 --- /dev/null +++ b/commands/voice/skipallc.js @@ -0,0 +1,42 @@ +const { Command } = require('discord.js-commando'); +const emoji = require('emoji-random'); + +module.exports = class SkipAllVoice extends Command { + constructor(client) { + super(client, { + name: 'skipall', + aliases: [ + 'endqueue', + 'endq', + 'skipqueue', + 'skipq' + ], + group: 'voice', + memberName: 'skipall', + description: 'Skips all the songs in the soundtrack queue.', + guildOnly: true, + examples: [ + 'msb!endqueue', + 'msb!endq', + 'msb!skipqueue', + 'msb!skipq' + ] + }); + } + run(msg) { + var voiceChannel = msg.member.voice.channel; + if (!voiceChannel) return msg.reply('Join a channel and try again. ' + emoji.random()); + + if ( + typeof msg.guild.musicData.songDispatcher == 'undefined' || + msg.guild.musicData.songDispatcher == null + ) { + return msg.reply('The soundtrack isn\'t playing right now. ' + emoji.random()); + } + if (!msg.guild.musicData.queue) + return msg.say('This is the only song in the soundtrack queue. ' + emoji.random()); + msg.guild.musicData.songDispatcher.end(); + msg.guild.musicData.queue.length = 0; // clear queue + return; + } +}; \ No newline at end of file diff --git a/commands/voice/skipto.cjs b/commands/voice/skipto.cjs new file mode 100644 index 0000000..aa27add --- /dev/null +++ b/commands/voice/skipto.cjs @@ -0,0 +1,41 @@ +const { Command } = require('discord.js-commando'); +const emoji = require('emoji-random'); + +module.exports = class SkipToVoice extends Command { + constructor(client) { + super(client, { + name: 'skipto', + group: 'voice', + memberName: 'skipto', + description: 'Skip to a certain song in the soundtrack queue.', + guildOnly: true, + args: [{ + key: 'songNumber', + prompt: 'What song would you like the skip to?', + type: 'integer' + }], + examples: ['msb!skipto 5'] + }); + } + run(msg, { songNumber }) { + if (songNumber < 1 && songNumber >= msg.guild.musicData.queue.length) { + return msg.reply('Please enter a valid song number' + emoji.random()); + } + var voiceChannel = msg.member.voice.channel; + if (!voiceChannel) return msg.reply('Join a channel and try again. ' + emoji.random()); + + if ( + typeof msg.guild.musicData.songDispatcher == 'undefined' || + msg.guild.musicData.songDispatcher == null + ) { + return msg.reply('The soundtrack isn\'t playing right now. ' + emoji.random()); + } + + if (msg.guild.musicData.queue < 1) + return msg.reply('This is the only song in the soundtrack queue. ' + emoji.random()); + + msg.guild.musicData.queue.splice(0, songNumber - 1); + msg.guild.musicData.songDispatcher.end(); + return; + } +}; \ No newline at end of file diff --git a/commands/voice/skipto.js b/commands/voice/skipto.js deleted file mode 100644 index aa27add..0000000 --- a/commands/voice/skipto.js +++ /dev/null @@ -1,41 +0,0 @@ -const { Command } = require('discord.js-commando'); -const emoji = require('emoji-random'); - -module.exports = class SkipToVoice extends Command { - constructor(client) { - super(client, { - name: 'skipto', - group: 'voice', - memberName: 'skipto', - description: 'Skip to a certain song in the soundtrack queue.', - guildOnly: true, - args: [{ - key: 'songNumber', - prompt: 'What song would you like the skip to?', - type: 'integer' - }], - examples: ['msb!skipto 5'] - }); - } - run(msg, { songNumber }) { - if (songNumber < 1 && songNumber >= msg.guild.musicData.queue.length) { - return msg.reply('Please enter a valid song number' + emoji.random()); - } - var voiceChannel = msg.member.voice.channel; - if (!voiceChannel) return msg.reply('Join a channel and try again. ' + emoji.random()); - - if ( - typeof msg.guild.musicData.songDispatcher == 'undefined' || - msg.guild.musicData.songDispatcher == null - ) { - return msg.reply('The soundtrack isn\'t playing right now. ' + emoji.random()); - } - - if (msg.guild.musicData.queue < 1) - return msg.reply('This is the only song in the soundtrack queue. ' + emoji.random()); - - msg.guild.musicData.queue.splice(0, songNumber - 1); - msg.guild.musicData.songDispatcher.end(); - return; - } -}; \ No newline at end of file diff --git a/commands/voice/volume.cjs b/commands/voice/volume.cjs new file mode 100644 index 0000000..0a59a68 --- /dev/null +++ b/commands/voice/volume.cjs @@ -0,0 +1,44 @@ +const { Command } = require('discord.js-commando'); +const emoji = require('emoji-random'); + +module.exports = class VolumeVoice extends Command { + constructor(client) { + super(client, { + name: 'volume', + aliases: ['vol', 'v'], + group: 'voice', + memberName: 'volume', + description: 'Changes the volume of playback.', + guildOnly: true, + args: [ + { + key: 'wantedVol', + prompt: 'What would you like the volume to be? (1 - 200)', + type: 'integer', + validate: wantedVol => wantedVol >= 1 && wantedVol <= 200 + } + ], + examples: [ + 'msb!volume 20', + 'msb!vol 50', + 'msb!v 70' + ] + }); + } + run(msg, { wantedVol }) { + var voiceChannel = msg.member.voice.channel; + if (!voiceChannel) return msg.reply('Join a channel and try again. ' + emoji.random()); + + if ( + typeof msg.guild.musicData.songDispatcher == 'undefined' || + msg.guild.musicData.songDispatcher == null + ) { + return msg.reply('The soundtrack isn\'t playing right now. ' + emoji.random()); + } + + const volume = wantedVol / 100; + msg.guild.musicData.volume = volume; + msg.guild.musicData.songDispatcher.setVolume(volume); + msg.reply(`Volume is now: **${wantedVol}%** ` + emoji.random()); + } +}; \ No newline at end of file diff --git a/commands/voice/volume.js b/commands/voice/volume.js deleted file mode 100644 index 0a59a68..0000000 --- a/commands/voice/volume.js +++ /dev/null @@ -1,44 +0,0 @@ -const { Command } = require('discord.js-commando'); -const emoji = require('emoji-random'); - -module.exports = class VolumeVoice extends Command { - constructor(client) { - super(client, { - name: 'volume', - aliases: ['vol', 'v'], - group: 'voice', - memberName: 'volume', - description: 'Changes the volume of playback.', - guildOnly: true, - args: [ - { - key: 'wantedVol', - prompt: 'What would you like the volume to be? (1 - 200)', - type: 'integer', - validate: wantedVol => wantedVol >= 1 && wantedVol <= 200 - } - ], - examples: [ - 'msb!volume 20', - 'msb!vol 50', - 'msb!v 70' - ] - }); - } - run(msg, { wantedVol }) { - var voiceChannel = msg.member.voice.channel; - if (!voiceChannel) return msg.reply('Join a channel and try again. ' + emoji.random()); - - if ( - typeof msg.guild.musicData.songDispatcher == 'undefined' || - msg.guild.musicData.songDispatcher == null - ) { - return msg.reply('The soundtrack isn\'t playing right now. ' + emoji.random()); - } - - const volume = wantedVol / 100; - msg.guild.musicData.volume = volume; - msg.guild.musicData.songDispatcher.setVolume(volume); - msg.reply(`Volume is now: **${wantedVol}%** ` + emoji.random()); - } -}; \ No newline at end of file diff --git a/package.json b/package.json index cde9cdb..1321c23 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "type": "module", "author": "sin", "license": "MIT", "dependencies": { diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..fb6a9cb --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,67 @@ +{ + "compilerOptions": { + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ + "module": "es2015", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ + // "lib": [], /* Specify library files to be included in the compilation. */ + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + // "outDir": "./", /* Redirect output structure to the directory. */ + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + + /* Advanced Options */ + "resolveJsonModule": true, /* Include modules imported with '.json' extension */ + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + } +} -- cgit v1.2.3