-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelpers.js
38 lines (37 loc) · 1.26 KB
/
helpers.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
const config = require('./config.json');
const he = require('he');
module.exports = {
improperUsage(command, message, reason) {
let reply = `${reason}, ${message.author}!`;
if (command.usage) {
reply += `\nThe proper usage would be: \`${config.prefix}${command.name} ${command.usage}\``;
}
return message.channel.send(reply);
},
decode(text) {
let output = he.decode(text).toString();
output = output.split('[i]').join('*');
output = output.split('[/i]').join('*');
output = output.split('[b]').join('**');
output = output.split('[/b]').join('**');
output = output.split('[u]').join('__');
output = output.split('[/u]').join('__');
output = output.split('[spoiler]').join('||');
output = output.split('[/spoiler]').join('||');
output = output.split('[url=').join('');
output = output.split('[/url]').join('');
output = output.split('[hr]').join('');
output = output.split('[*]').join('* ');
return output;
},
// https://stackoverflow.com/questions/175739/built-in-way-in-javascript-to-check-if-a-string-is-a-valid-number
isNumeric(str) {
if (typeof str != 'string') return false;
return !isNaN(str) && !isNaN(parseFloat(str));
},
async sendFiles(channel, files) {
for (const f of files) {
await channel.send({ files: [f] });
}
},
};