/
format.js
68 lines (67 loc) · 2.34 KB
/
format.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
const capitalize = require("./capitalizeFirstChar");
const colors = require("colors");
module.exports = {
stats: (object) => {
const x = Object.entries(object);
let output = "";
for (let i = 0; i < x.length; i++) {
output += `${x[i][0]}: ${JSON.stringify(x[i][1])}\n`;
}
return this.orange(output);
},
skills: (object) => {
const newObject = {
[object.name]: `Current level: ${object.type === "Commune" ? object.level + "/10" : object.level}. Current experience: ${object.exp}/${object.expToLevelUp}`
};
return `\`\`\`json\n${JSON.stringify(newObject)}\`\`\``;
},
dices: (successDiceArray, failedDiceArray) => {
let output = `+ ${successDiceArray}\nNombre de dés réussis: ${successDiceArray.length}\n- ${failedDiceArray}\nNombre de dés ratés: ${failedDiceArray.length}`;
return `\`\`\`diff\n${output}\`\`\``;
},
clfuObject: (object) => {
const { command, summary } = { ...object };
const prettySummary = capitalize(summary); // capitalize first letter
return `\`${command}\`\n*${prettySummary}*`;
},
clfuArray: (array) => {
let output1 = "";
let output2 = "";
let output3 = "";
for (let i = 0; i < array.length; i++) {
const { command, summary } = { ...array[i] };
if (!summary) {
break;
}
const prettySummary = capitalize(summary);
// very dumb code, but three chunks (~6000 characters) should be enough to cover most cases
if (output1.length < 1800) {
output1 += `\`${command}\`\n*${prettySummary}*\n`;
}
else if (output2.length < 1800) {
output2 += `\`${command}\`\n*${prettySummary}*\n`;
}
else if (output3.length < 1800) {
output3 += `\`${command}\`\n*${prettySummary}*\n`;
}
}
return {
output1: output1,
output2: output2,
output3: output3
};
},
orange: (string) => `\`\`\`fix\n${string}\`\`\``,
json: (string) => `\`\`\`json\n${string}\`\`\``,
bash: (string) => `\`\`\`bash\n${string}\`\`\``,
lisp: (string) => `\`\`\`lisp\n${string}\`\`\``,
mainLog: ({
timestamp,
username,
discriminator,
command,
args }) => {
colors.enable();
return `${colors.blue.italic("[" + timestamp + "]")} ${colors.magenta(username + "#" + discriminator)} called command ${colors.green.bold(command)}, args: ${colors.green.italic(args)}`;
},
};