@ -46,7 +46,7 @@ client.on("guildCreate", (guild) => {
async function updateScore ( isCorrect , score , authorId ) {
async function updateScore ( isCorrect , score , authorId ) {
if ( ! isCorrect ) {
if ( ! isCorrect ) {
return ` N ice try! Your score is still ${ score } . ` ;
return ` n ice try! Your score is still ${ score } . ` ;
} else {
} else {
score += 4 ;
score += 4 ;
if ( score == 4 ) {
if ( score == 4 ) {
@ -67,7 +67,7 @@ async function updateScore(isCorrect, score, authorId) {
doc . save ( ) ;
doc . save ( ) ;
}
}
return ` G reat job! Your score is now ${ score } . ` ;
return ` g reat job! Your score is now ${ score } . ` ;
}
}
}
}
@ -104,79 +104,13 @@ async function otherCommands(message) {
console . log ( err ) ;
console . log ( err ) ;
}
}
} ) ;
} ) ;
if ( message . content === "do be training" ) {
axios . get ( "https://scibowldb.com/api/questions/random" ) . then ( ( res ) => {
const data = res . data ;
const messageAuthorFilter = ( m ) => m . author . id === message . author . id ;
message . reply ( data . question . tossup_question ) . then ( ( ) => {
message . channel
. awaitMessages ( messageAuthorFilter , {
max : 1 ,
time : 30000 ,
errors : [ "time" ] ,
} )
. then ( ( answerMsg ) => {
answerMsg = answerMsg . first ( ) ;
let predicted = null ;
if ( data . question . tossup_format === "Multiple Choice" ) {
if (
answerMsg . content . charAt ( 0 ) . toLowerCase ( ) ===
data . question . tossup_answer . charAt ( 0 ) . toLowerCase ( )
) {
predicted = "correct" ;
} else {
predicted = "incorrect" ;
}
} else {
if (
answerMsg . content . toLowerCase ( ) ===
data . question . tossup_answer . toLowerCase ( )
) {
predicted = "correct" ;
} else {
predicted = "incorrect" ;
}
}
answerMsg . channel . send (
` Correct answer: ** ${ data . question . tossup_answer } **. Predicted: ** ${ predicted } **. Please react to your answer! `
) ;
answerMsg . react ( "✅" ) ;
answerMsg . react ( "❌" ) ;
const filter = ( reaction , user ) => {
return (
[ "❌" , "✅" ] . includes ( reaction . emoji . name ) &&
user . id === answerMsg . author . id
) ;
} ;
answerMsg
. awaitReactions ( filter , {
max : 1 ,
time : 600000 ,
errors : [ "time" ] ,
} )
. then ( ( userReaction ) => {
const reaction = userReaction . first ( ) ;
if ( reaction . emoji . name === "❌" ) {
updateScore ( false , score , authorId ) . then ( ( msgToReply ) =>
answerMsg . reply ( msgToReply )
) ;
} else {
updateScore ( true , score , authorId ) . then ( ( msgToReply ) =>
answerMsg . reply ( msgToReply )
) ;
}
} ) ;
} ) . catch ( console . error ) ;
} ) ;
} ) ;
} else {
const subject = message . content . substring ( 15 ) ;
const subject = message . content . substring ( 15 ) ;
let categoryArray = [ ] ;
let categoryArray = [ ] ;
switch ( subject ) {
switch ( subject ) {
case "" :
categoryArray = [ "BIOLOGY" , "PHYSICS" , "CHEMISTRY" , "EARTH AND SPACE" , "ASTRONOMY" , "MATH" ] ;
break ;
case "astro" :
case "astro" :
case "astronomy" :
case "astronomy" :
categoryArray = [ "ASTRONOMY" ]
categoryArray = [ "ASTRONOMY" ]
@ -210,9 +144,9 @@ async function otherCommands(message) {
}
}
axios
axios
. post ( "https://scibowldb.com/api/questions" , { categories : categoryArray } )
. post ( "https://scibowldb.com/api/questions/random " , { categories : categoryArray } )
. then ( ( res ) => {
. then ( ( res ) => {
data = res . data . questions [ Math . floor ( Math . random ( ) * res . data . questions . length ) ] ;
data = res . data . question ;
const messageFilter = ( m ) => m . author . id === authorId ;
const messageFilter = ( m ) => m . author . id === authorId ;
message . reply ( data . tossup_question ) . then ( ( ) => {
message . reply ( data . tossup_question ) . then ( ( ) => {
message . channel
message . channel
@ -244,44 +178,39 @@ async function otherCommands(message) {
predicted = "incorrect" ;
predicted = "incorrect" ;
}
}
}
}
answerMsg . channel . send (
` Correct answer: ** ${ data . tossup_answer } **. Predicted: ** ${ predicted } **. Please react to your answer! `
if ( predicted === "correct" ) {
) ;
updateScore ( true , score , authorId ) . then ( ( msgToReply ) =>
answerMsg . react ( "✅" ) ;
answerMsg . reply ( msgToReply )
answerMsg . react ( "❌" ) ;
const reactionFilter = ( reaction , user ) => {
return (
[ "❌" , "✅" ] . includes ( reaction . emoji . name ) &&
user . id === answerMsg . author . id
) ;
) ;
} ;
} else {
answerMsg
answerMsg . react ( "♻️" ) ;
. awaitReactions ( reactionFilter , {
answerMsg . channel . send (
max : 1 ,
` It seems your answer was incorrect. The correct answer was ** \` ${ data . tossup_answer } \` **. Please react with "♻️" to override your answer if you think you got it right. `
time : 600000 ,
) ;
errors : [ "time" ] ,
const filter = ( reaction , user ) => {
} )
return (
. then ( async ( userReaction ) => {
[ "♻️" ] . includes ( reaction . emoji . name ) &&
const reaction = userReaction . first ( ) ;
user . id === answerMsg . author . id
if ( reaction . emoji . name == "❌" ) {
) ;
updateScore ( false , score , authorId ) . then ( ( msgToReply ) =>
} ;
answerMsg . reply ( msgToReply )
answerMsg
) ;
. awaitReactions ( filter , {
} else {
max : 1 ,
time : 600000 ,
errors : [ "time" ] ,
} )
. then ( ( userReaction ) => {
updateScore ( true , score , authorId ) . then ( ( msgToReply ) =>
updateScore ( true , score , authorId ) . then ( ( msgToReply ) =>
answerMsg . reply ( msgToReply )
answerMsg . reply ( msgToReply )
) ;
) ;
}
} ) ;
} )
}
. catch ( console . error ) ; // Reaction message filter
} )
} )
. catch ( ( collected , error ) => {
. catch ( console . error ) ;
message . reply ( "\n**ANSWER TIMEOUT**" ) ;
} ) ;
} ) ;
} ) ;
} )
} )
. catch ( console . error ) ;
. catch ( console . error ) ;
}
} else {
} else {
// Not any of the commands supported
// Not any of the commands supported
message . channel . send (
message . channel . send (