Add warn and mute commands. General code clean-up.
This commit is contained in:
parent
28bb8165bc
commit
15b7da82e8
5 changed files with 264 additions and 67 deletions
44
src/utils.ts
Normal file
44
src/utils.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import * as moment from "moment-timezone";
|
||||
import { ModActionType } from "./data/ModActionType";
|
||||
|
||||
/**
|
||||
* Turns a "delay string" such as "1h30m" to milliseconds
|
||||
* @param {String} str
|
||||
* @returns {Number}
|
||||
*/
|
||||
export function convertDelayStringToMS(str) {
|
||||
const regex = /^([0-9]+)\s*([dhms])?[a-z]*\s*/;
|
||||
let match;
|
||||
let ms = 0;
|
||||
|
||||
str = str.trim();
|
||||
|
||||
// tslint:disable-next-line
|
||||
while (str !== "" && (match = str.match(regex)) !== null) {
|
||||
if (match[2] === "d") ms += match[1] * 1000 * 60 * 60 * 24;
|
||||
else if (match[2] === "h") ms += match[1] * 1000 * 60 * 60;
|
||||
else if (match[2] === "s") ms += match[1] * 1000;
|
||||
else if (match[2] === "m" || !match[2]) ms += match[1] * 1000 * 60;
|
||||
|
||||
str = str.slice(match[0].length);
|
||||
}
|
||||
|
||||
// Invalid delay string
|
||||
if (str !== "") {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ms;
|
||||
}
|
||||
|
||||
export function successMessage(str) {
|
||||
return `👌 ${str}`;
|
||||
}
|
||||
|
||||
export function errorMessage(str) {
|
||||
return `❌ ${str}`;
|
||||
}
|
||||
|
||||
export function uclower(str) {
|
||||
return str[0].toLowerCase() + str.slice(1);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue