Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const http = require('http');
- const express = require('express');
- const app = express();
- app.get("/", (request, response) => {
- response.sendStatus(200);
- });
- app.listen(process.env.PORT);
- setInterval(() => {
- http.get(`http://${process.env.PROJECT_DOMAIN}.glitch.me/`);
- }, 280000);
- //ABOVE THIS IS ALL GLITCH STUFF
- const Discord = require('discord.js');
- const yt = require('ytdl-core');
- const tokens = require('./tokens.json');
- const dbl = require("dblposter");
- const client = new Discord.Client();
- var randomColor = require('randomcolor');
- var search = require('youtube-search');
- const DBLPoster = new dbl(`eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjM3MDI3NDU5ODU1OTY3ODQ2NyIsImJvdCI6dHJ1ZSwiaWF0IjoxNTE5NTcwOTY4fQ.6swOzBO_I8lh82_BN77CKiJMbKZK4l8x5EZVE8ldzVU`);
- var opts = {
- maxResults: 1,
- key: process.env.APIKEY,
- type: "video"
- };
- let queue = {};
- const commands = {
- 'play': (msg) => {
- if (queue[msg.guild.id] === undefined) return msg.channel.send("Añade primero la cancion pon: `%add`");
- if (!msg.guild.voiceConnection) return commands.join(msg).then(() => commands.play(msg));
- if (queue[msg.guild.id].playing) return msg.channel.send('Esa Cancion Ya Esta Sonando');
- let dispatcher;
- queue[msg.guild.id].playing = true;
- (function play(song) {
- if (song === undefined) return msg.channel.send('La Lista Esta Vacia Añade Canciones Poniendo `%add`.').then(() => {
- queue[msg.guild.id].playing = false;
- msg.member.voiceChannel.leave();
- });
- msg.channel.send(`Reproduciendose: **${song.title}** Pedida Por: **${song.requester}**`);
- dispatcher = msg.guild.voiceConnection.playStream(yt(song.url, { filter: "audioonly" }), { passes : tokens.passes });
- let collector = msg.channel.createCollector(m => m);
- collector.on('message', m => {
- if (m.content.startsWith(tokens.prefix + 'pause')) {
- msg.channel.send('paused').then(() => {dispatcher.pause();});
- return
- } else if (m.content.startsWith(tokens.prefix + 'resume')){
- msg.channel.send('resumed').then(() => {dispatcher.resume();});
- return
- } else if (m.content.startsWith(tokens.prefix + 'skip')){
- msg.channel.send('Skipped song.').then(() => {dispatcher.end();});
- return
- } else if (m.content.startsWith(tokens.prefix + 'volume')){
- if (Math.round(dispatcher.volume*50) <= 0) return msg.channel.send(`Volume: ${Math.round(dispatcher.volume*50)}`);
- dispatcher.setVolume(Math.max(((m.content.split(' ')[1])))/50,0);
- msg.channel.send(`Volume: ${Math.round(dispatcher.volume*50)}`);
- return
- } else if (m.content.startsWith(tokens.prefix + 'time')){
- msg.channel.send(`Current position: ${Math.floor(dispatcher.time / 60000)}:${Math.floor((dispatcher.time % 60000)/1000) <10 ? '0'+Math.floor((dispatcher.time % 60000)/1000) : Math.floor((dispatcher.time % 60000)/1000)}`);
- return
- }
- });
- dispatcher.on('end', () => {
- collector.stop();
- play(queue[msg.guild.id].songs.shift());
- });
- dispatcher.on('error', (err) => {
- return msg.channel.send('error: ' + err).then(() => {
- collector.stop();
- play(queue[msg.guild.id].songs.shift());
- });
- });
- })(queue[msg.guild.id].songs.shift());
- },
- 'ping': (msg) => { msg.channel.send('Pong! Heartbeat: ' + String(parseInt(client.ping)) + 'ms'); },
- 'pause': (msg) => {if (queue[msg.guild.id] === undefined && !queue[msg.guild.id].playing) msg.channel.send("Este comando sólo se puede usar mientras se está reproduciendo algo.");},
- 'resume': (msg) => {if (queue[msg.guild.id] === undefined && !queue[msg.guild.id].playing) msg.channel.send("Este comando sólo se puede usar mientras se está reproduciendo algo.");},
- 'skip': (msg) => {if (queue[msg.guild.id] === undefined && !queue[msg.guild.id].playing) msg.channel.send("Este comando sólo se puede usar mientras se está reproduciendo algo.");},
- 'volume': (msg) => {if (queue[msg.guild.id] === undefined && !queue[msg.guild.id].playing) msg.channel.send("Este comando sólo se puede usar mientras se está reproduciendo algo.");},
- 'time': (msg) => {if (queue[msg.guild.id] === undefined && !queue[msg.guild.id].playing) msg.channel.send("Este comando sólo se puede usar mientras se está reproduciendo algo.");},
- 'join': (msg) => {
- return new Promise((resolve, reject) => {
- const voiceChannel = msg.member.voiceChannel;
- if (!voiceChannel || voiceChannel.type !== 'voice') {
- msg.channel.send('No pude conectarme a tu canal de voz. Asegúrate de que estás en un canal de voz y que tengo permisos para hablar y conectarme a él.')
- return false
- };
- voiceChannel.join().then(connection => resolve(connection)).catch(err => reject(err));
- });
- },
- 'add': (msg) => {
- let url = msg.content.split(' ')[1];
- let args = msg.content.replace("%add ", "")
- if (url == '' || url === undefined) return msg.channel.send(`Debe agregar una url de vídeo de YouTube, o id después de ${tokens.prefix}add`);
- yt.getInfo(url, (err, info) => {
- if(err) {
- search(args, opts, function(err, results) {
- if(err) return console.log(err);
- if (!queue.hasOwnProperty(msg.guild.id)) queue[msg.guild.id] = {}, queue[msg.guild.id].playing = false, queue[msg.guild.id].songs = [];
- queue[msg.guild.id].songs.push({url: results[0].link, title: results[0].title, requester: msg.author.username});
- msg.channel.send("Añadida **" + results[0].link + "** a la lista.");
- });
- return
- };
- if (!queue.hasOwnProperty(msg.guild.id)) queue[msg.guild.id] = {}, queue[msg.guild.id].playing = false, queue[msg.guild.id].songs = [];
- queue[msg.guild.id].songs.push({url: url, title: info.title, requester: msg.author.username});
- msg.channel.send("Añadida **" + info.title+ "** a la lista.");
- });
- var failed = false
- const voiceChannel = msg.member.voiceChannel;
- if (!voiceChannel || voiceChannel.type !== 'voice') {
- var failed = true
- } else voiceChannel.join()
- if (queue[msg.guild.id] === undefined) {msg.channel.send("Usa `%play`")} else {
- if (!failed===true && !queue[msg.guild.id].playing) {commands.play(msg)} else {msg.channel.send("Usa `%play`")}
- }
- },
- 'queue': (msg) => {
- if (queue[msg.guild.id] === undefined) return msg.channel.send("No hay canciones en la lista añade mas usando `%add`");
- let tosend = [];
- queue[msg.guild.id].songs.forEach((song, i) => { tosend.push(`${i+1}. ${song.title} - Requested by: ${song.requester}`);});
- if (tosend.length === 0) return msg.channel.send("No hay canciones en la lista añade mas usando `%add`");
- msg.channel.send(`__**${msg.guild.name}'s Lista De Canciones:**__ ACTUALMENTE **${tosend.length}** canciones en la lista ${(tosend.length > 15 ? '*[Only next 15 shown]*' : '')}\n\`\`\`${tosend.slice(0,15).join('\n')}\`\`\``);
- },
- 'help': (msg) => {
- const embed = new Discord.RichEmbed()
- .setTitle("")
- .setColor(0xfaeb30)
- .setDescription("")
- .addField(tokens.prefix + "ping", "Pong.")
- .addField(tokens.prefix + "help", "Te Da Ayuda.")
- .addField(tokens.prefix + "play", "Reproduce la siguiente cancion")
- .addField(tokens.prefix + "add [Nombre De La Cancion]", "Añade canciones a la lista.")
- .addField(tokens.prefix + "queue", "Enseña la lista.")
- .addField(tokens.prefix + "join", "Se une al canal de voz en el que se encuentra. (O un canal llamado `musica` si existe).")
- .addField(tokens.prefix + "pause *", "Pausa la cancion.")
- .addField(tokens.prefix + "resume *", "Reanuda la cancion")
- .addField(tokens.prefix + "skip *", "Salta a la siguiente cancion.")
- .addField(tokens.prefix + "volume [x] *", "Ajusta el volumen a[x]. (De 0 a 100).")
- .addField(tokens.prefix + "time *", "Muestra el tiempo transcurrido desde que empezó la canción.")
- msg.author.send({embed});
- msg.author.send("`*`: Necesita estar tocando una canción para que este comando funcione.");
- msg.channel.send("Se le ha enviado una lista de comandos.");
- }
- };
- client.on('guildCreate', (i) => {
- console.log("+1: " + i.name )
- DBLPoster.bind(client);
- });
- client.on('guildDelete', (i) => {
- console.log("-1: " + i.name )
- DBLPoster.bind(client);
- });
- client.on('ready', () => {
- console.log('--------------------------------------');
- console.log('Nombre : ' + client.user.username + '#' + client.user.discriminator);
- console.log('ID : ' + client.user.id);
- console.log('Servers : ' + client.guilds.size);
- console.log('-------------------------------------');
- setInterval(function() {
- client.user.setActivity(String(client.guilds.size) + " servers!", { type: 'WATCHING' })
- .then(()=>setTimeout(function() {client.user.setActivity(" %help!", { type: 'LISTENING' });}, 5000))
- }, 10000);
- });
- client.on('message', msg => {
- if (msg.channel.type === "dm" && msg.author !== client.user) {
- msg.channel.send("AJMA_MUSICA no puede responder a las DMs. Los comandos tampoco están disponibles en los DMs. Únase al servidor de ayuda: PROXIMAMENTE")
- const embed = new Discord.RichEmbed()
- .setTitle("DM DE: __" + msg.author.tag + "__")
- .setColor(randomColor())
- .setDescription(msg.content)
- .setTimestamp()
- .setThumbnail(msg.author.displayAvatarURL)
- .setFooter("AJMA_MUSICA", client.user.displayAvatarURL)
- client.guilds.find(val => val.id === '331166980121821185').channels.find(val => val.id === '425184376792416283').send(embed)
- return
- } else if(msg.channel.type === "dm") { return }
- if (!msg.content.startsWith(tokens.prefix)) return;
- if (commands.hasOwnProperty(msg.content.toLowerCase().slice(tokens.prefix.length).split(' ')[0])) commands[msg.content.toLowerCase().slice(tokens.prefix.length).split(' ')[0]](msg);
- });
- client.login(process.env.TOKEN);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement