ferd-countdown
Advanced tools
Comparing version 0.0.1 to 0.0.2
module.exports = function(ferd) { | ||
var timeString; | ||
var timerInterval; | ||
/** | ||
@@ -17,14 +18,67 @@ * Listens for `countdown` or `countdown help` matches, and sends back some | ||
+ '> `countdown Ys`, where `Y` is a number, and `s` represents seconds\n' | ||
+ '> `countdown Xm Ys`, where `X` and `Y` are numbers, and `m` and `s` represent minutes and seconds\n'; | ||
+ '> `countdown Xm Ys`, where `X` and `Y` are numbers, and `m` and `s` represent minutes and seconds\n\n' | ||
+ '> `countdown stop` stops the countdown and prints out how much time was remaining'; | ||
response.send(helpString); | ||
}); | ||
var re = /countdown\s(\d+)\s(seconds*)|countdown\s(\d+)\sminutes*\s(\d+)\sseconds*|countdown\s(\d+)\sminutes*\sand\s(\d+)\sseconds*|countdown\s(\d+)\s(minutes*)|countdown\s(\d+):(\d+)|countdown\s(\d+)m\s(\d+)s|countdown\s(\d+)([ms])/i; | ||
ferd.listen(/countdown\s(\d+)\s(seconds)/i, function(response) { | ||
// re1 = /countdown\s(\d+)\s(seconds*)/i; | ||
// re2 = /countdown\s(\d+)\sminutes*\s(\d+)\sseconds*/i; | ||
// re3 = /countdown\s(\d+)\sminutes*\sand\s(\d+)\sseconds*/i; | ||
// re4 = /countdown\s(\d+)\s(minutes*)/i; | ||
// re5 = /countdown\s(\d+):(\d+)/i; | ||
// re6 = /countdown\s(\d+)m\s(\d+)s/i; | ||
// re7 = /countdown\s(\d+)([ms])/i; | ||
ferd.listen(re, function(response) { | ||
var sender = response.getMessageSender(); | ||
var matches = response.match; | ||
var timeRemaining = parseInt(matches[1]); | ||
var timeString = secondsToString(timeRemaining); | ||
var timerInterval; | ||
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 | ||
minutes = parseInt(minutes); | ||
seconds = parseInt(seconds); | ||
if(!minutes) {minutes = 0;} | ||
if(!seconds) {seconds = 0;} | ||
var totalSeconds = (minutes*60) + seconds; | ||
var timeRemaining = totalSeconds; | ||
var m; | ||
timeString = secondsToString(timeRemaining); | ||
@@ -72,2 +126,7 @@ /** | ||
ferd.listen(/countdown stop/i, function(response) { | ||
clearInterval(timerInterval); | ||
response.send('Timer stopped at ' + timeString); | ||
}); | ||
}; | ||
@@ -74,0 +133,0 @@ |
{ | ||
"name": "ferd-countdown", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"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
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
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
5325
129
1