@ -1,69 +1,65 @@
#!/usr/bin/env node
#!/usr/bin/env node
import * as Discord from 'discord.js' ;
import * as Discord from "discord.js" ;
import { execSync } from 'child_process' ;
import { execSync } from "child_process" ;
const client = new Discord . Client ( { partials : [ 'MESSAGE' , 'CHANNEL' , 'REACTION' ] } ) ;
const client = new Discord . Client ( {
import fetch from 'node-fetch' ;
partials : [ "MESSAGE" , "CHANNEL" , "REACTION" ] ,
import * as fs from 'fs' ;
import * as path from 'path' ;
let hits = 0 ;
const helpMessage = "`do be helping`: display this help message\n`do be roundgen`: send a pdf round to the channel\n`do be roundgen dm`: dm a pdf round to you\n`do be scoring`: start a scoring session\n > `do be scoring (a/b)(4/10)`: add points to Team A or Team B\n > `do be scoring stop`: end scoring session and post final points\n`do be hits`: send the number of rounds generated\n`do be servers`: send the number of servers this bot is a part of\n`do be iss`: show the current location of the International Space Station\n`do be training`: send a quick practice problem (you **must** react to your answer, or the bot will yell at you)\n > subject options: astro, phys, chem, math, bio, ess, energy\n`do be top`: list cross-server top 10 players\nSource Code: https://github.com/ADawesomeguy/AwesomeSciBo (don't forget to star!)" ;
if ( fs . existsSync ( 'numhits.txt' ) ) {
fs . readFile ( 'numhits.txt' , 'utf8' , function ( err , data ) {
hits = data ;
if ( err ) {
console . log ( err ) ;
}
} ) ;
} ) ;
} else {
import fetch from "node-fetch" ;
fs . writeFile ( 'numhits.txt' , hits . toString ( ) , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
import * as fs from "fs" ;
}
import * as path from "path" ;
import axios from "axios" ;
import userScore from "./mongooseModels/mongooseUserScoreModel.js" ;
import { } from 'dotenv/config.js' ;
const helpMessage =
"`do be helping`: display this help message\n`do be roundgen`: send a pdf round to the channel\n`do be roundgen dm`: dm a pdf round to you\n`do be scoring`: start a scoring session\n > `do be scoring (a/b)(4/10)`: add points to Team A or Team B\n > `do be scoring stop`: end scoring session and post final points\n > `do be servers`: send the number of servers this bot is a part of\n > `do be iss`: show the current location of the International Space Station\n`do be training`: send a quick practice problem (you **must** react to your answer, or the bot will yell at you)\n > subject options: astro, phys, chem, math, bio, ess, energy\n`do be top`: list cross-server top 10 players\nSource Code: https://github.com/ADawesomeguy/AwesomeSciBo (don't forget to star!)" ;
client . once ( 'ready' , ( ) => {
client . once ( "ready" , ( ) => {
console . log ( client . user . username ) ;
console . log ( client . user . username ) ;
client . user . setActivity ( "for \"do be helping\" | Add me to your own server: adat.link/awscibo" , { type : "WATCHING" } ) ;
client . user . setActivity (
'for "do be helping" | Add me to your own server: adat.link/awscibo' ,
{ type : "WATCHING" }
) ;
} ) ;
} ) ;
client . on ( 'guildCreate' , guild => {
client . on ( "guildCreate" , ( guild ) => {
guild . channels . cache . find ( channel => channel . name === 'general' && channel . type === 'text' ) . send ( "'Sup, I'm the AwesomeSciBo bot!" ) . catch ( console . error ) ;
guild . channels . cache
. find ( ( channel ) => channel . name === "general" && channel . type === "text" )
. send ( "'Sup, I'm the AwesomeSciBo bot!" )
. catch ( console . error ) ;
} ) ;
} ) ;
client . on ( 'message' , async message => {
client . on ( "message" , async ( message ) => {
if ( message . author . bot ) {
if ( message . author . bot ) {
return ;
return ;
}
}
const formattedMessage = message . content . toLowerCase ( ) . replace ( /\s+/g , '' ) ;
const formattedMessage = message . content . toLowerCase ( ) . replace ( /\s+/g , "" ) ;
if ( formattedMessage . startsWith ( "dobe" ) ) {
if ( formattedMessage . startsWith ( "dobe" ) ) {
switch ( formattedMessage ) {
switch ( formattedMessage ) {
case 'dobehits' :
case "dobehelping" :
checkHits ( ) ;
break ;
case 'dobehelping' :
sendHelpMessage ( ) ;
sendHelpMessage ( ) ;
break ;
break ;
case 'doberoundgen' :
case "doberoundgen" :
generateRound ( false ) ;
generateRound ( false ) ;
break ;
break ;
case 'doberoundgendm' :
case "doberoundgendm" :
generateRound ( true ) ;
generateRound ( true ) ;
break ;
break ;
case 'dobescoring' :
case "dobescoring" :
startScoring ( ) ;
startScoring ( ) ;
break ;
break ;
case 'dobetop' :
case "dobetop" :
showLeaderboard ( ) ;
showLeaderboard ( ) ;
break ;
break ;
case 'dobehappy' :
case "dobehappy" :
dontWorryBeHappy ( ) ;
dontWorryBeHappy ( ) ;
break ;
break ;
case 'dobeservers' :
case "dobeservers" :
showServerNumber ( ) ;
showServerNumber ( ) ;
break ;
break ;
case 'dobeiss' :
case "dobeiss" :
showIssLocation ( ) ;
showIssLocation ( ) ;
break ;
break ;
default :
default :
@ -72,10 +68,15 @@ client.on('message', async message => {
}
}
async function otherCommands ( ) {
async function otherCommands ( ) {
if ( message . content . toLowerCase ( ) . startsWith ( "do be announcing" ) && message . author . id === process . argv [ 3 ] ) {
if (
message . content . toLowerCase ( ) . startsWith ( "do be announcing" ) &&
message . author . id === process . argv [ 3 ]
) {
const announcement = message . content . substring ( 17 ) ;
const announcement = message . content . substring ( 17 ) ;
client . guilds . cache . forEach ( ( guild ) => {
client . guilds . cache . forEach ( ( guild ) => {
const 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 ) ;
@ -83,101 +84,52 @@ client.on('message', async message => {
}
}
} ) ;
} ) ;
} else if ( message . content . toLowerCase ( ) . startsWith ( "do be training" ) ) {
} else if ( message . content . toLowerCase ( ) . startsWith ( "do be training" ) ) {
// BEGIN CHANGES
if ( message . content === "do be training" ) {
if ( message . content === "do be training" ) {
const author = message . author ;
axios . get ( "https://scibowldb.com/api/questions/random" ) . then ( data => {
fetch ( "https://scibowldb.com/api/questions/random" )
const messageAuthorFilter = ( m ) => m . author . id === message . author . id ;
. then ( response => response . json ( ) )
message
. then ( data => {
. reply ( data . data . question . tossup_question )
let filter = m => m . author . id === message . author . id ;
. then ( ( ) => {
message . reply ( data . question . tossup_question ) . then ( ( ) => {
message . channel . awaitMessages ( messageAuthorFilter , {
message . channel . awaitMessages ( filter , {
max : 1 ,
max : 1 ,
time : 30000 ,
time : 30000 ,
errors : [ 'time' ]
errors : [ "time" ] ,
} )
. then ( message => {
message = message . first ( ) ;
let score = 0 ;
if ( fs . existsSync ( ` userScore/ ${ message . author . id } ` ) ) {
fs . readFile ( ` userScore/ ${ message . author . id } ` , 'utf8' , function ( err , data ) {
score = Number ( data ) ;
if ( err ) {
console . log ( err ) ;
}
} ) ;
} ) ;
} else {
fs . writeFile ( ` userScore/ ${ message . author . id } ` , score . toString ( ) , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
}
let predicted = "unsure" ;
if ( data . question . tossup_format === "Multiple Choice" ) {
if ( message . content . charAt ( 0 ) . toLowerCase ( ) === data . question . tossup_answer . charAt ( 0 ) . toLowerCase ( ) ) {
predicted = "correct" ;
} else {
predicted = "incorrect" ;
}
} else {
if ( message . content . toLowerCase ( ) === data . question . tossup_answer . toLowerCase ( ) ) {
predicted = "correct" ;
} else {
predicted = "incorrect" ;
}
}
message . channel . send ( ` Correct answer: ** ${ data . question . tossup_answer } **. Predicted: ** ${ predicted } **. Please react to your answer! ` ) ;
message . react ( '✅' ) ;
message . react ( '❌' ) ;
const filter = ( reaction , user ) => {
return [ '❌' , '✅' ] . includes ( reaction . emoji . name ) && user . id === message . author . id ;
} ;
message . awaitReactions ( filter , { max : 1 , time : 600000 , errors : [ 'time' ] } )
. then ( userReaction => {
const reaction = userReaction . first ( ) ;
if ( reaction . emoji . name === "❌" ) {
fs . writeFile ( ` userScore/ ${ message . author . id } ` , score . toString ( ) , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
message . reply ( ` nice try! Your score is now ${ score } ` ) ;
} else {
score += 4 ;
fs . writeFile ( ` userScore/ ${ message . author . id } ` , score . toString ( ) , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
message . reply ( ` nice job! Your score is now ${ score } ` ) ;
fs . writeFile ( ` userScore/ ${ message . author . id } ` , score . toString ( ) , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
}
} )
. catch ( collected => {
} )
} )
. catch ( ( collected , error ) => {
message . reply ( '\n**ANSWER TIMEOUT**' ) ;
} )
} )
} )
} )
. then ( ( message ) => {
const responseAuthorID = message . first ( ) . author . id ;
} ) ;
} ) ;
} else {
} else {
const subject = message . content . substring ( 15 ) ;
const subject = message . content . substring ( 15 ) ;
let subjectURL ;
let subjectURL ;
switch ( subject ) {
switch ( subject ) {
case 'astro' :
case "astro" :
case 'astronomy' :
case "astronomy" :
subjectURL = ` https://moose.lcsrc.org/subjects/astronomy.json ` ;
subjectURL = ` https://moose.lcsrc.org/subjects/astronomy.json ` ;
break ;
break ;
case 'bio' :
case "bio" :
case 'biology' :
case "biology" :
subjectURL = ` https://moose.lcsrc.org/subjects/biology.json ` ;
subjectURL = ` https://moose.lcsrc.org/subjects/biology.json ` ;
break ;
break ;
case 'ess' :
case "ess" :
case 'earth science' :
case "earth science" :
case 'es' :
case "es" :
subjectURL = ` https://moose.lcsrc.org/subjects/ess.json ` ;
subjectURL = ` https://moose.lcsrc.org/subjects/ess.json ` ;
break ;
break ;
case 'chem' :
case "chem" :
case 'chemistry' :
case "chemistry" :
subjectURL = ` https://moose.lcsrc.org/subjects/chemistry.json ` ;
subjectURL = ` https://moose.lcsrc.org/subjects/chemistry.json ` ;
break ;
break ;
case 'phys' :
case "phys" :
case 'physics' :
case "physics" :
subjectURL = ` https://moose.lcsrc.org/subjects/physics.json ` ;
subjectURL = ` https://moose.lcsrc.org/subjects/physics.json ` ;
break ;
break ;
case 'math' :
case "math" :
subjectURL = ` https://moose.lcsrc.org/subjects/math.json ` ;
subjectURL = ` https://moose.lcsrc.org/subjects/math.json ` ;
break ;
break ;
case 'energy' :
case "energy" :
subjectURL = ` https://moose.lcsrc.org/subjects/energy.json ` ;
subjectURL = ` https://moose.lcsrc.org/subjects/energy.json ` ;
break ;
break ;
default :
default :
@ -185,71 +137,98 @@ client.on('message', async message => {
return ;
return ;
break ;
break ;
}
}
const author = message . author ;
const authorId = message . author . id ;
fetch ( subjectURL )
fetch ( subjectURL )
. then ( response => response . json ( ) )
. then ( ( response ) => response . json ( ) )
. then ( data => {
. then ( ( data ) => {
const questionNum = Math . floor ( Math . random ( ) * data . length ) ;
const questionNum = Math . floor ( Math . random ( ) * data . length ) ;
let filter = m => m . author . id === message . author . i d;
const messageFilter = ( m ) => m . author . id === authorI d;
message . reply ( data [ questionNum ] . tossup_question ) . then ( ( ) => {
message . reply ( data [ questionNum ] . tossup_question ) . then ( ( ) => {
message . channel . awaitMessages ( filter , {
message . channel
. awaitMessages ( messageFilter , {
max : 1 ,
max : 1 ,
time : 30000 ,
time : 30000 ,
errors : [ 'time' ]
errors : [ "time" ] ,
} )
} )
. then ( message => {
. then ( ( answerMsg ) => {
message = message . first ( ) ;
answerMsg = answerMsg . first ( ) ;
let score = 0 ;
let score =
if ( fs . existsSync ( ` userScore/ ${ message . author . id } ` ) ) {
userScore . findOne ( { authorID : authorId } ) . select ( "score" ) ||
fs . readFile ( ` userScore/ ${ message . author . id } ` , 'utf8' , function ( err , data ) {
0 ;
score = Number ( data ) ;
let predicted = null ;
if ( err ) {
console . log ( err ) ;
}
} ) ;
} else {
fs . writeFile ( ` userScore/ ${ message . author . id } ` , score . toString ( ) , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
}
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 (
answerMsg . content . charAt ( 0 ) . toLowerCase ( ) ===
data [ questionNum ] . tossup_answer . charAt ( 0 ) . toLowerCase ( )
) {
predicted = "correct" ;
predicted = "correct" ;
} else {
} else {
predicted = "incorrect" ;
predicted = "incorrect" ;
}
}
} else {
} else {
if ( message . content . toLowerCase ( ) === data [ questionNum ] . tossup_answer . toLowerCase ( ) ) {
if (
answerMsg . content . toLowerCase ( ) ===
data [ questionNum ] . tossup_answer . toLowerCase ( )
) {
predicted = "correct" ;
predicted = "correct" ;
} else {
} else {
predicted = "incorrect" ;
predicted = "incorrect" ;
}
}
}
}
message . channel . send ( ` Correct answer: ** ${ data [ questionNum ] . tossup_answer } **. Predicted: ** ${ predicted } **. Please react to your answer! ` ) ;
answerMsg . channel . send (
message . react ( '✅' ) ;
` Correct answer: ** ${ data [ questionNum ] . tossup_answer } **. Predicted: ** ${ predicted } **. Please react to your answer! `
message . react ( '❌' ) ;
) ;
const filter = ( reaction , user ) => {
answerMsg . react ( "✅" ) ;
return [ '❌' , '✅' ] . includes ( reaction . emoji . name ) && user . id === message . author . id ;
answerMsg . react ( "❌" ) ;
const reactionFilter = ( reaction , user ) => {
return (
[ "❌" , "✅" ] . includes ( reaction . emoji . name ) &&
user . id === answerMsg . author . id
) ;
} ;
} ;
message . awaitReactions ( filter , { max : 1 , time : 600000 , errors : [ 'time' ] } )
answerMsg
. then ( userReaction => {
. awaitReactions ( reactionFilter , {
max : 1 ,
time : 600000 ,
errors : [ "time" ] ,
} )
. then ( async ( userReaction ) => {
const reaction = userReaction . first ( ) ;
const reaction = userReaction . first ( ) ;
if ( reaction . emoji . name === "❌" ) {
if ( reaction . emoji . name === "❌" ) {
fs . writeFile ( ` userScore/ ${ message . author . id } ` , score . toString ( ) , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
answerMsg . reply ( ` nice try! Your score is now ${ score } ` ) ;
message . reply ( ` nice try! Your score is now ${ score } ` ) ;
} else {
} else {
score += 4 ;
score += 4 ;
fs . writeFile ( ` userScore/ ${ message . author . id } ` , score . toString ( ) , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
if ( score == 4 ) {
message . reply ( ` nice job! Your score is now ${ score } ` ) ;
const newUserScore = new userScore ( {
fs . writeFile ( ` userScore/ ${ message . author . id } ` , score . toString ( ) , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
authorID : authorId ,
score : score ,
} ) ;
newUserScore . save ( ( err ) =>
err
? console . log (
"Error creating new user for scoring"
)
: console . log (
"Sucessfully created user to score."
)
) ;
} else {
const doc = await userScore . findOne ( {
authorID : authorId ,
} ) ;
doc . score = doc . score + 4 ;
doc . save ( ) ;
}
answerMsg . reply ( ` nice job! Your score is now ${ score } ` ) ;
}
}
} )
} )
. catch ( collected => {
. catch ( ( collected ) => { } ) ;
} )
} )
} )
. catch ( ( collected , error ) => {
. catch ( ( collected , error ) => {
message . reply ( '\n**ANSWER TIMEOUT**' ) ;
message . reply ( "\n**ANSWER TIMEOUT**" ) ;
} )
} ) ;
} )
} ) ;
} )
} )
. catch ( console . error ) ;
. catch ( console . error ) ;
}
}
@ -257,21 +236,24 @@ client.on('message', async message => {
if ( formattedMessage . startsWith ( "dobescoring" || "dobetraining" ) ) {
if ( formattedMessage . startsWith ( "dobescoring" || "dobetraining" ) ) {
return ;
return ;
}
}
message . channel . send ( "That didn't quite make sense! Please use `do be helping` to see the available commands." )
message . channel . send (
"That didn't quite make sense! Please use `do be helping` to see the available commands."
) ;
}
}
}
}
async function checkHits ( ) {
message . channel . send ( hits ) ;
fs . writeFile ( 'numhits.txt' , hits . toString ( ) , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
}
async function sendHelpMessage ( ) {
async function sendHelpMessage ( ) {
message . channel . send ( new Discord . MessageEmbed ( ) . setTitle ( "Help" ) . setDescription ( helpMessage ) ) ;
message . channel . send (
new Discord . MessageEmbed ( ) . setTitle ( "Help" ) . setDescription ( helpMessage )
) ;
}
}
async function generateRound ( isDM ) {
async function generateRound ( isDM ) {
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 ) ;
}
} ) ;
let 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 ++ ) {
@ -283,9 +265,9 @@ client.on('message', async message => {
let bonus_format ;
let bonus_format ;
let bonus_answer ;
let bonus_answer ;
let htmlContent = "" ;
let 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 ) => {
tossup_question = data . question . tossup_question ;
tossup_question = data . question . tossup_question ;
tossup_answer = data . question . tossup_answer ;
tossup_answer = data . question . tossup_answer ;
question_category = data . question . category ;
question_category = data . question . category ;
@ -293,59 +275,118 @@ client.on('message', async message => {
bonus_question = data . question . bonus_question ;
bonus_question = data . question . bonus_question ;
bonus_answer = data . question . bonus_answer ;
bonus_answer = data . question . bonus_answer ;
bonus_format = data . question . bonus_format ;
bonus_format = data . question . bonus_format ;
htmlContent = ` <br><br> ${ i } . Tossup \n <br><br> ` + ` <strong> ${ question_category } </strong> ` + " " + ` <em> ${ tossup_format } </em> ` + " " + tossup_question + "<br><br>" + "<strong>ANSWER:</strong> " + tossup_answer + "<br><br>" ;
htmlContent =
htmlContent += "<br><br>Bonus\n<br><br>" + ` <strong> ${ question_category } </strong> ` + " " + ` <em> ${ bonus_format } </em> ` + " " + bonus_question + "<br><br>" + "<strong>ANSWER:</strong> " + bonus_answer + "<br><br>" ;
` <br><br> ${ i } . Tossup \n <br><br> ` +
` <strong> ${ question_category } </strong> ` +
" " +
` <em> ${ tossup_format } </em> ` +
" " +
tossup_question +
"<br><br>" +
"<strong>ANSWER:</strong> " +
tossup_answer +
"<br><br>" ;
htmlContent +=
"<br><br>Bonus\n<br><br>" +
` <strong> ${ question_category } </strong> ` +
" " +
` <em> ${ bonus_format } </em> ` +
" " +
bonus_question +
"<br><br>" +
"<strong>ANSWER:</strong> " +
bonus_answer +
"<br><br>" ;
htmlContent = htmlContent . replace ( /\n/g , "<br>" ) ;
htmlContent = htmlContent . replace ( /\n/g , "<br>" ) ;
fs . appendFile ( 'index.html' , htmlContent , ( error ) => { if ( error ) { console . log ( error ) ; } } ) ;
fs . appendFile ( "index.html" , htmlContent , ( error ) => {
if ( error ) {
console . log ( error ) ;
}
} ) ;
} ) ;
} ) ;
}
}
if ( generatingMsg ) {
if ( generatingMsg ) {
generatingMsg . delete ( { timeout : 100 } ) . catch ( console . error ) ;
generatingMsg . delete ( { timeout : 100 } ) . catch ( console . error ) ;
}
}
execSync ( "curl --request POST --url https://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 https://localhost:3136/convert/html --header 'Content-Type: multipart/form-data' --form files=@index.html -o round.pdf" ,
{ encoding : "utf-8" }
) ;
if ( isDM ) {
if ( isDM ) {
client . users . cache . get ( message . author . id ) . send ( new Discord . MessageEmbed ( ) . setTitle ( "Here's your round!" ) . attachFiles ( "round.pdf" ) ) . catch ( ( ) => message . reply ( "Unable to DM you! Make sure DMs from server members are allowed." ) ) ;
client . users . cache
. get ( message . author . id )
. send (
new Discord . MessageEmbed ( )
. setTitle ( "Here's your round!" )
. attachFiles ( "round.pdf" )
)
. catch ( ( ) =>
message . reply (
"Unable to DM you! Make sure DMs from server members are allowed."
)
) ;
} else {
} else {
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 ++ ;
}
}
async function startScoring ( ) {
async function startScoring ( ) {
let scoreA = 0 ;
let scoreA = 0 ;
let scoreB = 0 ;
let scoreB = 0 ;
const scoreboard = await message . channel . send ( ` Here's the score: \n Team A: ${ scoreA } \n Team B: ${ scoreB } ` )
const 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 , {
collector . on ( 'collect' , m => {
time : 1500000 ,
} ) ;
collector . on ( "collect" , ( m ) => {
if ( m . content . toLowerCase ( ) === "do be scoring a 4" ) {
if ( m . content . toLowerCase ( ) === "do be scoring a 4" ) {
m . delete ( { timeout : 1000 } ) . catch ( console . error ) ;
m . delete ( { timeout : 1000 } ) . catch ( console . error ) ;
scoreA += 4 ;
scoreA += 4 ;
scoreboard . channel . send ( ` Here's the score: \n Team A: ${ scoreA } \n Team B: ${ scoreB } ` ) ;
scoreboard . channel . send (
` Here's the score: \n Team A: ${ scoreA } \n Team B: ${ scoreB } `
) ;
} else if ( m . content . toLowerCase ( ) === "do be scoring a 10" ) {
} else if ( m . content . toLowerCase ( ) === "do be scoring a 10" ) {
m . delete ( { timeout : 1000 } ) . catch ( console . error ) ;
m . delete ( { timeout : 1000 } ) . catch ( console . error ) ;
scoreA += 10 ;
scoreA += 10 ;
scoreboard . channel . send ( ` Here's the score: \n Team A: ${ scoreA } \n Team B: ${ scoreB } ` ) ;
scoreboard . channel . send (
` Here's the score: \n Team A: ${ scoreA } \n Team B: ${ scoreB } `
) ;
} else if ( m . content . toLowerCase ( ) === "do be scoring b 4" ) {
} else if ( m . content . toLowerCase ( ) === "do be scoring b 4" ) {
m . delete ( { timeout : 1000 } ) . catch ( console . error ) ;
m . delete ( { timeout : 1000 } ) . catch ( console . error ) ;
scoreB += 4 ;
scoreB += 4 ;
scoreboard . channel . send ( ` Here's the score: \n Team A: ${ scoreA } \n Team B: ${ scoreB } ` ) ;
scoreboard . channel . send (
` Here's the score: \n Team A: ${ scoreA } \n Team B: ${ scoreB } `
) ;
} else if ( m . content . toLowerCase ( ) === "do be scoring b 10" ) {
} else if ( m . content . toLowerCase ( ) === "do be scoring b 10" ) {
m . delete ( { timeout : 1000 } ) . catch ( console . error ) ;
m . delete ( { timeout : 1000 } ) . catch ( console . error ) ;
scoreB += 10 ;
scoreB += 10 ;
scoreboard . channel . send ( ` Here's the score: \n Team A: ${ scoreA } \n Team B: ${ scoreB } ` ) ;
scoreboard . channel . send (
` Here's the score: \n Team A: ${ scoreA } \n Team B: ${ scoreB } `
) ;
} else if ( m . content === "do be scoring stop" ) {
} else if ( m . content === "do be scoring stop" ) {
m . delete ( { timeout : 1000 } ) . catch ( console . error ) ;
m . delete ( { timeout : 1000 } ) . catch ( console . error ) ;
scoreboard . delete ( { timeout : 1000 } ) ;
scoreboard . delete ( { timeout : 1000 } ) ;
m . channel . send ( ` **FINAL SCORE:** \n Team A: ${ scoreA } \n Team B: ${ scoreB } ` ) ;
m . channel . send (
` **FINAL SCORE:** \n Team A: ${ scoreA } \n Team B: ${ scoreB } `
) ;
collector . stop ( ) ;
collector . stop ( ) ;
}
}
} ) ;
} ) ;
} )
} ) ;
}
}
async function dontWorryBeHappy ( ) {
async function dontWorryBeHappy ( ) {
message . channel . send ( new Discord . MessageEmbed ( ) . setTitle ( ` Don't Worry Be Happy! ` ) . setImage ( "https://media.giphy.com/media/7OKC8ZpTT0PVm/giphy.gif" ) . setURL ( "https://youtu.be/d-diB65scQU" ) ) ;
message . channel . send (
new Discord . MessageEmbed ( )
. setTitle ( ` Don't Worry Be Happy! ` )
. setImage ( "https://media.giphy.com/media/7OKC8ZpTT0PVm/giphy.gif" )
. setURL ( "https://youtu.be/d-diB65scQU" )
) ;
}
}
async function showServerNumber ( ) {
async function showServerNumber ( ) {
@ -354,36 +395,53 @@ client.on('message', async message => {
async function showIssLocation ( ) {
async function showIssLocation ( ) {
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 ) => {
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' ) ) ;
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" )
) ;
} ) ;
} ) ;
}
}
async function showLeaderboard ( ) {
async function showLeaderboard ( ) {
let messageContent = '' ;
let messageContent = "" ;
let scores = [ ] ;
let scores = [ ] ;
const directoryPath = path . join ( 'userScore' ) ;
const directoryPath = path . join ( "userScore" ) ;
fs . readdir ( directoryPath , function ( err , files ) {
fs . readdir ( directoryPath , function ( err , files ) {
if ( err ) {
if ( err ) {
return console . log ( 'Unable to scan directory: ' + err ) ;
return console . log ( "Unable to scan directory: " + err ) ;
}
}
files . forEach ( function ( file ) {
files . forEach ( function ( file ) {
scores . push ( ` ${ fs . readFileSync ( 'userScore/' + file , 'utf8' ) } |<@ ${ file } > ` )
scores . push (
` ${ fs . readFileSync ( "userScore/" + file , "utf8" ) } |<@ ${ file } > `
) ;
} ) ;
const 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 ] } ) ;
if ( scores . length < 10 ) {
if ( scores . length < 10 ) {
message . channel . send ( "Not enough scores yet!" ) ;
message . channel . send ( "Not enough scores yet!" ) ;
return ;
return ;
}
}
for ( let i = 0 ; i < 10 ; i ++ ) {
for ( let i = 0 ; i < 10 ; i ++ ) {
const 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 )
) ;
} ) ;
} ) ;
}
}
} ) ;
} ) ;
client . login ( process . argv [ 2 ] ) . catch ( error => console . log ( error ) ) ;
client
. login ( "ODEzMTY0MTQ4NjM5OTI0Mjk2.YDLUIA.AGIG6Xo4TryATHectRt4o2z0nbY" )
. catch ( ( error ) => console . log ( error ) ) ;