Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.76 KB | None | 0 0
  1. const http = require('http');
  2. const express = require('express');
  3. const app = express();
  4. app.get("/", (request, response) => {
  5. response.sendStatus(200);
  6. });
  7. app.listen(process.env.PORT);
  8. setInterval(() => {
  9. http.get(`http://${process.env.PROJECT_DOMAIN}.glitch.me/`);
  10. }, 280000);
  11.  
  12.  
  13. //ABOVE THIS IS ALL GLITCH STUFF
  14. const Discord = require('discord.js');
  15. const yt = require('ytdl-core');
  16. const tokens = require('./tokens.json');
  17. const dbl = require("dblposter");
  18. const client = new Discord.Client();
  19. var randomColor = require('randomcolor');
  20. var search = require('youtube-search');
  21. const DBLPoster = new dbl(`eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjM3MDI3NDU5ODU1OTY3ODQ2NyIsImJvdCI6dHJ1ZSwiaWF0IjoxNTE5NTcwOTY4fQ.6swOzBO_I8lh82_BN77CKiJMbKZK4l8x5EZVE8ldzVU`);
  22.  
  23.  
  24. var opts = {
  25. maxResults: 1,
  26. key: process.env.APIKEY,
  27. type: "video"
  28. };
  29.  
  30.  
  31.  
  32. let queue = {};
  33.  
  34. const commands = {
  35. 'play': (msg) => {
  36. if (queue[msg.guild.id] === undefined) return msg.channel.send("Añade primero la cancion pon: `%add`");
  37. if (!msg.guild.voiceConnection) return commands.join(msg).then(() => commands.play(msg));
  38. if (queue[msg.guild.id].playing) return msg.channel.send('Esa Cancion Ya Esta Sonando');
  39. let dispatcher;
  40. queue[msg.guild.id].playing = true;
  41. (function play(song) {
  42. if (song === undefined) return msg.channel.send('La Lista Esta Vacia Añade Canciones Poniendo `%add`.').then(() => {
  43. queue[msg.guild.id].playing = false;
  44. msg.member.voiceChannel.leave();
  45. });
  46. msg.channel.send(`Reproduciendose: **${song.title}** Pedida Por: **${song.requester}**`);
  47. dispatcher = msg.guild.voiceConnection.playStream(yt(song.url, { filter: "audioonly" }), { passes : tokens.passes });
  48. let collector = msg.channel.createCollector(m => m);
  49. collector.on('message', m => {
  50. if (m.content.startsWith(tokens.prefix + 'pause')) {
  51. msg.channel.send('paused').then(() => {dispatcher.pause();});
  52. return
  53. } else if (m.content.startsWith(tokens.prefix + 'resume')){
  54. msg.channel.send('resumed').then(() => {dispatcher.resume();});
  55. return
  56. } else if (m.content.startsWith(tokens.prefix + 'skip')){
  57. msg.channel.send('Skipped song.').then(() => {dispatcher.end();});
  58. return
  59. } else if (m.content.startsWith(tokens.prefix + 'volume')){
  60. if (Math.round(dispatcher.volume*50) <= 0) return msg.channel.send(`Volume: ${Math.round(dispatcher.volume*50)}`);
  61. dispatcher.setVolume(Math.max(((m.content.split(' ')[1])))/50,0);
  62. msg.channel.send(`Volume: ${Math.round(dispatcher.volume*50)}`);
  63. return
  64. } else if (m.content.startsWith(tokens.prefix + 'time')){
  65. 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)}`);
  66. return
  67. }
  68. });
  69. dispatcher.on('end', () => {
  70. collector.stop();
  71. play(queue[msg.guild.id].songs.shift());
  72. });
  73. dispatcher.on('error', (err) => {
  74. return msg.channel.send('error: ' + err).then(() => {
  75. collector.stop();
  76. play(queue[msg.guild.id].songs.shift());
  77. });
  78. });
  79. })(queue[msg.guild.id].songs.shift());
  80. },
  81. 'ping': (msg) => { msg.channel.send('Pong! Heartbeat: ' + String(parseInt(client.ping)) + 'ms'); },
  82. '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.");},
  83. '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.");},
  84. '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.");},
  85. '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.");},
  86. '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.");},
  87. 'join': (msg) => {
  88. return new Promise((resolve, reject) => {
  89. const voiceChannel = msg.member.voiceChannel;
  90. if (!voiceChannel || voiceChannel.type !== 'voice') {
  91. 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.')
  92. return false
  93. };
  94. voiceChannel.join().then(connection => resolve(connection)).catch(err => reject(err));
  95. });
  96. },
  97. 'add': (msg) => {
  98. let url = msg.content.split(' ')[1];
  99. let args = msg.content.replace("%add ", "")
  100. 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`);
  101. yt.getInfo(url, (err, info) => {
  102. if(err) {
  103. search(args, opts, function(err, results) {
  104. if(err) return console.log(err);
  105. if (!queue.hasOwnProperty(msg.guild.id)) queue[msg.guild.id] = {}, queue[msg.guild.id].playing = false, queue[msg.guild.id].songs = [];
  106. queue[msg.guild.id].songs.push({url: results[0].link, title: results[0].title, requester: msg.author.username});
  107. msg.channel.send("Añadida **" + results[0].link + "** a la lista.");
  108. });
  109. return
  110. };
  111. if (!queue.hasOwnProperty(msg.guild.id)) queue[msg.guild.id] = {}, queue[msg.guild.id].playing = false, queue[msg.guild.id].songs = [];
  112. queue[msg.guild.id].songs.push({url: url, title: info.title, requester: msg.author.username});
  113. msg.channel.send("Añadida **" + info.title+ "** a la lista.");
  114. });
  115. var failed = false
  116. const voiceChannel = msg.member.voiceChannel;
  117. if (!voiceChannel || voiceChannel.type !== 'voice') {
  118. var failed = true
  119. } else voiceChannel.join()
  120. if (queue[msg.guild.id] === undefined) {msg.channel.send("Usa `%play`")} else {
  121. if (!failed===true && !queue[msg.guild.id].playing) {commands.play(msg)} else {msg.channel.send("Usa `%play`")}
  122. }
  123. },
  124. 'queue': (msg) => {
  125. if (queue[msg.guild.id] === undefined) return msg.channel.send("No hay canciones en la lista añade mas usando `%add`");
  126. let tosend = [];
  127. queue[msg.guild.id].songs.forEach((song, i) => { tosend.push(`${i+1}. ${song.title} - Requested by: ${song.requester}`);});
  128. if (tosend.length === 0) return msg.channel.send("No hay canciones en la lista añade mas usando `%add`");
  129. 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')}\`\`\``);
  130. },
  131.  
  132. 'help': (msg) => {
  133. const embed = new Discord.RichEmbed()
  134. .setTitle("")
  135. .setColor(0xfaeb30)
  136. .setDescription("")
  137. .addField(tokens.prefix + "ping", "Pong.")
  138. .addField(tokens.prefix + "help", "Te Da Ayuda.")
  139. .addField(tokens.prefix + "play", "Reproduce la siguiente cancion")
  140. .addField(tokens.prefix + "add [Nombre De La Cancion]", "Añade canciones a la lista.")
  141. .addField(tokens.prefix + "queue", "Enseña la lista.")
  142. .addField(tokens.prefix + "join", "Se une al canal de voz en el que se encuentra. (O un canal llamado `musica` si existe).")
  143. .addField(tokens.prefix + "pause *", "Pausa la cancion.")
  144. .addField(tokens.prefix + "resume *", "Reanuda la cancion")
  145. .addField(tokens.prefix + "skip *", "Salta a la siguiente cancion.")
  146. .addField(tokens.prefix + "volume [x] *", "Ajusta el volumen a[x]. (De 0 a 100).")
  147. .addField(tokens.prefix + "time *", "Muestra el tiempo transcurrido desde que empezó la canción.")
  148. msg.author.send({embed});
  149. msg.author.send("`*`: Necesita estar tocando una canción para que este comando funcione.");
  150. msg.channel.send("Se le ha enviado una lista de comandos.");
  151. }
  152. };
  153.  
  154. client.on('guildCreate', (i) => {
  155. console.log("+1: " + i.name )
  156.  
  157. DBLPoster.bind(client);
  158. });
  159.  
  160. client.on('guildDelete', (i) => {
  161. console.log("-1: " + i.name )
  162.  
  163. DBLPoster.bind(client);
  164. });
  165.  
  166. client.on('ready', () => {
  167. console.log('--------------------------------------');
  168. console.log('Nombre : ' + client.user.username + '#' + client.user.discriminator);
  169. console.log('ID : ' + client.user.id);
  170. console.log('Servers : ' + client.guilds.size);
  171. console.log('-------------------------------------');
  172.  
  173.  
  174.  
  175. setInterval(function() {
  176. client.user.setActivity(String(client.guilds.size) + " servers!", { type: 'WATCHING' })
  177. .then(()=>setTimeout(function() {client.user.setActivity(" %help!", { type: 'LISTENING' });}, 5000))
  178. }, 10000);
  179. });
  180.  
  181. client.on('message', msg => {
  182. if (msg.channel.type === "dm" && msg.author !== client.user) {
  183. 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")
  184. const embed = new Discord.RichEmbed()
  185. .setTitle("DM DE: __" + msg.author.tag + "__")
  186. .setColor(randomColor())
  187. .setDescription(msg.content)
  188. .setTimestamp()
  189. .setThumbnail(msg.author.displayAvatarURL)
  190. .setFooter("AJMA_MUSICA", client.user.displayAvatarURL)
  191. client.guilds.find(val => val.id === '331166980121821185').channels.find(val => val.id === '425184376792416283').send(embed)
  192. return
  193. } else if(msg.channel.type === "dm") { return }
  194. if (!msg.content.startsWith(tokens.prefix)) return;
  195. if (commands.hasOwnProperty(msg.content.toLowerCase().slice(tokens.prefix.length).split(' ')[0])) commands[msg.content.toLowerCase().slice(tokens.prefix.length).split(' ')[0]](msg);
  196. });
  197. client.login(process.env.TOKEN);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement