SHARE
TWEET

Untitled

a guest May 19th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. const request = require('request')
  3. function random(a, b, c, d) {//array -Stole from someone on stack exchange.
  4.     c = a.length; while (c) b = Math.random() * c-- | 0, d = a[c], a[c] = a[b], a[b] = d
  5. }
  6.  
  7. module.exports.run = (client, msg, args, db, settings, util, lang) => {
  8.     //let msg = message;
  9.     request('https://opentdb.com/api.php?amount=10&type=multiple&encode=url3986', { json: true }, (err, res, body) => {
  10.     //console.log(body.results);    
  11.     var array = [
  12.             body.results[0].incorrect_answers[0] + '\n',
  13.             body.results[0].incorrect_answers[1] + '\n',
  14.             body.results[0].incorrect_answers[2] + '\n',
  15.             body.results[0].correct_answer + '\n']
  16.            
  17.         var place = '';
  18.         random(array)
  19.         msg.channel.send(decodeURIComponent(body.results[0].question) + '\n' + decodeURIComponent(place)).then(mes => {
  20.             //mes.react('🇦')
  21.     .then(() => {mes.react('🇦').then(()=> {if (r.emoji.name == '🇦') {
  22.                 if (array[0] == body.results[0].correct_answer + '\n') mes.edit("YOU WIN!")
  23.                 else mes.edit("YOU LOSE!")
  24.             }})
  25.         }
  26.     .then(() => {mes.react('🇧').then(()=> {if (r.emoji.name == '🇧') {
  27.             if (array[1] == body.results[0].correct_answer + '\n') mes.edit("YOU WIN!")
  28.             else mes.edit("YOU LOSE!")
  29.             }})
  30.     }
  31.     .then(() => {mes.react('🇨').then(()=> {if (r.emoji.name == '🇨') {
  32.         if (array[2] == body.results[0].correct_answer + '\n') mes.edit("YOU WIN!")
  33.         else mes.edit("YOU LOSE!")
  34.             }})
  35.     }
  36.     .then(() => {mes.react('🇩').then(()=> {if (r.emoji.name == '🇩') {
  37.         if (array[3] == body.results[0].correct_answer + '\n') mes.edit("YOU WIN!")
  38.         else mes.edit("YOU LOSE!")
  39.             }})
  40.     });
  41.             /*const filter = (reaction, user) => reaction.emoji.name == '🇦' || reaction.emoji.name == '🇧' || reaction.emoji.name == '🇨' || reaction.emoji.name == '🇩' && user.id == msg.author.id && console.log(user);
  42.             const collector = mes.createReactionCollector(filter, { time: 25000 });
  43.             collector.on('collect', (r, user) => {
  44.                 if (r.emoji.name == '🇦') {
  45.                     if (array[0] == body.results[0].correct_answer + '\n') mes.edit("YOU WIN!")
  46.                     else mes.edit("YOU LOSE!")
  47.                 } else if (r.emoji.name == '🇧') {
  48.                     if (array[1] == body.results[0].correct_answer + '\n') mes.edit("YOU WIN!")
  49.                     else mes.edit("YOU LOSE!")
  50.                 } else if (r.emoji.name == '🇨') {
  51.                     if (array[2] == body.results[0].correct_answer + '\n') mes.edit("YOU WIN!")
  52.                     else mes.edit("YOU LOSE!")
  53.                 } */
  54.          
  55. }
  56. module.exports.help = {
  57.     name: "trivia"
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top