Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const request = require('request')
- function random(a, b, c, d) {//array -Stole from someone on stack exchange.
- c = a.length; while (c) b = Math.random() * c-- | 0, d = a[c], a[c] = a[b], a[b] = d
- }
- module.exports.run = (client, msg, args, db, settings, util, lang) => {
- // let msg = message;
- request('https://opentdb.com/api.php?amount=10&type=multiple&encode=url3986', { json: true }, (err, res, body) => {
- //console.log(body.results);
- var array = [
- body.results[0].incorrect_answers[0] + '\n',
- body.results[0].incorrect_answers[1] + '\n',
- body.results[0].incorrect_answers[2] + '\n',
- body.results[0].correct_answer + '\n']
- var place = '';
- random(array)
- msg.channel.send(decodeURIComponent(body.results[0].question) + '\n' + decodeURIComponent(place)).then(mes => {
- mes.react('đĻ')
- .then(() => mes.react('đ§'))
- .then(() => mes.react('đ¨'))
- .then(() => mes.react('đŠī¸'))
- const filter = (reaction, user) => reaction.emoji.name == 'đĻī¸' || reaction.emoji.name == 'đ§ī¸' || reaction.emoji.name == 'đ¨ī¸' || reaction.emoji.name == 'đŠī¸' && user.id == msg.author.id && console.log(user);
- const collector = mes.createReactionCollector(filter, { time: 0 });
- collector.on('collect', (r, user) => {
- if (r.emoji.name == 'đĻī¸') {
- if (array[0] == body.results[0].correct_answer + '\n') mes.edit("YOU WIN!")
- else mes.edit("YOU LOSE!")
- } else if (r.emoji.name == 'đ§ī¸') {
- if (array[1] == body.results[0].correct_answer + '\n') mes.edit("YOU WIN!")
- else mes.edit("YOU LOSE!")
- } else if (r.emoji.name == 'đ¨ī¸') {
- if (array[2] == body.results[0].correct_answer + '\n') mes.edit("YOU WIN!")
- else mes.edit("YOU LOSE!")
- } else if (r.emoji.name == 'đŠī¸') {
- if (array[3] == body.results[0].correct_answer + '\n') mes.edit("YOU WIN!")
- else mes.edit("YOU LOSE!")
- }
- });
- });
- });
- }
- module.exports.help = {
- name: "trivia"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement