Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. //THIS FILE IS STUPID!!
  2. const ytdl = require('ytdl-core');
  3. var queue = []
  4. var length_cache
  5. var length = 0;
  6. var joined = false;
  7. function validateYouTubeUrl(link) {
  8. if (link !== undefined && link !== '' && link !== null) {
  9. var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=|\?v=)([^#\&\?]*).*/;
  10. var match = link.match(regExp);
  11. if (match && match[2].length == 11) {
  12. return (true)
  13. }
  14. else {
  15. return (false)
  16. }
  17. }
  18. else {
  19. return (false)
  20. }
  21. }
  22. function nextsong(message,streamOptions){
  23. message
  24. }
  25. function disconnect(message) {
  26. if (queue[0] !== undefined) {
  27. setTimeout(function () {
  28. if (message.guild.voiceConnection !== null) {
  29. console.log('Here')
  30. message.guild.voiceConnection.disconnect();
  31. joined = false
  32.  
  33.  
  34. }
  35. }, length)
  36. //setTimeout(this.streamyt, length, message)
  37. }
  38. else {
  39. setTimeout(function () {
  40. message.channel.send('Das Lied ist Vorbei')
  41. if (message.guild.voiceConnection !== null) {
  42. console.log('Here2')
  43. message.guild.voiceConnection.disconnect();
  44. message.channel.setTopic("Starte einen song mit -play <youtube link>")
  45. joined = false
  46. }
  47. }, length)
  48. }
  49. }
  50. function sectomin(time) {
  51. var hr = ~~(time / 3600);
  52. var min = ~~((time % 3600) / 60);
  53. var sec = time % 60;
  54. var sec_min = "";
  55. if (hr > 0) {
  56. sec_min += "" + hrs + ":" + (min < 10 ? "0" : "");
  57. }
  58. sec_min += "" + min + ":" + (sec < 10 ? "0" : "");
  59. sec_min += "" + sec;
  60. return sec_min + " min";
  61. }
  62. module.exports = {
  63. streamyt: function (message, link, streamOptions) {
  64. if (message.member.voiceChannelID === '592389413296668722') {
  65. if (message.channel.id === '593398959427289108') {
  66. if (validateYouTubeUrl(link) === true) {
  67. queue.push(link)
  68. if (joined === false) {
  69. length_cache = length;
  70. ytdl.getInfo(queue[0]).then(info => {
  71. length = (info.length_seconds * 1000)
  72. console.log(length)
  73. message.channel.setTopic(':musical_note: **Derzeit Läuft**: "' + info.title + '" Länge: ' + sectomin(info.length_seconds))
  74. });
  75. vlength(message)
  76. const stream = ytdl(queue[0], { filter: 'audioonly', highWaterMark: 1024 * 1024 * 10 });
  77. console.log(queue)
  78. message.member.voiceChannel.join().then(connection => {
  79. console.log(streamOptions)
  80. let player = connection.playStream(stream, streamOptions)
  81. }).catch(console.error);
  82. joined = true
  83. queue.shift()
  84. }
  85. nextsong(message, streamOptions)
  86. console.log(queue)
  87. console.log(length)
  88.  
  89. }
  90. else {
  91. message.reply('Du Musst einen gültigen Youtube link angeben')
  92. }
  93. }
  94. else {
  95. message.reply('Du musst in <#593398959427289108> schreiben ')
  96. }
  97. }
  98. else {
  99. message.reply('Ich kann das nicht, du musst zuerst in "🎵Musik" sein')
  100. }
  101. }
  102. }
  103. function vlength(message) {
  104. if (length === length_cache) {
  105. setTimeout(function () { vlength(message) }, 200);
  106. }
  107. else {
  108. console.log('true')
  109. console.log(length)
  110. disconnect(message)
  111. nextsong()
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement