@ -7,7 +7,7 @@ import fetch from 'node-fetch';
import * as fs from 'fs' ;
import * as fs from 'fs' ;
import * as path from 'path' ;
import * as path from 'path' ;
var hits = 0 ;
let hits = 0 ;
if ( fs . existsSync ( 'numhits.txt' ) ) {
if ( fs . existsSync ( 'numhits.txt' ) ) {
fs . readFile ( 'numhits.txt' , 'utf8' , function ( err , data ) {
fs . readFile ( 'numhits.txt' , 'utf8' , function ( err , data ) {
@ -32,9 +32,9 @@ client.on('guildCreate', guild => {
client . on ( 'message' , async message => {
client . on ( 'message' , async message => {
if ( message . content . startsWith ( "do be announcing" ) && message . author . id === process . argv [ 3 ] ) {
if ( message . content . startsWith ( "do be announcing" ) && message . author . id === process . argv [ 3 ] ) {
var announcement = message . content . substring ( 17 ) ;
const announcement = message . content . substring ( 17 ) ;
client . guilds . cache . forEach ( ( guild ) => {
client . guilds . cache . forEach ( ( guild ) => {
var channel = guild . channels . cache . find ( channel => channel . name === 'general' ) ;
const channel = guild . channels . cache . find ( channel => channel . name === 'general' ) ;
if ( channel ) {
if ( channel ) {
if ( channel . type === "text" ) {
if ( channel . type === "text" ) {
channel . send ( announcement ) . catch ( console . error ) ;
channel . send ( announcement ) . catch ( console . error ) ;
@ -52,18 +52,18 @@ client.on('message', async message => {
}
}
if ( message . content . toLowerCase ( ) === ( "do be roundgen html dm" ) ) {
if ( message . content . toLowerCase ( ) === ( "do be roundgen html dm" ) ) {
fs . writeFile ( 'round.html' , "<h1>Here's your round!</h1>" , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
fs . writeFile ( 'round.html' , "<h1>Here's your round!</h1>" , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
var person = client . users . cache . get ( message . author . id ) ;
const person = client . users . cache . get ( message . author . id ) ;
var i ;
const i ;
let generatingMsg = await message . channel . send ( "Generating..." ) ;
let generatingMsg = await message . channel . send ( "Generating..." ) ;
for ( i = 1 ; i < 26 ; i ++ ) {
for ( i = 1 ; i < 26 ; i ++ ) {
var tossup_question ;
const tossup_question ;
var question_category ;
const question_category ;
var tossup_format ;
const tossup_format ;
var tossup_answer ;
const tossup_answer ;
var bonus_question ;
const bonus_question ;
var bonus_format ;
const bonus_format ;
var bonus_answer ;
const bonus_answer ;
var htmlContent = "" ;
const htmlContent = "" ;
await fetch ( 'https://scibowldb.com/api/questions/random' )
await fetch ( 'https://scibowldb.com/api/questions/random' )
. then ( response => response . json ( ) )
. then ( response => response . json ( ) )
. then ( data => {
. then ( data => {
@ -86,17 +86,17 @@ client.on('message', async message => {
}
}
if ( message . content . toLowerCase ( ) === ( "do be roundgen html" ) ) {
if ( message . content . toLowerCase ( ) === ( "do be roundgen html" ) ) {
fs . writeFile ( 'round.html' , "<h1>Here's your round!</h1>" , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
fs . writeFile ( 'round.html' , "<h1>Here's your round!</h1>" , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
var i ;
let i ;
let generatingMsg = await message . channel . send ( "Generating..." ) ;
let generatingMsg = await message . channel . send ( "Generating..." ) ;
for ( i = 1 ; i < 26 ; i ++ ) {
for ( i = 1 ; i < 26 ; i ++ ) {
var tossup_question ;
const tossup_question ;
var question_category ;
const question_category ;
var tossup_format ;
const tossup_format ;
var tossup_answer ;
const tossup_answer ;
var bonus_question ;
const bonus_question ;
var bonus_format ;
const bonus_format ;
var bonus_answer ;
const bonus_answer ;
var htmlContent = "" ;
const htmlContent = "" ;
await fetch ( 'https://scibowldb.com/api/questions/random' )
await fetch ( 'https://scibowldb.com/api/questions/random' )
. then ( response => response . json ( ) )
. then ( response => response . json ( ) )
. then ( data => {
. then ( data => {
@ -119,18 +119,18 @@ client.on('message', async message => {
}
}
if ( message . content . toLowerCase ( ) === ( "do be roundgen pdf dm" ) ) {
if ( message . content . toLowerCase ( ) === ( "do be roundgen pdf dm" ) ) {
fs . writeFile ( 'index.html' , "<h1>Here's your round!</h1>" , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
fs . writeFile ( 'index.html' , "<h1>Here's your round!</h1>" , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
var person = client . users . cache . get ( message . author . id ) ;
const person = client . users . cache . get ( message . author . id ) ;
var i ;
let i ;
let generatingMsg = await message . channel . send ( "Generating..." ) ;
let generatingMsg = await message . channel . send ( "Generating..." ) ;
for ( i = 1 ; i < 26 ; i ++ ) {
for ( i = 1 ; i < 26 ; i ++ ) {
var tossup_question ;
const tossup_question ;
var question_category ;
const question_category ;
var tossup_format ;
const tossup_format ;
var tossup_answer ;
const tossup_answer ;
var bonus_question ;
const bonus_question ;
var bonus_format ;
const bonus_format ;
var bonus_answer ;
const bonus_answer ;
var htmlContent = "" ;
const htmlContent = "" ;
await fetch ( 'https://scibowldb.com/api/questions/random' )
await fetch ( 'https://scibowldb.com/api/questions/random' )
. then ( response => response . json ( ) )
. then ( response => response . json ( ) )
. then ( data => {
. then ( data => {
@ -148,24 +148,23 @@ client.on('message', async message => {
} ) ;
} ) ;
}
}
generatingMsg . delete ( { timeout : 1000 } ) ;
generatingMsg . delete ( { timeout : 1000 } ) ;
var output = execSync ( "curl --request POST --url http://localhost:3136/convert/html --header 'Content-Type: multipart/form-data' --form files=@index.html -o round.pdf" , { encoding : 'utf-8' } ) ;
execSync ( "curl --request POST --url http://localhost:3136/convert/html --header 'Content-Type: multipart/form-data' --form files=@index.html -o round.pdf" , { encoding : 'utf-8' } ) ;
//console.log(output);
setTimeout ( function ( ) { person . send ( new Discord . MessageEmbed ( ) . setTitle ( "Here's your round!" ) . attachFiles ( "round.pdf" ) ) ; } , 1000 ) ;
setTimeout ( function ( ) { person . send ( new Discord . MessageEmbed ( ) . setTitle ( "Here's your round!" ) . attachFiles ( "round.pdf" ) ) ; } , 1000 ) ;
hits ++ ;
hits ++ ;
}
}
if ( message . content . toLowerCase ( ) === ( "do be roundgen pdf" ) ) {
if ( message . content . toLowerCase ( ) === ( "do be roundgen pdf" ) ) {
fs . writeFile ( 'index.html' , "<h1>Here's your round!</h1>" , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
fs . writeFile ( 'index.html' , "<h1>Here's your round!</h1>" , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
var i ;
let i ;
let generatingMsg = await message . channel . send ( "Generating..." ) ;
let generatingMsg = await message . channel . send ( "Generating..." ) ;
for ( i = 1 ; i < 26 ; i ++ ) {
for ( i = 1 ; i < 26 ; i ++ ) {
var tossup_question ;
const tossup_question ;
var question_category ;
const question_category ;
var tossup_format ;
const tossup_format ;
var tossup_answer ;
const tossup_answer ;
var bonus_question ;
const bonus_question ;
var bonus_format ;
const bonus_format ;
var bonus_answer ;
const bonus_answer ;
var htmlContent = "" ;
const htmlContent = "" ;
await fetch ( 'https://scibowldb.com/api/questions/random' )
await fetch ( 'https://scibowldb.com/api/questions/random' )
. then ( response => response . json ( ) )
. then ( response => response . json ( ) )
. then ( data => {
. then ( data => {
@ -183,15 +182,14 @@ client.on('message', async message => {
} ) ;
} ) ;
}
}
generatingMsg . delete ( { timeout : 1000 } ) ;
generatingMsg . delete ( { timeout : 1000 } ) ;
var output = execSync ( "curl --request POST --url http://localhost:3136/convert/html --header 'Content-Type: multipart/form-data' --form files=@index.html -o round.pdf" , { encoding : 'utf-8' } ) ;
execSync ( "curl --request POST --url http://localhost:3136/convert/html --header 'Content-Type: multipart/form-data' --form files=@index.html -o round.pdf" , { encoding : 'utf-8' } ) ;
//console.log(output);
message . channel . send ( new Discord . MessageEmbed ( ) . setTitle ( "Here's your round!" ) . attachFiles ( "round.pdf" ) ) ;
message . channel . send ( new Discord . MessageEmbed ( ) . setTitle ( "Here's your round!" ) . attachFiles ( "round.pdf" ) ) ;
hits ++ ;
hits ++ ;
}
}
if ( message . content . toLowerCase ( ) === "do be scoring" ) {
if ( message . content . toLowerCase ( ) === "do be scoring" ) {
var scoreA = 0 ;
let scoreA = 0 ;
var scoreB = 0 ;
let scoreB = 0 ;
le t scoreboard = await message . channel . send ( ` Here's the score: \n Team A: ${ scoreA } \n Team B: ${ scoreB } ` )
cons t scoreboard = await message . channel . send ( ` Here's the score: \n Team A: ${ scoreA } \n Team B: ${ scoreB } ` )
. then ( ( scoreboard ) => {
. then ( ( scoreboard ) => {
const filter = m => m . content . includes ( 'do be' ) ;
const filter = m => m . content . includes ( 'do be' ) ;
const collector = message . channel . createMessageCollector ( filter , { time : 1500000 } ) ;
const collector = message . channel . createMessageCollector ( filter , { time : 1500000 } ) ;
@ -231,19 +229,12 @@ client.on('message', async message => {
await fetch ( "http://api.open-notify.org/iss-now.json" )
await fetch ( "http://api.open-notify.org/iss-now.json" )
. then ( request => request . json ( ) )
. then ( request => request . json ( ) )
. then ( data => {
. then ( data => {
//var astros = '';
message . channel . send ( new Discord . MessageEmbed ( ) . setTitle ( "The current location of the ISS!" ) . setImage ( ` https://api.mapbox.com/styles/v1/mapbox/light-v10/static/pin-s+000( ${ data . iss_position . longitude } , ${ data . iss_position . latitude } )/-87.0186,20,1/1000x1000?access_token=pk.eyJ1IjoiYWRhd2Vzb21lZ3V5IiwiYSI6ImNrbGpuaWdrYzJ0bGYydXBja2xsNmd2YTcifQ.Ude0UFOf9lFcQ-3BANWY5A ` ) . setURL ( 'https://spotthestation.nasa.gov/tracking_map.cfm' ) ;
//for (let i = 0; i < data.people.length; i++) {
// console.log(data.people[i]);
// astros += `${data.people[i]}\n`;
//}
message . channel . send ( new Discord . MessageEmbed ( ) . setTitle ( "The current location of the ISS!" ) . setImage ( ` https://api.mapbox.com/styles/v1/mapbox/light-v10/static/pin-s+000( ${ data . iss_position . longitude } , ${ data . iss_position . latitude } )/-87.0186,20,1/1000x1000?access_token=pk.eyJ1IjoiYWRhd2Vzb21lZ3V5IiwiYSI6ImNrbGpuaWdrYzJ0bGYydXBja2xsNmd2YTcifQ.Ude0UFOf9lFcQ-3BANWY5A ` ) . setURL ( 'https://spotthestation.nasa.gov/tracking_map.cfm' ) / * . addFields (
{ name : 'Current inhabitants' , value : ` ${ astros } ` }
) * / ) ;
} ) ;
} ) ;
}
}
if ( message . content . startsWith ( "do be training" ) ) {
if ( message . content . startsWith ( "do be training" ) ) {
if ( message . content === "do be training" ) {
if ( message . content === "do be training" ) {
var author = message . author ;
const author = message . author ;
fetch ( "https://scibowldb.com/api/questions/random" )
fetch ( "https://scibowldb.com/api/questions/random" )
. then ( response => response . json ( ) )
. then ( response => response . json ( ) )
. then ( data => {
. then ( data => {
@ -256,7 +247,7 @@ client.on('message', async message => {
} )
} )
. then ( message => {
. then ( message => {
message = message . first ( ) ;
message = message . first ( ) ;
var score = 0 ;
let score = 0 ;
if ( fs . existsSync ( ` userScore/ ${ message . author . id } ` ) ) {
if ( fs . existsSync ( ` userScore/ ${ message . author . id } ` ) ) {
fs . readFile ( ` userScore/ ${ message . author . id } ` , 'utf8' , function ( err , data ) {
fs . readFile ( ` userScore/ ${ message . author . id } ` , 'utf8' , function ( err , data ) {
score = Number ( data ) ;
score = Number ( data ) ;
@ -267,7 +258,7 @@ client.on('message', async message => {
} else {
} else {
fs . writeFile ( ` userScore/ ${ message . author . id } ` , score . toString ( ) , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
fs . writeFile ( ` userScore/ ${ message . author . id } ` , score . toString ( ) , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
}
}
var predicted = "unsure" ;
let predicted = "unsure" ;
if ( data . question . tossup_format === "Multiple Choice" ) {
if ( data . question . tossup_format === "Multiple Choice" ) {
if ( message . content . charAt ( 0 ) . toLowerCase ( ) === data . question . tossup_answer . charAt ( 0 ) . toLowerCase ( ) ) {
if ( message . content . charAt ( 0 ) . toLowerCase ( ) === data . question . tossup_answer . charAt ( 0 ) . toLowerCase ( ) ) {
predicted = "correct" ;
predicted = "correct" ;
@ -289,7 +280,7 @@ client.on('message', async message => {
} ;
} ;
message . awaitReactions ( filter , { max : 1 , time : 600000 , errors : [ 'time' ] } )
message . awaitReactions ( filter , { max : 1 , time : 600000 , errors : [ 'time' ] } )
. then ( reaction => {
. then ( reaction => {
var reaction = reaction . first ( ) ;
const reaction = reaction . first ( ) ;
if ( reaction . emoji . name === "❌" ) {
if ( reaction . emoji . name === "❌" ) {
fs . writeFile ( ` userScore/ ${ message . author . id } ` , score . toString ( ) , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
fs . writeFile ( ` userScore/ ${ message . author . id } ` , score . toString ( ) , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
message . reply ( ` nice try! Your score is now ${ score } ` ) ;
message . reply ( ` nice try! Your score is now ${ score } ` ) ;
@ -301,7 +292,6 @@ client.on('message', async message => {
}
}
} )
} )
. catch ( collected => {
. catch ( collected => {
//message.channel.send("\n**REACTION TIMEOUT**");
} )
} )
} )
} )
. catch ( ( collected , error ) => {
. catch ( ( collected , error ) => {
@ -310,8 +300,8 @@ client.on('message', async message => {
} )
} )
} )
} )
} else {
} else {
var subject = message . content . substring ( 15 ) ;
const subject = message . content . substring ( 15 ) ;
var subjectURL ;
let subjectURL ;
switch ( subject ) {
switch ( subject ) {
case 'astro' :
case 'astro' :
subjectURL = ` https://moose.lcsrc.org/subjects/astronomy.json ` ;
subjectURL = ` https://moose.lcsrc.org/subjects/astronomy.json ` ;
@ -335,11 +325,11 @@ client.on('message', async message => {
subjectURL = ` https://scibowldb.com/api/questions/random ` ;
subjectURL = ` https://scibowldb.com/api/questions/random ` ;
break ;
break ;
}
}
var author = message . author ;
const author = message . author ;
fetch ( subjectURL )
fetch ( subjectURL )
. then ( response => response . json ( ) )
. then ( response => response . json ( ) )
. then ( data => {
. then ( data => {
var questionNum = Math . floor ( Math . random ( ) * data . length ) ;
const questionNum = Math . floor ( Math . random ( ) * data . length ) ;
let filter = m => m . author . id === message . author . id ;
let filter = m => m . author . id === message . author . id ;
message . reply ( data [ questionNum ] . tossup_question ) . then ( ( ) => {
message . reply ( data [ questionNum ] . tossup_question ) . then ( ( ) => {
message . channel . awaitMessages ( filter , {
message . channel . awaitMessages ( filter , {
@ -349,7 +339,7 @@ client.on('message', async message => {
} )
} )
. then ( message => {
. then ( message => {
message = message . first ( ) ;
message = message . first ( ) ;
var score = 0 ;
let score = 0 ;
if ( fs . existsSync ( ` userScore/ ${ message . author . id } ` ) ) {
if ( fs . existsSync ( ` userScore/ ${ message . author . id } ` ) ) {
fs . readFile ( ` userScore/ ${ message . author . id } ` , 'utf8' , function ( err , data ) {
fs . readFile ( ` userScore/ ${ message . author . id } ` , 'utf8' , function ( err , data ) {
score = Number ( data ) ;
score = Number ( data ) ;
@ -360,7 +350,7 @@ client.on('message', async message => {
} else {
} else {
fs . writeFile ( ` userScore/ ${ message . author . id } ` , score . toString ( ) , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
fs . writeFile ( ` userScore/ ${ message . author . id } ` , score . toString ( ) , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
}
}
var predicted = "unsure" ;
let predicted = "unsure" ;
if ( data [ questionNum ] . tossup_format === "Multiple Choice" ) {
if ( data [ questionNum ] . tossup_format === "Multiple Choice" ) {
if ( message . content . charAt ( 0 ) . toLowerCase ( ) === data [ questionNum ] . tossup_answer . charAt ( 0 ) . toLowerCase ( ) ) {
if ( message . content . charAt ( 0 ) . toLowerCase ( ) === data [ questionNum ] . tossup_answer . charAt ( 0 ) . toLowerCase ( ) ) {
predicted = "correct" ;
predicted = "correct" ;
@ -382,7 +372,7 @@ client.on('message', async message => {
} ;
} ;
message . awaitReactions ( filter , { max : 1 , time : 600000 , errors : [ 'time' ] } )
message . awaitReactions ( filter , { max : 1 , time : 600000 , errors : [ 'time' ] } )
. then ( reaction => {
. then ( reaction => {
var reaction = reaction . first ( ) ;
const reaction = reaction . first ( ) ;
if ( reaction . emoji . name === "❌" ) {
if ( reaction . emoji . name === "❌" ) {
fs . writeFile ( ` userScore/ ${ message . author . id } ` , score . toString ( ) , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
fs . writeFile ( ` userScore/ ${ message . author . id } ` , score . toString ( ) , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
message . reply ( ` nice try! Your score is now ${ score } ` ) ;
message . reply ( ` nice try! Your score is now ${ score } ` ) ;
@ -394,7 +384,6 @@ client.on('message', async message => {
}
}
} )
} )
. catch ( collected => {
. catch ( collected => {
//message.channel.send("\n**REACTION TIMEOUT**");
} )
} )
} )
} )
. catch ( ( collected , error ) => {
. catch ( ( collected , error ) => {
@ -416,9 +405,9 @@ client.on('message', async message => {
files . forEach ( function ( file ) {
files . forEach ( function ( file ) {
scores . push ( ` ${ fs . readFileSync ( 'userScore/' + file , 'utf8' ) } |<@ ${ file } > ` )
scores . push ( ` ${ fs . readFileSync ( 'userScore/' + file , 'utf8' ) } |<@ ${ file } > ` )
} ) ;
} ) ;
var scoresFormatted = scores . sort ( function ( a , b ) { return b . split ( '|' ) [ 0 ] - a . split ( '|' ) [ 0 ] } ) ;
const scoresFormatted = scores . sort ( function ( a , b ) { return b . split ( '|' ) [ 0 ] - a . split ( '|' ) [ 0 ] } ) ;
for ( var i = 0 ; i < 10 ; i ++ ) {
for ( let i = 0 ; i < 10 ; i ++ ) {
var currentScore = scoresFormatted [ i ] . split ( '|' ) ;
const currentScore = scoresFormatted [ i ] . split ( '|' ) ;
messageContent += ` ${ currentScore [ 1 ] } : ${ currentScore [ 0 ] } \n \n ` ;
messageContent += ` ${ currentScore [ 1 ] } : ${ currentScore [ 0 ] } \n \n ` ;
}
}
message . channel . send ( new Discord . MessageEmbed ( ) . setTitle ( 'Top Ten!' ) . setDescription ( messageContent ) ) ;
message . channel . send ( new Discord . MessageEmbed ( ) . setTitle ( 'Top Ten!' ) . setDescription ( messageContent ) ) ;