more functions

This commit is contained in:
rhearmas 2019-12-20 20:09:16 -05:00
parent 68847e9c72
commit 4bfe1a97e0
1 changed files with 76 additions and 17 deletions

View File

@ -189,4 +189,63 @@ module.exports = (client) => {
'Hi mom!'
]);
};
const timestampToDate = timestamp => {
if (timestamp === true) {
return new Date();
}
if (typeof timestamp === 'number') {
return new Date(timestamp);
}
return timestamp;
};
const parseArgs = (args, options) => {
if (!options)
return args;
if (typeof options === 'string')
options = [options];
let optionValues = {};
let i;
for (i = 0; i < args.length; i++) {
let arg = args[i];
if (!arg.startsWith('-')) {
break;
}
let label = arg.substr(1);
if (options.indexOf(label + ':') > -1) {
let leftover = args.slice(i + 1).join(' ');
let matches = leftover.match(/^"(.+?)"/);
if (matches) {
optionValues[label] = matches[1];
i += matches[0].split(' ').length;
} else {
i++;
optionValues[label] = args[i];
}
} else if (options.indexOf(label) > -1) {
optionValues[label] = true;
} else {
break;
}
}
return {
options: optionValues,
leftover: args.slice(i)
};
};
const multiSend = (channel, messages, delay) => {
delay = delay || 100;
messages.forEach((m, i) => {
setTimeout(() => {
channel.send(m);
}, delay * i);
});
};
};