Skip to content

Commit

Permalink
fixed errors in quiz
Browse files Browse the repository at this point in the history
  • Loading branch information
mushahidq committed Mar 21, 2021
1 parent eec8b43 commit 6df70d1
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require("dotenv").config()
const fs = require('fs')
const Discord = require("discord.js")
const client = new Discord.Client()
const { prefix, channelid } = require('./config.json')
const { prefix, channelid, funtranslations } = require('./config.json')

client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
Expand Down Expand Up @@ -34,7 +34,7 @@ function gotMessage(msg) {

const args = msg.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
if(msg.channel.id == channelid) {
if(msg.channel.id == channelid || msg.channel.id == funtranslations) {
if(!client.commands.has(commandName)){
return msg.channel.send(`${commandName} command not found\nUse \`!help\` for help`);
}
Expand Down
7 changes: 4 additions & 3 deletions commands/accept.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const { prefix, channelid } = require('../config.json')
const fetch = require('node-fetch')
const querystring = require('querystring')

module.exports = {
name: 'accept',
despcription: "Accept someone's duel challenge",
guildOnly: true,
execute: async (message, args, quiz) => {
if(quiz.duel) {
if(quiz.duel && message.author.id == quiz.participant2.id) {
message.channel.send(`${message.author} has accepted ${quiz.participant1}'s challenge.\nThe duel will begin in 10 seconds.\nThere will be three questions and first person to answer two correctly wins the duel.\nThe questions are of true/false type but you'll have to type out the entire sentence in the answer, for example "\`!first The statement.. is false.\`".\nUse \`${prefix}first\`, \`${prefix}second\` and \`${prefix}third\` to answer first second and third questions respectively.\nThe quiz will end automatically after 5 mins.`);
quiz.isgoingon = true;
const response = await fetch('https://opentdb.com/api.php?amount=3&type=boolean').then(response => response.json());
Expand All @@ -15,9 +16,9 @@ module.exports = {
for (result of response.results) {
quiz.questions[i] = result.question;
if (result.correct_answer === 'True') {
quiz.answers[i] = result.question.slice(0, -1) + " is true.";
quiz.answers[i] = querystring.stringify(result.question.slice(0, -1) + " is true.");
} else if (result.correct_answer == 'False') {
quiz.answers[i] = result.question.slice(0, -1) + " is false.";
quiz.answers[i] = querystring.stringify(result.question.slice(0, -1) + " is false.");
}
message.channel.send(`\n${quiz.questions[i]}`);
i++;
Expand Down
4 changes: 2 additions & 2 deletions commands/duel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ module.exports = {
if(message.mentions.users.size) {
const taggedUser = message.mentions.users.first();
message.channel.send(`${taggedUser}, you have been challenged to a duel of wits by ${message.author}.\nRespond with \`${prefix}accept\` in the next five minutes to accept the challenge or with \`${prefix}reject\` to reject the challenge.`);
quiz.participant1 = JSON.stringify(message.author);
quiz.participant1 = message.author;
quiz.duel = true;
quiz.participant2 = JSON.stringify(taggedUser);
quiz.participant2 = taggedUser;
setTimeout(() => {
if(quiz.duel && !quiz.isgoingon) {
message.channel.send(`${taggedUser} has not accepted the challenge in the required time`);
Expand Down
2 changes: 1 addition & 1 deletion commands/first.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports ={
guildOnly: true,
execute(message, args, quiz) {
if(quiz.isgoingon) {
if (true) {//message.author == quiz.particpant1 || message.author == quiz.particpant2) {
if (message.author.id == quiz.participant1.id || message.author.id == quiz.participant2.id) {
const answer = args.join(' ');
if (answer == quiz.answers[0] && !quiz.answered[0]){
if (message.author == quiz.particpant1) {
Expand Down
2 changes: 1 addition & 1 deletion commands/second.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports ={
guildOnly: true,
execute(message, args, quiz) {
if(quiz.isgoingon) {
if (message.author.id == quiz.particpant1.id || message.author.id == quiz.particpant2.id) {
if (message.author.id == quiz.participant1.id || message.author.id == quiz.participant2.id) {
const answer = args.join(' ');
if (answer == quiz.answers[1] && !quiz.answered[1]){
if (message.author == quiz.particpant1) {
Expand Down
2 changes: 1 addition & 1 deletion commands/third.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports ={
guildOnly: true,
execute(message, args, quiz) {
if(quiz.isgoingon) {
if (message.author.id == quiz.particpant1.id || message.author.id == quiz.particpant2.id) {
if (message.author.id == quiz.participant1.id || message.author.id == quiz.participant2.id) {
const answer = args.join(' ');
if (answer == quiz.answers[2] && !quiz.answered[2]){
if (message.author == quiz.particpant1) {
Expand Down
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"prefix": "!",
"channelid": "822840237071138817"
"channelid": "822840237071138817",
"funtranslations": "823155856291659816"
}

0 comments on commit 6df70d1

Please sign in to comment.