This repository has been archived by the owner on Jun 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
82 lines (77 loc) · 2.22 KB
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
exports.checkDate = function(args, isDayIncluded) {
var yearString = args[0].split('/')[0];
var monthString = args[0].split('/')[1];
//checking to make sure they are numbers
var yearInt = parseInt(yearString);
var monthInt = parseInt(monthString);
var errorLog = '';
if (isDayIncluded) {
var dayString = args[0].split('/')[2];
var dayInt = parseInt(dayString);
if (
isNaN(yearInt) ||
isNaN(monthInt) ||
isNaN(dayInt) ||
args[0].split('/').length > 3 ||
yearString.length != 4 ||
monthString.length < 1 ||
monthString.length > 2 ||
dayString.length < 1 ||
dayString.length > 2
) {
errorLog =
'The date you entered is not formated correctly \n' +
'e.g. !commandname YYYY/MM/DD';
return errorLog;
}
} else {
if (
isNaN(yearInt) ||
isNaN(monthInt) ||
args[0].split('/').length > 2 ||
yearString.length != 4 ||
monthString.length < 1 ||
monthString.length > 2
) {
errorLog =
'The date you entered is not formated correctly \n' +
'e.g. !commandname YYYY/MM';
return errorLog;
}
}
return errorLog;
};
exports.checkArguments = function(args, numberOfArguments) {
var errorLog = '';
for (let i = 0; i < numberOfArguments; i++) {
if (args[i] == undefined) {
errorLog =
'The command you entered is missing some information \n' +
'e.g. !commandname YYYY/MM/DD';
if (numberOfArguments > 1) {
errorLog += ' username';
}
return errorLog;
}
}
//why even bother checking if they have more arguments if I won't use them
// //check if too many arguments
// if (args.length > numberOfArguments) {
// errorLog =
// `You have too many arguments. There should only be ${numberOfArguments}.\n` +
// 'e.g. !commandname YYYY/MM/DD';
// if (numberOfArguments > 1) {
// errorLog += ' username';
// }
// return errorLog;
// }
return errorLog;
};
exports.drawWinner = myArray => {
var randomNum = Math.floor(Math.random() * myArray.length);
console.log(
new Date() +
`The winning entry number is ${randomNum} - user ${myArray[randomNum]}`
);
return myArray[randomNum];
};