Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. const fs = require('fs');
  2. module.exports = (bot, utils, ytdl, config) => {
  3.  
  4. fs.readdir("./commands/", (err, files) => {
  5.  
  6. if (err) console.error(err);
  7. let jsfiles = files.filter(f => f.split(".").pop() === "js");
  8.  
  9. if (jsfiles.length <= 0) return console.log("There are no commands to load...");
  10.  
  11. console.log(`Loading ${jsfiles.length} commands...`);
  12. jsfiles.forEach((f, i) => {
  13. let props = require(`../commands/${f}`);
  14. bot.commands.set(props.help.name, props);
  15. props.help.aliases.forEach(alias => {
  16. bot.aliases.set(alias, props.help.name);
  17. });
  18. });
  19. });
  20.  
  21. bot.loadCommand = (commandName) => {
  22. try {
  23. let props = require(`../commands/${commandName}`);
  24. if (props.init) props.init(bot);
  25. bot.commands.set(commandName, props);
  26. props.help.aliases.forEach(alias => {
  27. bot.aliases.set(alias, props.help.name);
  28. });
  29. return false;
  30. } catch (err) {
  31. return utils.cmd_fail(`Error: ${err}\nCommand \`${commandName}\` cannot be found.`, `${config.prefix}reload <command>`);
  32. }
  33. };
  34.  
  35. bot.unloadCommand = async (commandName) => {
  36. try {
  37. if (!commandName) return `The command \`${commandName}\` doesn"t seem to exist. Try again!`;
  38.  
  39. if (commandName.shutdown) await commandName.shutdown(bot);
  40. delete require.cache[require.resolve(`../commands/${commandName}.js`)];
  41. return false;
  42. } catch (err) {
  43. return utils.cmd_fail(`Error: ${err}\nCommand \`${commandName}\` cannot be found.`, `${config.prefix}reload <command>`);
  44. }
  45. };
  46.  
  47. bot.handleVideo = async (video, message, vc, playlist = false) => {
  48. let queue = bot.queue.get(message.guild.id);
  49. let music = {
  50. id: video.id,
  51. title: video.title,
  52. url: `https://www.youtube.com/watch?v=${video.id}`
  53. };
  54.  
  55. if (!queue) {
  56. let queueConstruct = {
  57. textChannel: message.channel,
  58. voiceChannel: vc,
  59. connection: null,
  60. musics: [],
  61. volume: 50,
  62. playing: true
  63. };
  64. let voteConstruct = {
  65. votes: 0,
  66. voters: []
  67. };
  68.  
  69. bot.queue.set(message.guild.id, queueConstruct);
  70. bot.votes.set(message.guild.id, voteConstruct)
  71. queueConstruct.musics.push(music);
  72.  
  73. try {
  74. var connection = await vc.join();
  75. queueConstruct.connection = connection;
  76. bot.play(message.guild, queueConstruct.musics[0]);
  77. } catch (err) {
  78. bot.queue.delete(message.guild.id);
  79. console.error(`I could not join your voice channel: ${err}`);
  80. }
  81. } else {
  82. queue.musics.push(music);
  83. if (playlist) return;
  84. else return message.channel.send(`<a:ga_music:553362699334057993> **${music.title}** has been added to queue`);
  85. }
  86. return;
  87. }
  88.  
  89. bot.play = (guild, music) => {
  90. let queue = bot.queue.get(guild.id);
  91. let votes = bot.votes.get(guild.id)
  92. if (!music) {
  93. queue.voiceChannel.leave();
  94. bot.queue.delete(guild.id);
  95. bot.votes.delete(guild.id);
  96. return queue.textChannel.send(`<a:ga_music:553362699334057993> Music playback has ended`);
  97. }
  98.  
  99. let dispatcher = queue.connection.playStream(ytdl(music.url))
  100. .on('end', () => {
  101. queue.musics.shift();
  102. votes.votes = 0;
  103. votes.voters = [];
  104. setTimeout(() => {
  105. bot.play(guild, queue.musics[0]);
  106. }, 250);
  107. })
  108. .on('error', err => console.error(err));
  109. dispatcher.setVolumeLogarithmic(queue.volume / 100);
  110.  
  111. queue.textChannel.send(`<a:ga_music:553362699334057993> **${music.title}** is now being played`);
  112. }
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement