Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.     var argh = msg.content.substring(8)
  3.     var args = argh.split(",")
  4.     var artist = args[1]
  5.     var song = args[0]
  6.  
  7.     lyr.fetch(artist, song, function (err, lyrics) {
  8.     if (err) return console.log(err)
  9.  
  10.     var lyra = lyrics.split('\n\n')
  11.     // msg.channel.send(lyra.length)
  12.     var ran = Math.floor((Math.random() * lyra.length))
  13.     for (i = 0; i < lyra.length; i++) {
  14.       if (lyra[i] === "") {
  15.         lyra.splice(i)
  16.       }
  17.       if (lyra[i]) {
  18.         if (lyra[i].replace(/[^\n]/g, "").length > 7) {
  19.           lyra.splice(i)
  20.         }
  21.     }
  22.  
  23.     }
  24.  
  25.     // msg.channel.send(ran)
  26.     if (lyra[ran] === 'Sorry, We don\'t have lyrics for this song yet.') {
  27.       msg.channel.send('```Proper command usage is !lyrics song, artist```')
  28.       return
  29.     }
  30.     var text = lyra[ran]
  31.     // if (!text) {
  32.     //   text = lyra[0]
  33.     // }
  34.     var Image = Canvas.Image
  35.     Canvas.registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'f.ttf'), { family: 'futura' }); // eslint-disable-line max-len
  36.     var img = new Image();
  37.     var canvas = new Canvas(800, 500)
  38.     var ctx = canvas.getContext('2d');
  39.     var img = new Image();
  40.     img.onload = function() {
  41.       ctx.drawImage(img,0,0,800,500);
  42.  
  43.       ctx.fillStyle = 'center'
  44.       ctx.fillStyle = 'white'
  45.       // ctx.fillText(text,0,200)
  46.       if (!text) {
  47.         var array2 = lyrics.split('\n\n')
  48.         var random = Math.floor((Math.random() * array2.length))
  49.  
  50.         // for (i = 0; i < array2.length; i++) {
  51.         //   if (array2[i] === "") {
  52.         //     array2.splice(i)
  53.         //   }
  54.         // }
  55.         text = array2[random]
  56.       }
  57.       // text = text.replace(/[\n\n]/g, "")
  58.       // var arga = text.split('\n')
  59.       // for (i = 0; i < arga.length; i++) {
  60.       //   if (arga[i].length < 3) {
  61.       //     arga.splice(i)
  62.       //   }
  63.       // }
  64.       // msg.channel.send(text)
  65.       // var text5 = arga.join('\n')
  66.       if (!text) {
  67.         var array2 = lyrics.split('\n\n')
  68.         text = array2[0]
  69.       }
  70.       var why = text.split('\n')
  71.       console.log(why)
  72.       console.log(why.length)
  73.       var mes2 = text.replace(/[^\n]/g, "").length
  74.  
  75.       // msg.channel.send(mes2 + "   mes2")
  76.       var lim = why.length
  77.       if (why.length > 4) {
  78.         lim = 4
  79.         mes2 = 4
  80.       }
  81.       var fontsize = 30
  82.       var mes = 0
  83.       var hello = 0
  84.       var split = []
  85.       console.log(why)
  86.       lea = 1000
  87.       if (why.length < 1000) {
  88.         lea = why.length
  89.       }
  90.       for (i = 0; i < lea; i++) {
  91.         console.log(i)
  92.         var xd = why[i]
  93.         // var jj = i
  94.         ctx.font = fontsize + "px futura"
  95.         var mes = ctx.measureText(why[i]).width
  96.         if (mes > 400) {
  97.  
  98.           var length = why[i].length
  99.           var array = xd.split("")
  100.  
  101.           for (j = length / 2;j < length;j++) {
  102.             if (array[j] === " ") {
  103.               split.push(j)
  104.               // msg.channel.send("i pushed:  " + j)
  105.             }
  106.           }
  107.           var num = parseInt(split[0])
  108.           var part1 = xd.substring(0, num)
  109.           var part2 = xd.substring(num, xd.length)
  110.           why.splice(i,1,part1,part2)
  111.           lim++
  112.           mes2++
  113.           hello++
  114.         }
  115.       }
  116.       console.log(why)
  117.       for (i = 0; i < lim; i++) {
  118.         if (why[i] == 'I\'m the sons of all I\'ve done') {
  119.           why[i] = 'I\'m the son of all I\'ve done'
  120.         }
  121.         mes = ctx.measureText(why[i]).width
  122.         // msg.channel.send(i)
  123.         ctx.font = fontsize + "px futura"
  124.         // msg.channel.send('mes  ' + mes)
  125.         var amount1 = ((800 - mes) / 2)
  126.         // msg.channel.send(amount1)
  127.         var msre = (50 * (mes2)) - 20
  128.         var amount2 = ((500 - msre) / 2)
  129.  
  130.         ctx.fillText(why[i],amount1,amount2 + 50 * i)
  131.       }
  132.       msg.channel.send(hello)
  133.       msg.channel.sendFile(canvas.toBuffer())
  134.     }
  135.     var numb = Math.floor(Math.random() * 4)
  136.     img.src = 'Z:/No Bot Intended/lyricpics/' + numb + '.jpg'
  137. });
  138.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement