From 6bb52088d47a714ba648a1b2fcf14a03638f61fa Mon Sep 17 00:00:00 2001 From: deuce <> Date: Fri, 27 Sep 2013 19:36:08 +0000 Subject: [PATCH] Add some sane loop limits. --- exec/ircbots/dis/dis.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/exec/ircbots/dis/dis.js b/exec/ircbots/dis/dis.js index c2e539a4dd..65082f05ef 100644 --- a/exec/ircbots/dis/dis.js +++ b/exec/ircbots/dis/dis.js @@ -23,6 +23,7 @@ Bot_Commands["DIS"].command = function (target, onick, ouh, srv, lbl, cmd) { var new_matcher; var i; + var deads = 0; new_matcher = "[\\.\\?\\!]\\s+("; for(i=0;i<arg;i++) { if(i) @@ -31,11 +32,14 @@ Bot_Commands["DIS"].command = function (target, onick, ouh, srv, lbl, cmd) { } new_matcher += ')'; + if(in_txt.substr(pos).search(new RegExp(new_matcher, 'i'))==-1) + return 'No sentences found in any of ths posts.'; + // In use in the loop. var re,orig=[],matched,remainder,last_matched='',iteration=0,pos=0; last_match_point = -1; - while(1) { + while(out.length < 510 && deads < iteration_limit) { iteration++; do { pos = random(in_txt.length); @@ -99,6 +103,7 @@ Bot_Commands["DIS"].command = function (target, onick, ouh, srv, lbl, cmd) { log(LOG_DEBUG, "Can't get an initial "+(arg)+"-token match"); break; } + deads++; } } -- GitLab