diff options
| author | Alee <alee14498@gmail.com> | 2018-06-24 22:36:58 -0400 |
|---|---|---|
| committer | Alee <alee14498@gmail.com> | 2018-06-24 22:36:58 -0400 |
| commit | 2783ab5634b54492c2d487d11bcacad767f57833 (patch) | |
| tree | fc5f0b314e0d0be5eb7535dd2f4701efaef5b874 | |
| parent | 1abdcfe8c1ec71b8a432f36fc60555431c2a247d (diff) | |
| download | AleeBot-2783ab5634b54492c2d487d11bcacad767f57833.tar.gz AleeBot-2783ab5634b54492c2d487d11bcacad767f57833.tar.bz2 AleeBot-2783ab5634b54492c2d487d11bcacad767f57833.zip | |
Added music back (finally) and changed from 2.10.1 to 2.11.0 Beta
| -rw-r--r-- | bot_discord.js | 12 | ||||
| -rw-r--r-- | commands/help.js | 2 | ||||
| -rw-r--r-- | commands/leave.js | 25 | ||||
| -rw-r--r-- | commands/leaveguild.js | 36 | ||||
| -rw-r--r-- | commands/play.js | 122 | ||||
| -rw-r--r-- | commands/queue.js | 49 | ||||
| -rw-r--r-- | commands/skip.js | 62 | ||||
| -rw-r--r-- | package-lock.json | 92 | ||||
| -rw-r--r-- | package.json | 4 | ||||
| -rw-r--r-- | storage/settings.json | 2 |
10 files changed, 392 insertions, 14 deletions
diff --git a/bot_discord.js b/bot_discord.js index 2ebbc62..45da5ea 100644 --- a/bot_discord.js +++ b/bot_discord.js @@ -30,6 +30,8 @@ const fs = require('fs'); const db = require('quick.db');
const api = require('./tokens.json');
const dbl = new DBL(api.dbltoken, client);
+const active = new Map();
+const ownerID = "242775871059001344";
const log = message => {
@@ -160,7 +162,7 @@ rl.on('line', function(cmd){ console.log(msg.cyan);
break;
default:
- console.log('Unknown Command type \'help\' to list the commands...'.yellow)
+ console.log('Unknown command, type \'help\' to list the commands...'.yellow)
}
rl.prompt();
});
@@ -245,7 +247,13 @@ client.on('message', (msg) => { }
}
try {
- cmd.run(client, msg, args);
+
+ let ops = {
+ ownerID: ownerID,
+ active: active
+ }
+
+ cmd.run(client, msg, args, ops);
}
catch (e) {
console.error(e);
diff --git a/commands/help.js b/commands/help.js index 182c618..318e5e2 100644 --- a/commands/help.js +++ b/commands/help.js @@ -40,7 +40,7 @@ module.exports.run = async (client, message) => { let prefix = prefixes[message.guild.id].prefixes
const embed = new Discord.RichEmbed()
- .setAuthor('AleeBot ' + require('../storage/settings.json').abVersion + ` Help and on ${client.guilds.size} servers`, 'https://cdn.discordapp.com/avatars/282547024547545109/6c147a444ae328c38145ef1f74169e38.png?size=2048')
+ .setAuthor('AleeBot ' + require('../storage/settings.json').abVersion + ` Help and on ${client.guilds.size} servers`, client.user.avatarURL)
.setDescription('Every command you input into AleeBot is `' + prefix + '`')
.setColor('#1fd619')
.setFooter('AleeCorp Copyright 2018, Licensed with GPL-3.0');
diff --git a/commands/leave.js b/commands/leave.js index 9a54555..a2a48d8 100644 --- a/commands/leave.js +++ b/commands/leave.js @@ -1,7 +1,7 @@ /**************************************** * * Leave: Command for AleeBot - * Copyright (C) 2018 AleeCorp + * Copyright (C) 2018 AleeCorp & (your name here) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,10 +17,18 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * * *************************************/ -module.exports.run = async (client, message) => { - if (!['242775871059001344', message.guild.owner.user.id].includes(message.author.id)) return message.reply('Nope! You need the person who created this bot or the owner of this guild to use this command.'); - message.channel.send('Alright, I\'m leaving the server now. Bye everyone!') - message.guild.leave(); + +module.exports.run = async (client, message, args) => { + if (!message.member.voiceChannel) return message.reply('You need a voice channel to perform this action.'); + + if (!message.guild.me.voiceChannel) return message.reply('Error: The bot isn\'t connected to a voice channel.') + + if (message.guild.me.voiceChannelID !== message.member.voiceChannelID) return message.reply('Error: You aren\'t connected in the same voice channel as the bot...'); + + message.guild.me.voiceChannel.leave(); + + message.channel.send("Leaving channel...") + }; exports.conf = { @@ -29,8 +37,7 @@ module.exports.run = async (client, message) => { }; exports.help = { name: 'leave', - description: 'Makes the bot leave the server', + description: 'Leaves voice chat.', usage: 'leave', - category: '- Owners Only', - }; -
\ No newline at end of file + category: '- Music Commands', + };
\ No newline at end of file diff --git a/commands/leaveguild.js b/commands/leaveguild.js new file mode 100644 index 0000000..ee0be0e --- /dev/null +++ b/commands/leaveguild.js @@ -0,0 +1,36 @@ +/**************************************** + * + * LeaveGuild: Command for AleeBot + * Copyright (C) 2018 AleeCorp + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * *************************************/ +module.exports.run = async (client, message) => { + if (!['242775871059001344', message.guild.owner.user.id].includes(message.author.id)) return message.reply('Nope! You need the person who created this bot or the owner of this guild to use this command.'); + message.channel.send('Alright, I\'m leaving the server now. Bye everyone!') + message.guild.leave(); + }; + + exports.conf = { + aliases: [], + guildOnly: false, + }; + exports.help = { + name: 'leaveguild', + description: 'Makes the bot leave the server', + usage: 'leaveguild', + category: '- Owners Only', + }; +
\ No newline at end of file diff --git a/commands/play.js b/commands/play.js new file mode 100644 index 0000000..06ca7f1 --- /dev/null +++ b/commands/play.js @@ -0,0 +1,122 @@ +/**************************************** + * + * Play: Command for AleeBot + * Copyright (C) 2018 AleeCorp & (your name here) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * *************************************/ + +module.exports.run = async (client, message, args, ops) => { + const ytdl = require('ytdl-core'); + + if (!message.member.voiceChannel) return message.reply('Please connect to a voice channel...'); + + if (!args[0]) return message.reply('Please input a url.'); + + let vaildate = await ytdl.validateURL(args[0]); + + if (!vaildate) return message.reply('Please input a **valid** url.'); + + let info = await ytdl.getInfo(args[0]); + + let data = ops.active.get(message.guild.id) || {}; + + if (!data.connection) data.connection = await message.member.voiceChannel.join(); + if (!data.queue) data.queue = []; + data.guildID = message.guild.id; + + data.queue.push({ + songTitle: info.title, + requester: message.author.tag, + url: args[0], + announceChannel: message.channel.id + }); + if (!data.dispatcher) play(client, ops, data); + else { + const { RichEmbed } = require('discord.js'); + const embed = new RichEmbed() + .setTitle('This music has been added to the queue!') + .setAuthor(info.title, client.user.avatarURL) + .setColor(0x00afff) + .setTimestamp() + .addField('Title', info.title) + .addField('Requested by:', message.author.tag) + .setFooter('AleeBot Music Player'); + + message.channel.send({embed}) + } + + ops.active.set(message.guild.id, data); + + }; + + async function play(client, ops, data) { + const ytdl = require('ytdl-core'); + const { RichEmbed } = require('discord.js'); + const embed = new RichEmbed() + .setTitle('Now playing!') + .setAuthor(data.queue[0].songTitle, client.user.avatarURL) + .setColor(0x00afff) + .setTimestamp() + .addField('Title', data.queue[0].songTitle) + .addField('Requested by:', data.queue[0].requester) + // .addField('Link', info.url) + // .addField('Duration', time) + .setFooter('AleeBot Music Player'); + + client.channels.get(data.queue[0].announceChannel).send({embed}) + + data.dispatcher = await data.connection.playStream(ytdl(data.queue[0].url, { filter: 'audioonly'})); + data.dispatcher.guildID = data.guildID; + + data.dispatcher.once('finish', function () { + finish(client, ops, this); + }); + + }; + + function finish(client, ops, dispatcher) { + + let fetched = ops.active.get(dispatcher.guildID); + + fetched.queue.shift(); + + if (fetched.queue.length > 0) { + + ops.active.set(dispatcher.guildID, fetched); + + play(client, ops, fetched); + + } else { + ops.active.delete(dispatcher.guildID); + + let vc = client.guild.get(dispatcher.guildID).me.voiceChannel; + + if (vc) vc.leave(); + + } + + } + + exports.conf = { + aliases: [], + guildOnly: false, + }; + exports.help = { + name: 'play', + description: 'Plays music.', + usage: 'play [url]', + category: '- Music Commands', + };
\ No newline at end of file diff --git a/commands/queue.js b/commands/queue.js new file mode 100644 index 0000000..67faf91 --- /dev/null +++ b/commands/queue.js @@ -0,0 +1,49 @@ +/**************************************** + * + * Queue: Command for AleeBot + * Copyright (C) 2018 AleeCorp & (your name here) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * *************************************/ + +module.exports.run = async (client, message, args, ops) => { + + let fetched = ops.active.get(message.guild.id); + + if (!fetched) return message.reply('Currently, there isn\'t any music playing in this guild.'); + + let queue = fetched.queue + let nowPlaying = queue[0]; + + let resp = `__**Now Playing**__\n**${nowPlaying.songTitle}** -- **Requested By:** *${nowPlaying.requester}*\n\n__**Queue**__\n`; + + for (var i = 1; i < queue.length; i++) { + resp += `${i}. **${queue[i].songTitle}** -- **Requested By:** *${queue[i].requester}*\n` + } + + message.channel.send(resp); + + }; + + exports.conf = { + aliases: [], + guildOnly: false, + }; + exports.help = { + name: 'queue', + description: 'Checks what music is in queue.', + usage: 'queue', + category: '- Music Commands', + };
\ No newline at end of file diff --git a/commands/skip.js b/commands/skip.js new file mode 100644 index 0000000..c1402cc --- /dev/null +++ b/commands/skip.js @@ -0,0 +1,62 @@ +/**************************************** + * + * Skip: Command for AleeBot + * Copyright (C) 2018 AleeCorp & (your name here) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * *************************************/ + +module.exports.run = async (client, message, args, ops) => { + + let fetched = ops.active.get(message.guild.id); + + if (!fetched) return message.reply('Currently, there isn\'t any music playing in this guild.'); + + if (message.member.voiceChannel !== message.guild.me.voiceChannel) return message.reply('Sorry, you are currently not in the same channel as the bot.') + + let userCount = message.member.voiceChannel.members.size; + + let required = Math.ceil(userCount/2); + + if (!fetched.queue[0].voteSkips) fetched.queue[0].voteSkips = []; + + if (fetched.queue[0].voteSkips.includes(message.member.id)) return message.reply(`Sorry, you have already voted to skip! ${fetched.queue[0].voteSkips.length}/${required} required.`) + + fetched.queue[0].voteSkips.push(message.member.id); + + ops.active.set(message.guild.id, fetched); + + if (fetched.queue[0].voteSkips.length >= required) { + + message.channel.send('Successfully skipped song!'); + + return fetched.dispatcher.emit('finish'); + + } + + message.channel.send(`Successfully voted to skip! ${fetched.queue[0].voteSkips.length}/${required} required.`) + + }; + + exports.conf = { + aliases: [], + guildOnly: false, + }; + exports.help = { + name: 'skip', + description: 'Skips a music.', + usage: 'skip', + category: '- Music Commands', + };
\ No newline at end of file diff --git a/package-lock.json b/package-lock.json index dd69929..1480897 100644 --- a/package-lock.json +++ b/package-lock.json @@ -112,6 +112,11 @@ "resolved": "https://registry.npmjs.org/colors/-/colors-1.3.0.tgz", "integrity": "sha512-EDpX3a7wHMWFA7PUHWPHNWqOxIIRSJetuwl0AS5Oi/5FMV8kWm69RTlgm00GKjBO1xFHMtBbL49yRtMMdticBw==" }, + "commander": { + "version": "2.15.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz", + "integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==" + }, "component-bind": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/component-bind/-/component-bind-1.0.0.tgz", @@ -386,6 +391,11 @@ "resolved": "https://registry.npmjs.org/has-cors/-/has-cors-1.1.0.tgz", "integrity": "sha1-XkdHk/fqmEPRu5nCPu9J/xJv/zk=" }, + "html-entities": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/html-entities/-/html-entities-1.2.1.tgz", + "integrity": "sha1-DfKTUfByEWNRXfueVUPl9u7VFi8=" + }, "http-errors": { "version": "1.6.3", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz", @@ -450,6 +460,14 @@ "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==" }, + "m3u8stream": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/m3u8stream/-/m3u8stream-0.2.2.tgz", + "integrity": "sha512-R/xWLXBtVr0m9sPruRL4p9uO01JyHxhcQ4nhqQhVgyT802OZyVW+dn+fWHvTnbfE6YMLc65TksZZut+Mh2OVMQ==", + "requires": { + "miniget": "^1.1.0" + } + }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -483,6 +501,11 @@ "mime-db": "~1.33.0" } }, + "miniget": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/miniget/-/miniget-1.2.0.tgz", + "integrity": "sha1-ADY3Oia71S2+aUX85sjAOR6eEkE=" + }, "moment": { "version": "2.22.2", "resolved": "https://registry.npmjs.org/moment/-/moment-2.22.2.tgz", @@ -493,16 +516,48 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, + "nan": { + "version": "2.10.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.10.0.tgz", + "integrity": "sha512-bAdJv7fBLhWC+/Bls0Oza+mvTaNQtP+1RyhhhvD95pgUJz6XM5IzgmxOkItJ9tkoCiplvAnXI1tNmmUD/eScyA==" + }, "negotiator": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" }, + "node-opus": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/node-opus/-/node-opus-0.3.0.tgz", + "integrity": "sha512-Hih2TCi/vQUY4D9PBiATT6fluJSjMJPLBfCNgAxJx03v6jT+UlVmXUKR62RXYWyijhXNghsFJMyeBe7MBm3cmQ==", + "requires": { + "bindings": "~1.2.1", + "commander": "^2.9.0", + "nan": "^2.10.0", + "ogg-packet": "^1.0.0" + }, + "dependencies": { + "bindings": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.2.1.tgz", + "integrity": "sha1-FK1hE4EtLTfXLme0ystLtyZQXxE=" + } + } + }, "object-component": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/object-component/-/object-component-0.0.3.tgz", "integrity": "sha1-8MaapQ78lbhmwYb0AKM3acsvEpE=" }, + "ogg-packet": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/ogg-packet/-/ogg-packet-1.0.0.tgz", + "integrity": "sha1-RbiFchrI991c8iOR1CEGrlM6xng=", + "optional": true, + "requires": { + "ref-struct": "*" + } + }, "on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", @@ -623,11 +678,37 @@ "resolved": "https://registry.npmjs.org/readline/-/readline-1.3.0.tgz", "integrity": "sha1-xYDXfvLPyHUrEySYBg3JeTp6wBw=" }, + "ref": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/ref/-/ref-1.3.5.tgz", + "integrity": "sha512-2cBCniTtxcGUjDpvFfVpw323a83/0RLSGJJY5l5lcomZWhYpU2cuLdsvYqMixvsdLJ9+sTdzEkju8J8ZHDM2nA==", + "optional": true, + "requires": { + "bindings": "1", + "debug": "2", + "nan": "2" + } + }, + "ref-struct": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/ref-struct/-/ref-struct-1.1.0.tgz", + "integrity": "sha1-XV7mWtQc78Olxf60BYcmHkee3BM=", + "optional": true, + "requires": { + "debug": "2", + "ref": "1" + } + }, "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, + "sax": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", + "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" + }, "send": { "version": "0.16.2", "resolved": "https://registry.npmjs.org/send/-/send-0.16.2.tgz", @@ -810,6 +891,17 @@ "version": "0.1.2", "resolved": "https://registry.npmjs.org/yeast/-/yeast-0.1.2.tgz", "integrity": "sha1-AI4G2AlDIMNy28L47XagymyKxBk=" + }, + "ytdl-core": { + "version": "0.20.4", + "resolved": "https://registry.npmjs.org/ytdl-core/-/ytdl-core-0.20.4.tgz", + "integrity": "sha512-d+jthiJxSQ6yqCeCwwMggXYOjFSOJsD7ahvAAE1sFW9nVNnsA/roz91SFH1FzaMGS7/y7AnJfhVgpE9i8uYjJQ==", + "requires": { + "html-entities": "^1.1.3", + "m3u8stream": "^0.2.1", + "miniget": "^1.1.0", + "sax": "^1.1.3" + } } } } diff --git a/package.json b/package.json index 2b778c0..7764612 100644 --- a/package.json +++ b/package.json @@ -24,10 +24,12 @@ "fs": "0.0.1-security", "git-last-commit": "^0.3.0", "moment": "^2.21.0", + "node-opus": "^0.3.0", "os": "^0.1.1", "parse-ms": "^1.0.1", "quick.db": "^6.3.1", - "readline": "^1.3.0" + "readline": "^1.3.0", + "ytdl-core": "^0.20.4" }, "devDependencies": {} } diff --git a/storage/settings.json b/storage/settings.json index 921cd68..e8f0527 100644 --- a/storage/settings.json +++ b/storage/settings.json @@ -1,4 +1,4 @@ { - "abVersion": "2.10.1 Beta", + "abVersion": "2.11.0 Beta", "prefix": "abb:" } |
