javascript - Using node.js to create IRC bot. Message sends twice despite function only being called once -
i'm using node.js create irc bot asks trivia questions. far works great, wanted implement system generates hints providing underscores each letter. time passes, fills in blanks. if nobody gets answer before blanks filled in, bot moves on. (if not in single-question mode)
the issue: if nobody answers question, bot moves on next 1 intended. bot supplies two hints @ same time. repeats first hint, other times it's satisfying else
statement , providing next hint.
i have troubleshooted verify function gethint
being called once.
i've been staring @ code 2.5 hours , i'm beginning lose hope. i'm brand new javascript, first time coding in it. appreciated.
example 1: satisfies if (there no hint)
twice
bot> drummer beatles?
bot> _ _ _ _ _ _ _ _ _ _
bot> r _ _ g o s _ _ r
bot> r _ n g o s t r r
bot> oh man, nobody got answer! was: ringo starr
bot> president of united states?
bot> _ _ _ _ _ _ _ _ _ _ _ **
bot> _ _ _ _ _ _ _ _ _ _ _ ** these 2 messages sent @ same time
example 2: satisfies if (there no hint)
and corresponding else
statement
bot> drummer beatles?
bot> _ _ _ _ _ _ _ _ _ _
bot> r _ _ g o s _ _ r
bot> r _ n g o s t r r
bot> oh man, nobody got answer! was: ringo starr
bot> president of united states?
bot> _ _ _ _ _ _ _ _ _ _ _ **
bot> _ _ c _ o b _ _ _ ** these 2 messages sent @ same time
i've done troubleshooting follow bot's path. givehint()
being called once.
function givehint() { if (triviaactive) { //if trivia enabled if (!ishint) { //if there's no hint ishint = true; triviahint = triviaanswer.replace(/ /g, ' '); triviahint = triviahint.replace(/[a-za-z0-9]/g, '_ '); modanswer = triviaanswer.replace(/[^a-za-z0-9]/g, ''); answerarray = modanswer.split(''); totalletters = math.round(answerarray.length / 2); bot.say(to, triviahint); givehintinterval = setinterval(givehint, 11000); } else { //there hint (var = 0; < totalletters - 1; i++) { giveletter = math.floor(math.random() * answerarray.length); characterreplace = answerarray[giveletter]; answerarray.splice(giveletter, 1); triviahint = replacenthmatch(triviahint, "_", giveletter + 1, characterreplace); console.log("replacing " + giveletter + " underscore " + characterreplace); if (answerarray.length == 0) { = totalletters; //escape loop clearinterval(givehintinterval); if (!triviacont) { //if trivia 'single question' mode ishint = false; triviaactive = false; bot.say(to, "oh man, nobody got answer! was: " + color(triviafull, 6)); triviaanswer = ""; } else { //if trivia in 'continuous mode' ishint = false; triviaactive = false; bot.say(to, "oh man, nobody got answer! was: " + color(triviafull, 6)); triviaanswer = ""; dotrivia(); //ask new question } } } bot.say(to, triviahint); } } }
dotrivia() - *this function finds random song database of songs , asks question it
function dotrivia() { if (!triviarestricted) { //new question, restart hint timer if (givehintinterval) { clearinterval(givehintinterval); } (var i=0;i!=1;i) { getrandomline('shuffle.txt'); var shufflearray = shuffled.split(","); var submitter = shufflearray[0]; var shufartist = shufflearray[1]; var shuftitle = shufflearray[2]; var shuflink = shufflearray[3]; if (shufartist && shuftitle) { triviaactive = true; //trivia active i=1; // escape loop var max = 2; var min = 1; var trivrandom = math.floor(math.random()*(max-min+1)+min); ishint = false; if (trivrandom == 1) { triviaquestion = "who artist of "+color(shuftitle,12)+"?"; bot.say(to,triviaquestion); triviaanswer = shufartist; triviafull = shufartist+" - "+shuftitle; givehint(); } else { triviaquestion = "can name song "+color(shufartist,12)+"?"; triviafull = shufartist+" - "+shuftitle; triviaanswer = shuftitle; bot.say(to, triviaquestion); givehint(); } } } } else {bot.notice(from, "trivia disabled.");} }
i have found answer question. in case curious, issue recursive function. givehint calling dotrivia calls givehint. thanks.
Comments
Post a Comment