diff --git a/index.js b/index.js index 67c8a2c4..62f88b3e 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -const config = require("./src/struct/config/config.js"); +const config = require("./src/struct/config/config.ts"); if (config.devMode) { config.token = config.devToken; @@ -6,7 +6,7 @@ if (config.devMode) { } const { ShardingManager } = require('discord.js'); -const manager = new ShardingManager('./src/bot.js', { token: config.token, respawn: config.respawn, totalShards: config.shards }); +const manager = new ShardingManager('./src/bot.ts', { token: config.token, respawn: config.respawn, totalShards: config.shards }); console.log('Launching shards...'); manager.spawn(config.shards, config.shardDelay, config.shardTimeout); diff --git a/package.json b/package.json index 783f26c5..b5853eec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "musix", - "version": "3.0.4", + "version": "3.0.5", "description": "V3 for Musix the discord music bot", "main": "./index.js", "scripts": { @@ -35,4 +35,4 @@ "ytdl-core": "^1.0.9", "ytdl-core-discord": "^1.1.0" } -} +} \ No newline at end of file diff --git a/src/bot.js b/src/bot.js deleted file mode 100644 index f0066a36..00000000 --- a/src/bot.js +++ /dev/null @@ -1,2 +0,0 @@ -const MusicClient = require('./struct/client.js'); -const client = new MusicClient({}); \ No newline at end of file diff --git a/src/bot.ts b/src/bot.ts new file mode 100644 index 00000000..21fca982 --- /dev/null +++ b/src/bot.ts @@ -0,0 +1,2 @@ +const MusicClient = require('./struct/client.ts'); +const client = new MusicClient({}); \ No newline at end of file diff --git a/src/commands/bass.js b/src/commands/bass.ts similarity index 100% rename from src/commands/bass.js rename to src/commands/bass.ts diff --git a/src/commands/cmduses.js b/src/commands/cmduses.ts similarity index 100% rename from src/commands/cmduses.js rename to src/commands/cmduses.ts diff --git a/src/commands/end.js b/src/commands/end.ts similarity index 100% rename from src/commands/end.js rename to src/commands/end.ts diff --git a/src/commands/eval.js b/src/commands/eval.ts similarity index 100% rename from src/commands/eval.js rename to src/commands/eval.ts diff --git a/src/commands/help.js b/src/commands/help.ts similarity index 100% rename from src/commands/help.js rename to src/commands/help.ts diff --git a/src/commands/invite.js b/src/commands/invite.ts similarity index 100% rename from src/commands/invite.js rename to src/commands/invite.ts diff --git a/src/commands/join.js b/src/commands/join.ts similarity index 100% rename from src/commands/join.js rename to src/commands/join.ts diff --git a/src/commands/loop.js b/src/commands/loop.ts similarity index 100% rename from src/commands/loop.js rename to src/commands/loop.ts diff --git a/src/commands/loopsong.js b/src/commands/loopsong.ts similarity index 100% rename from src/commands/loopsong.js rename to src/commands/loopsong.ts diff --git a/src/commands/nowplaying.js b/src/commands/nowplaying.ts similarity index 100% rename from src/commands/nowplaying.js rename to src/commands/nowplaying.ts diff --git a/src/commands/pause.js b/src/commands/pause.ts similarity index 100% rename from src/commands/pause.js rename to src/commands/pause.ts diff --git a/src/commands/play.js b/src/commands/play.ts similarity index 79% rename from src/commands/play.js rename to src/commands/play.ts index 95185826..d2c2ed50 100644 --- a/src/commands/play.js +++ b/src/commands/play.ts @@ -35,20 +35,11 @@ module.exports = { client.messages.playlistAdded = client.messages.playlistAdded.replace("%TITLE%", playlist.title); return lmsg.edit(client.messages.playlistAdded); } else { - try { - var video = await youtube.getVideo(url); - } catch (error) { - search(searchString, function (err, res) { - if (err) return console.log(err); - if (res.videos.length === 0) { - msg.channel.send(client.messages.noResults); - } else { - client.funcs.handleVideo(res.videos[0], msg, voiceChannel, client, false); - } - }) - return; - } - return client.funcs.handleVideo(video, msg, voiceChannel, client, false); + search(searchString, function (err, res) { + if (err) return console.log(err); + if (res.videos.length === 0) return msg.channel.send(client.messages.noResults); + client.funcs.handleVideo(res.videos[0], msg, voiceChannel, client, false); + }) } } }; diff --git a/src/commands/queue.js b/src/commands/queue.ts similarity index 100% rename from src/commands/queue.js rename to src/commands/queue.ts diff --git a/src/commands/remove.js b/src/commands/remove.ts similarity index 100% rename from src/commands/remove.js rename to src/commands/remove.ts diff --git a/src/commands/restart.js b/src/commands/restart.ts similarity index 100% rename from src/commands/restart.js rename to src/commands/restart.ts diff --git a/src/commands/resume.js b/src/commands/resume.ts similarity index 100% rename from src/commands/resume.js rename to src/commands/resume.ts diff --git a/src/commands/savedb.js b/src/commands/savedb.ts similarity index 100% rename from src/commands/savedb.js rename to src/commands/savedb.ts diff --git a/src/commands/search.js b/src/commands/search.js deleted file mode 100644 index e41c342e..00000000 --- a/src/commands/search.js +++ /dev/null @@ -1,71 +0,0 @@ -const YouTube = require("simple-youtube-api"); -const he = require('he'); - -module.exports = { - name: 'search', - alias: 'sr', - usage: '', - description: 'Search the top 10 queryes and choose one.', - onlyDev: false, - permission: 'none', - category: 'music', - async execute(msg, args, client, Discord, command) { - const youtube = new YouTube(client.config.api_key); - const searchString = args.slice(1).join(" "); - const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : ""; - const queue = client.queue.get(msg.guild.id); - const voiceChannel = msg.member.voice.channel; - if (!queue) { - if (!msg.member.voice.channel) return msg.channel.send(client.messages.noVoiceChannel); - } else { - if (voiceChannel !== queue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel); - } - if (!args[1]) return msg.channel.send(client.messages.noQuery); - if (voiceChannel.full) return msg.channel.send(client.messages.channelFull); - if (!voiceChannel.joinable) return msg.channel.send(client.messages.noPermsConnect); - if (!voiceChannel.speakable) return msg.channel.send(client.messages.noPermsSpeak); - if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) { - const lmsg = await msg.channel.send(client.messages.loadingSongs); - const playlist = await youtube.getPlaylist(url); - const videos = await playlist.getVideos(); - for (const video of Object.values(videos)) { - const video2 = await youtube.getVideoByID(video.id); - await client.funcs.handleVideo(video2, msg, voiceChannel, client, true); - } - let message; - message = client.messages.playlistAdded.replace("%TITLE%", playlist.title); - return lmsg.edit(message); - } else { - try { - var video = await youtube.getVideo(url); - } catch (error) { - try { - var videos = await youtube.searchVideos(searchString, 10); - let index = 0; - const embed = new Discord.MessageEmbed() - .setTitle(client.messages.songSelection) - .setDescription(`${videos.map(video2 => `**${++index}** ${he.decode(video2.title)} `).join('\n')}`) - .setFooter(client.messages.provideANumber) - .setColor(client.config.embedColor) - msg.channel.send(embed); - try { - var response = await msg.channel.awaitMessages(message2 => message2.content > 0 && message2.content < 11 && message2.author === msg.author, { - max: 1, - time: 10000, - errors: ['time'] - }); - } catch (err) { - console.error(err); - return msg.channel.send(client.messages.cancellingVideoSelection); - } - const videoIndex = parseInt(response.first().content); - var video = await youtube.getVideoByID(videos[videoIndex - 1].id); - } catch (err) { - console.error(err); - return msg.channel.send(client.messages.noResults); - } - } - return client.funcs.handleVideo(video, msg, voiceChannel, client, false); - } - } -}; \ No newline at end of file diff --git a/src/commands/search.ts b/src/commands/search.ts new file mode 100644 index 00000000..3aa89d77 --- /dev/null +++ b/src/commands/search.ts @@ -0,0 +1,51 @@ +const yts = require('yt-search'); +const he = require('he'); + +module.exports = { + name: 'search', + alias: 'sr', + usage: '', + description: 'Search the top 10 queryes and choose one.', + onlyDev: false, + permission: 'none', + category: 'music', + async execute(msg, args, client, Discord, command) { + const searchString = args.slice(1).join(" "); + const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : ""; + const queue = client.queue.get(msg.guild.id); + const voiceChannel = msg.member.voice.channel; + if (!queue) { + if (!msg.member.voice.channel) return msg.channel.send(client.messages.noVoiceChannel); + } else { + if (voiceChannel !== queue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel); + } + if (!args[1]) return msg.channel.send(client.messages.noQuery); + if (voiceChannel.full) return msg.channel.send(client.messages.channelFull); + if (!voiceChannel.joinable) return msg.channel.send(client.messages.noPermsConnect); + if (!voiceChannel.speakable) return msg.channel.send(client.messages.noPermsSpeak); + yts(searchString, async function (err, res) { + if (err) return console.log(err); + if (res.videos.length === 0) return msg.channel.send(client.messages.noResults); + const videos = res.videos.slice(0, 10); + let index = 0; + const embed = new Discord.MessageEmbed() + .setTitle(client.messages.songSelection) + .setDescription(`${videos.map(video2 => `**${++index}** ${he.decode(video2.title)} `).join('\n')}`) + .setFooter(client.messages.provideANumber) + .setColor(client.config.embedColor) + msg.channel.send(embed); + try { + var response = await msg.channel.awaitMessages(message2 => message2.content > 0 && message2.content < 11 && message2.author === msg.author, { + max: 1, + time: 10000, + errors: ['time'] + }); + } catch (err) { + console.error(err); + return msg.channel.send(client.messages.cancellingVideoSelection); + } + const videoIndex = parseInt(response.first().content) - 1; + return client.funcs.handleVideo(videos[videoIndex], msg, voiceChannel, client, false); + }) + } +}; \ No newline at end of file diff --git a/src/commands/seek.js b/src/commands/seek.ts similarity index 100% rename from src/commands/seek.js rename to src/commands/seek.ts diff --git a/src/commands/settings.js b/src/commands/settings.ts similarity index 100% rename from src/commands/settings.js rename to src/commands/settings.ts diff --git a/src/commands/settings/announcesongs.js b/src/commands/settings/announcesongs.ts similarity index 100% rename from src/commands/settings/announcesongs.js rename to src/commands/settings/announcesongs.ts diff --git a/src/commands/settings/bass.js b/src/commands/settings/bass.ts similarity index 100% rename from src/commands/settings/bass.js rename to src/commands/settings/bass.ts diff --git a/src/commands/settings/permissions.js b/src/commands/settings/permissions.ts similarity index 100% rename from src/commands/settings/permissions.js rename to src/commands/settings/permissions.ts diff --git a/src/commands/settings/prefix.js b/src/commands/settings/prefix.ts similarity index 100% rename from src/commands/settings/prefix.js rename to src/commands/settings/prefix.ts diff --git a/src/commands/settings/reset.js b/src/commands/settings/reset.ts similarity index 100% rename from src/commands/settings/reset.js rename to src/commands/settings/reset.ts diff --git a/src/commands/settings/setDj.js b/src/commands/settings/setDj.ts similarity index 100% rename from src/commands/settings/setDj.js rename to src/commands/settings/setDj.ts diff --git a/src/commands/settings/volume.js b/src/commands/settings/volume.ts similarity index 100% rename from src/commands/settings/volume.js rename to src/commands/settings/volume.ts diff --git a/src/commands/shuffle.js b/src/commands/shuffle.ts similarity index 100% rename from src/commands/shuffle.js rename to src/commands/shuffle.ts diff --git a/src/commands/skip.js b/src/commands/skip.ts similarity index 100% rename from src/commands/skip.js rename to src/commands/skip.ts diff --git a/src/commands/skipto.js b/src/commands/skipto.ts similarity index 92% rename from src/commands/skipto.js rename to src/commands/skipto.ts index 073926e6..c9ee7c59 100644 --- a/src/commands/skipto.js +++ b/src/commands/skipto.ts @@ -10,7 +10,8 @@ module.exports = { const queue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { if (!args[1]) return msg.channel.send(`${client.messages.correctUsage}\`${command.usage}\``); - const point = parseInt(args[1] - 1); + let point = parseInt(args[1]); + point = point - 1; if (isNaN(point)) return msg.channel.send(client.messages.validNumber); if (point > queue.songs.size) return msg.channel.send(client.messages.noSongs); if (point < 0) return msg.channel.send(client.messages.cantSkipToCurrent); diff --git a/src/commands/status.js b/src/commands/status.ts similarity index 100% rename from src/commands/status.js rename to src/commands/status.ts diff --git a/src/commands/stop.js b/src/commands/stop.ts similarity index 100% rename from src/commands/stop.js rename to src/commands/stop.ts diff --git a/src/commands/volume.js b/src/commands/volume.ts similarity index 100% rename from src/commands/volume.js rename to src/commands/volume.ts diff --git a/src/events/clientEvents/guildCreate.js b/src/events/clientEvents/guildCreate.ts similarity index 100% rename from src/events/clientEvents/guildCreate.js rename to src/events/clientEvents/guildCreate.ts diff --git a/src/events/clientEvents/msg.js b/src/events/clientEvents/msg.ts similarity index 100% rename from src/events/clientEvents/msg.js rename to src/events/clientEvents/msg.ts diff --git a/src/events/clientEvents/ready.js b/src/events/clientEvents/ready.ts similarity index 100% rename from src/events/clientEvents/ready.js rename to src/events/clientEvents/ready.ts diff --git a/src/events/clientEvents/voiceStateUpdate.js b/src/events/clientEvents/voiceStateUpdate.ts similarity index 100% rename from src/events/clientEvents/voiceStateUpdate.js rename to src/events/clientEvents/voiceStateUpdate.ts diff --git a/src/events/dispatcherEvents/error.js b/src/events/dispatcherEvents/error.ts similarity index 100% rename from src/events/dispatcherEvents/error.js rename to src/events/dispatcherEvents/error.ts diff --git a/src/events/dispatcherEvents/finish.js b/src/events/dispatcherEvents/finish.ts similarity index 100% rename from src/events/dispatcherEvents/finish.js rename to src/events/dispatcherEvents/finish.ts diff --git a/src/events/events.js b/src/events/events.ts similarity index 62% rename from src/events/events.js rename to src/events/events.ts index 53472a4d..82a62f1c 100644 --- a/src/events/events.js +++ b/src/events/events.ts @@ -2,16 +2,16 @@ module.exports = function (client) { const Discord = require('discord.js'); const events = './clientEvents/'; client.on('ready', () => { - require(`${events}ready`).execute(client, Discord); + require(`${events}ready.ts`).execute(client, Discord); }); client.on('message', (msg) => { - require(`${events}msg`).execute(client, msg, Discord); + require(`${events}msg.ts`).execute(client, msg, Discord); }); client.on('guildCreate', (guild) => { - require(`${events}guildCreate`).execute(client, guild); + require(`${events}guildCreate.ts`).execute(client, guild); }); client.on('voiceStateUpdate', (oldState, newState) => { - require(`${events}voiceStateUpdate`).execute(client, oldState, newState); + require(`${events}voiceStateUpdate.ts`).execute(client, oldState, newState); }); client.on('error', (error) => { client.channels.fetch(client.config.debug_channel).send(`Error: ${error} on shard: ${client.shard}`); diff --git a/src/struct/client.js b/src/struct/client.ts similarity index 86% rename from src/struct/client.js rename to src/struct/client.ts index d660fe2d..bf74e137 100644 --- a/src/struct/client.js +++ b/src/struct/client.ts @@ -3,7 +3,7 @@ const admin = require('firebase-admin'); const serviceAccount = require('./config/serviceAccount.json'); const fs = require('fs'); const path = require('path'); -const events = require('../events/events.js'); +const events = require('../events/events.ts'); module.exports = class extends Client { constructor() { @@ -21,12 +21,12 @@ module.exports = class extends Client { this.queue = new Map(); this.funcs = {}; this.dispatcher = {}; - this.config = require('./config/config.js'); - this.messages = require('./config/messages.js'); + this.config = require('./config/config.ts'); + this.messages = require('./config/messages.ts'); this.db = admin.firestore(); this.db.FieldValue = require('firebase-admin').firestore.FieldValue; - this.dispatcher.finish = require('../events/dispatcherEvents/finish.js'); - this.dispatcher.error = require('../events/dispatcherEvents/error.js'); + this.dispatcher.finish = require('../events/dispatcherEvents/finish.ts'); + this.dispatcher.error = require('../events/dispatcherEvents/error.ts'); this.global = { db: { guilds: {}, @@ -37,14 +37,14 @@ module.exports = class extends Client { this.funcs[filename.slice(0, -3)] = require(`./funcs/${filename}`); }); - const commandFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands')).filter(f => f.endsWith('.js')); + const commandFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands')).filter(f => f.endsWith('.ts')); for (const file of commandFiles) { const command = require(`../commands/${file}`); command.uses = 0; this.commands.set(command.name, command); this.commandAliases.set(command.alias, command); } - const settingFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands/settings')).filter(f => f.endsWith('.js')); + const settingFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands/settings')).filter(f => f.endsWith('.ts')); for (const file of settingFiles) { const option = require(`../commands/settings/${file}`); this.settingCmd.set(option.name, option); diff --git a/src/struct/config/config.js b/src/struct/config/config.ts similarity index 97% rename from src/struct/config/config.js rename to src/struct/config/config.ts index dbd0b344..8d2550a4 100644 --- a/src/struct/config/config.js +++ b/src/struct/config/config.ts @@ -13,7 +13,7 @@ module.exports = { embedColor: "#b50002", invite: "https://discordapp.com/oauth2/authorize?client_id=607266889537945605&permissions=3427328&scope=bot", supportServer: "https://discord.gg/rvHuJtB", - devMode: false, + devMode: true, dblApi: false, saveDB: true, respawn: true, diff --git a/src/struct/config/messages.js b/src/struct/config/messages.ts similarity index 100% rename from src/struct/config/messages.js rename to src/struct/config/messages.ts diff --git a/src/struct/config/queueConfig.js b/src/struct/config/queueConfig.ts similarity index 100% rename from src/struct/config/queueConfig.js rename to src/struct/config/queueConfig.ts diff --git a/src/struct/config/streamConfig.js b/src/struct/config/streamConfig.ts similarity index 100% rename from src/struct/config/streamConfig.js rename to src/struct/config/streamConfig.ts diff --git a/src/struct/funcs/check.js b/src/struct/funcs/check.ts similarity index 100% rename from src/struct/funcs/check.js rename to src/struct/funcs/check.ts diff --git a/src/struct/funcs/checkDB.js b/src/struct/funcs/checkDB.ts similarity index 100% rename from src/struct/funcs/checkDB.js rename to src/struct/funcs/checkDB.ts diff --git a/src/struct/funcs/dbget.js b/src/struct/funcs/dbget.ts similarity index 100% rename from src/struct/funcs/dbget.js rename to src/struct/funcs/dbget.ts diff --git a/src/struct/funcs/exe.js b/src/struct/funcs/exe.ts similarity index 100% rename from src/struct/funcs/exe.js rename to src/struct/funcs/exe.ts diff --git a/src/struct/funcs/ffmpeg.js b/src/struct/funcs/ffmpeg.ts similarity index 100% rename from src/struct/funcs/ffmpeg.js rename to src/struct/funcs/ffmpeg.ts diff --git a/src/struct/funcs/handleVideo.js b/src/struct/funcs/handleVideo.ts similarity index 95% rename from src/struct/funcs/handleVideo.js rename to src/struct/funcs/handleVideo.ts index 3101954f..5bbc06f8 100644 --- a/src/struct/funcs/handleVideo.js +++ b/src/struct/funcs/handleVideo.ts @@ -16,7 +16,7 @@ module.exports = async function (video, msg, voiceChannel, client, playlist = fa return msg.channel.send(message); } - const construct = require("../config/queueConfig.js"); + const construct = require("../config/queueConfig.ts"); construct.textChannel = msg.channel; construct.voiceChannel = voiceChannel; diff --git a/src/struct/funcs/msToTime.js b/src/struct/funcs/msToTime.ts similarity index 81% rename from src/struct/funcs/msToTime.js rename to src/struct/funcs/msToTime.ts index 3247cb7e..a771b8d2 100644 --- a/src/struct/funcs/msToTime.js +++ b/src/struct/funcs/msToTime.ts @@ -1,8 +1,8 @@ module.exports = function msToTime(duration, format) { var seconds = Math.floor((duration / 1000) % 60), minutes = Math.floor((duration / (1000 * 60)) % 60), - hours = Math.floor((duration / (1000 * 60 * 60)) % 24); - days = Math.floor((duration / (1000 * 60 * 60 * 24)) % 24); + hours = Math.floor((duration / (1000 * 60 * 60)) % 24), + days = Math.floor((duration / (1000 * 60 * 60 * 24)) % 24); days = (days < 10) ? "0" + days : days; hours = (hours < 10) ? "0" + hours : hours; diff --git a/src/struct/funcs/play.js b/src/struct/funcs/play.ts similarity index 94% rename from src/struct/funcs/play.js rename to src/struct/funcs/play.ts index 2540bc91..5b62bcf5 100644 --- a/src/struct/funcs/play.js +++ b/src/struct/funcs/play.ts @@ -1,7 +1,7 @@ module.exports = async function (guild, song, client, seek, play) { const Discord = require('discord.js'); const ytdl = require('ytdl-core'); - const streamConfig = require("../config/streamConfig.js"); + const streamConfig = require("../config/streamConfig.ts"); const getThumb = require('video-thumbnail-url'); const prism = require('prism-media'); @@ -20,7 +20,7 @@ module.exports = async function (guild, song, client, seek, play) { "-f", "s16le", "-ar", "48000", "-ac", "2", - "-af", `bass=g=${queue.bass}` + "-af", `bass=g=${queue.bass}`, ]; const transcoder = new prism.FFmpeg({ args: ffmpegArgs }); diff --git a/src/struct/funcs/saveDB.js b/src/struct/funcs/saveDB.ts similarity index 100% rename from src/struct/funcs/saveDB.js rename to src/struct/funcs/saveDB.ts diff --git a/src/struct/funcs/shuffle.js b/src/struct/funcs/shuffle.ts similarity index 100% rename from src/struct/funcs/shuffle.js rename to src/struct/funcs/shuffle.ts diff --git a/src/struct/funcs/urlMatch.js b/src/struct/funcs/urlMatch.ts similarity index 100% rename from src/struct/funcs/urlMatch.js rename to src/struct/funcs/urlMatch.ts