ferd-countdown
Advanced tools
Comparing version 0.0.2 to 0.0.3
161
countdown.js
module.exports = function(ferd) { | ||
var timeString; | ||
var timerInterval; | ||
var timerInterval = setInterval(function() {},1); | ||
clearInterval(timerInterval); | ||
/** | ||
@@ -35,88 +37,91 @@ * Listens for `countdown` or `countdown help` matches, and sends back some | ||
ferd.listen(re, function(response) { | ||
var sender = response.getMessageSender(); | ||
var matches = response.match; | ||
if(timerInterval._onTimeout === null) { | ||
var sender = response.getMessageSender(); | ||
var matches = response.match; | ||
var minutes; | ||
var seconds; | ||
var minutes; | ||
var seconds; | ||
// Determine what format the user entered and calculate the amount of seconds | ||
if(matches[1] && matches[2]) { | ||
minutes = 0; | ||
seconds = matches[1]; | ||
}// 5 seconds | ||
else if(matches[3] && matches[4]) { | ||
minutes = matches[3]; | ||
seconds = matches[4]; | ||
}// 5 minutes 5 seconds | ||
else if(matches[5] && matches[6]) { | ||
minutes = matches[5]; | ||
seconds = matches[6]; | ||
}// 5 minutes and 5 seconds | ||
else if(matches[7] && matches[8]) { | ||
minutes = matches[7]; | ||
seconds = 0; | ||
}// 5 minutes | ||
else if(matches[9] && matches[10]) { | ||
minutes = matches[9]; | ||
seconds = matches[10]; | ||
}// 5:05 | ||
else if(matches[11] && matches[12]) { | ||
minutes = matches[11]; | ||
seconds = matches[12]; | ||
}// 5m 5s | ||
else if(matches[13] && matches[14]) { | ||
if(matches[14] === 'm') { | ||
minutes = matches[13]; | ||
} else {seconds = matches[13];} | ||
}// 5m/s | ||
// Determine what format the user entered and calculate the amount of seconds | ||
if(matches[1] && matches[2]) { | ||
minutes = 0; | ||
seconds = matches[1]; | ||
}// 5 seconds | ||
else if(matches[3] && matches[4]) { | ||
minutes = matches[3]; | ||
seconds = matches[4]; | ||
}// 5 minutes 5 seconds | ||
else if(matches[5] && matches[6]) { | ||
minutes = matches[5]; | ||
seconds = matches[6]; | ||
}// 5 minutes and 5 seconds | ||
else if(matches[7] && matches[8]) { | ||
minutes = matches[7]; | ||
seconds = 0; | ||
}// 5 minutes | ||
else if(matches[9] && matches[10]) { | ||
minutes = matches[9]; | ||
seconds = matches[10]; | ||
}// 5:05 | ||
else if(matches[11] && matches[12]) { | ||
minutes = matches[11]; | ||
seconds = matches[12]; | ||
}// 5m 5s | ||
else if(matches[13] && matches[14]) { | ||
if(matches[14] === 'm') { | ||
minutes = matches[13]; | ||
} else {seconds = matches[13];} | ||
}// 5m/s | ||
minutes = parseInt(minutes); | ||
seconds = parseInt(seconds); | ||
minutes = parseInt(minutes); | ||
seconds = parseInt(seconds); | ||
if(!minutes) {minutes = 0;} | ||
if(!seconds) {seconds = 0;} | ||
if(!minutes) {minutes = 0;} | ||
if(!seconds) {seconds = 0;} | ||
var totalSeconds = (minutes*60) + seconds; | ||
var timeRemaining = totalSeconds; | ||
var totalSeconds = (minutes*60) + seconds; | ||
var timeRemaining = totalSeconds; | ||
var m; | ||
timeString = secondsToString(timeRemaining); | ||
var m; | ||
timeString = secondsToString(timeRemaining); | ||
/** | ||
* beginCountdown | ||
* | ||
* @description [description] | ||
* @return {[type]} | ||
*/ | ||
var beginCountdown = function() { | ||
timerInterval = setInterval(function() { | ||
if (timeRemaining === 0) { | ||
endCountdown(); | ||
} else { | ||
timeRemaining = timeRemaining - 1; | ||
timeString = secondsToString(timeRemaining); | ||
response.updateMessage(m, 'Time remaining: ' + timeString); | ||
} | ||
}, 1000); | ||
}; | ||
/** | ||
* beginCountdown | ||
* | ||
* @description [description] | ||
* @return {[type]} | ||
*/ | ||
var beginCountdown = function() { | ||
timerInterval = setInterval(function() { | ||
if (timeRemaining === 0) { | ||
endCountdown(); | ||
} else { | ||
timeRemaining = timeRemaining - 1; | ||
timeString = secondsToString(timeRemaining); | ||
response.updateMessage(m, 'Time remaining: ' + timeString); | ||
} | ||
}, 1000); | ||
}; | ||
/** | ||
* endCountdown | ||
* | ||
* @description [description] | ||
* @return {[type]} | ||
*/ | ||
var endCountdown = function() { | ||
clearInterval(timerInterval); | ||
m.updateMessage('Time up!'); | ||
}; | ||
/** | ||
* endCountdown | ||
* | ||
* @description [description] | ||
* @return {[type]} | ||
*/ | ||
var endCountdown = function() { | ||
clearInterval(timerInterval); | ||
m.updateMessage('Time up!'); | ||
response.send('Time up!'); | ||
}; | ||
/** | ||
* Run the style | ||
*/ | ||
if (timeRemaining <= 0) { | ||
m = response.send('Sorry ' + sender.name + ', but you can only use numbers greater than 0 for the countdown! Type `countdown help` for valid countdown formats.'); | ||
} else { | ||
m = response.send('Time remaining: ' + timeString); | ||
beginCountdown(); | ||
/** | ||
* Run the style | ||
*/ | ||
if (timeRemaining <= 0) { | ||
m = response.send('Sorry ' + sender.name + ', but you can only use numbers greater than 0 for the countdown! Type `countdown help` for valid countdown formats.'); | ||
} else { | ||
m = response.send('Time remaining: ' + timeString); | ||
beginCountdown(); | ||
} | ||
} | ||
@@ -123,0 +128,0 @@ |
{ | ||
"name": "ferd-countdown", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "A countdown module for Ferd the Slackbot", | ||
@@ -5,0 +5,0 @@ "main": "countdown.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
5632
133
0