-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeta.js
More file actions
277 lines (228 loc) · 8.48 KB
/
meta.js
File metadata and controls
277 lines (228 loc) · 8.48 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
const fs = require('fs');
const { EmbedBuilder } = require('discord.js');
const { characterEmoji, matriceEmoji, skillEmoji } = require('./storage');
const stringSimilarity = require('string-similarity');
const { calculateDPS } = require('./dpscalc');
const flameCompsWhale = {
annaLiuZekeFlame: {
characters: ["annagas6", "liu6", "zeke6"],
sets: ["anna4pc3", "liu4pc3", "zeke4pc3"],
trait: ["liu"],
skills: [],
},
annaLanZekeFlame: {
characters: ["annagas6", "lan6", "zeke6"],
sets: ["anna4pc3", "liu4pc3", "zeke4pc3"],
trait: ["liu"],
skills: [],
},
annaLiuLanFlame: {
characters: ["annagas6", "lan6", "liu6"],
sets: ["anna4pc3", "liu4pc3", "lan4pc3"],
trait: ["liu"],
skills: [],
},
fionaLiuZekeFlame: {
characters: ["zeke6", "liu6", "fiona6"],
sets: ["zeke4pc3", "liu4pc3", "fiona4pc3"],
trait: ["zeke"],
skills: ["wellspring", "maelstrom"],
},
fionaLiuLanFlame: {
characters: ["liu6", "lan6", "fiona6"],
sets: ["liu4pc3", "lan4pc3", "fiona4pc3"],
trait: ["liu"],
skills: ["wellspring", "maelstrom"],
},
};
const frostCompsWhale = {
yulanFionaAlyssFrost: {
characters: ["yulanmartial6", "fiona6", "alyss6"],
sets: ["lyrasamir2pc3", "fiona4pc3", "yulan4pc3"],
trait: ["yulan"],
skills: ["wellspring", "maelstrom"],
},
yulanFionaIcarusFrost: {
characters: ["yulansweeping6", "fiona6", "icarus6"],
sets: ["fiona4pc3", "yulan4pc3", "icarus4pc3"],
trait: ["yulan"],
skills: ["hydro", "torrential"],
},
yulanFionaZekeFrost: {
characters: ["yulanmartial6", "fiona6", "zeke6"],
sets: ["lyrasamir2pc3", "fiona4pc3", "yulan4pc3"],
trait: ["yulan"],
skills: ["wellspring", "maelstrom"],
},
tripleFrost: {
characters: ["yulansweeping6", "icarus6", "alyss6"],
sets: ["yulan4pc3", "icarus4pc3", "alyss4pc3"],
trait: ["yulan"],
skills: [],
},
}
function getCharacterEmoji(characterInput) {
const characterNames = Object.keys(characterEmoji);
const matches = stringSimilarity.findBestMatch(characterInput, characterNames);
// Get the best match
const bestMatch = matches.bestMatch;
// Lower the similarity threshold (e.g., 0.6) to make matching less strict
if (bestMatch.rating >= 0.3) {
const characterName = bestMatch.target;
return characterEmoji[characterName];
} else {
// If no suitable match is found, return 'Invalid Character'
return 'Invalid Character';
}
}
function getMatrixEmoji(matrixInput) {
console.log(matrixInput)
const matrixNames = Object.keys(matriceEmoji);
const matches = stringSimilarity.findBestMatch(matrixInput, matrixNames);
// Get the best match
const bestMatch = matches.bestMatch;
// Lower the similarity threshold (e.g., 0.6) to make matching less strict
if (bestMatch.rating >= 0.3) {
const matrixName = bestMatch.target;
return matriceEmoji[matrixName];
} else {
// If no suitable match is found, return 'Invalid Matrix'
return 'Invalid Matrix';
}
}
// Function to get the emoji for a skill name
function getSkillEmoji(skillInput) {
const skillNames = Object.keys(skillEmoji);
const matches = stringSimilarity.findBestMatch(skillInput, skillNames);
// Get the best match
const bestMatch = matches.bestMatch;
// Lower the similarity threshold (e.g., 0.3) to make matching less strict
if (bestMatch.rating >= 0.3) {
const skillName = bestMatch.target;
return skillEmoji[skillName];
} else {
// If no suitable match is found, return 'Invalid Skill'
return 'Invalid Skill';
}
}
function formatCharacterNamesWithEmoji(compsData) {
const formattedData = {};
for (const key in compsData) {
if (compsData.hasOwnProperty(key)) {
const characters = compsData[key].characters;
// Iterate over characters and format their names with emojis
const formattedCharacters = characters.map(character => {
const parts = character.split(/[0-9]/); // Split by digits
const name = parts[0].trim();
const stars = character.match(/[0-9]+/) || []; // Extract stars
const emoji = getCharacterEmoji(name); // Get character emoji
return `${emoji} ${name} ${stars[0] || ''}☆`; // Format with emoji
});
formattedData[key] = formattedCharacters;
}
}
return formattedData;
}
function formatSetNamesWithEmoji(compsData) {
const formattedData = {};
for (const key in compsData) {
if (compsData.hasOwnProperty(key)) {
const sets = compsData[key].sets;
// Iterate over sets and format their names with emojis
const formattedSets = sets.map(set => {
const emoji = getMatrixEmoji(set); // Get set emoji
return `${emoji} ${set}`; // Format with emoji
});
formattedData[key] = formattedSets;
}
}
return formattedData;
}
function calculateDPSForCompositions(compositions) {
const dpsValues = {};
for (const compositionName in compositions) {
if (compositions.hasOwnProperty(compositionName)) {
const input = compositions[compositionName];
const { characters, sets, trait, skills } = input; // Include sets in destructuring
// Spread the values as separate arguments to calculateDPS
const dps = calculateDPS(...characters, ...sets, ...trait, ...skills); // Include sets in arguments
dpsValues[compositionName] = dps;
}
}
return dpsValues;
}
function getComps(element, investment) {
// Replace 'element' and 'investment' with the actual values passed from the command
if (element === 'flame' && investment === 'whale') {
return flameCompsWhale;
} else if (element === 'frost' && investment === 'whale') {
return frostCompsWhale;
}
// Add more conditions for other elements and investments as needed
// Default to an empty object if no matching conditions are found
return {};
}
function parseDmgPercentData(dpsValues) {
const parsedData = {};
for (const key in dpsValues) {
if (dpsValues.hasOwnProperty(key)) {
parsedData[key] = dpsValues[key].dmgPercentPerMin;
}
}
return parsedData;
}
// Command handler
async function handleMetaCommand(element, investment, interaction) {
const comps = getComps(element, investment);
const dpsValues = calculateDPSForCompositions(comps);
const parsedData = parseDmgPercentData(dpsValues);
const formattedCharacterData = formatCharacterNamesWithEmoji(comps);
const formattedSetData = formatSetNamesWithEmoji(comps);
let investmentEmoji = `:whale:`;
if (investment == "whale") {
investmentEmoji = `:whale:`;
}
const embed = new EmbedBuilder()
.setTitle(`Meta Comps for ${element} ${investmentEmoji}`)
.setColor('#FF5733');
const keys = Object.keys(parsedData);
const numColumns = 3; // Change this number to the desired number of columns
const numRows = Math.ceil(keys.length / numColumns);
const fields = [];
for (let row = 0; row < numRows; row++) {
for (let column = 0; column < numColumns; column++) {
const index = row + column * numRows;
if (index < keys.length) {
const key = keys[index];
const value = parsedData[key];
const formattedChars = formattedCharacterData[key];
const formattedSets = formattedSetData[key];
if (Array.isArray(formattedChars) && formattedChars.length > 0) {
fields.push({ name: 'Characters', value: formattedChars.join('\n'), inline: true });
} else {
console.error(`Invalid or empty formatted characters for key "${key}"`);
}
if (Array.isArray(formattedSets) && formattedSets.length > 0) {
fields.push({ name: 'Sets', value: formattedSets.join('\n'), inline: true });
} else {
console.error(`Invalid or empty formatted sets for key "${key}"`);
}
// Add Trait and Skills inline with Dmg%/Min
if (typeof value === 'string' && value.trim() !== '') {
// Use a non-empty string as a placeholder for the field name
const fieldName = 'Final';
const trait = comps[key].trait.join(', ');
const skills = comps[key].skills.join(', ');
const traitEmoji = getCharacterEmoji(trait);
const skillsEmoji = getSkillEmoji(skills);
fields.push({ name: fieldName, value: `**Trait:** ${traitEmoji} ${trait} \n**Skills:** ${skillsEmoji} ${skills} \n \`${value} Dmg%/Min\`\n`, inline: true });
} else {
console.error(`Invalid or empty value for field "${key}"`);
}
}
}
}
embed.addFields(fields);
await interaction.reply({ embeds: [embed] });
}
module.exports = { handleMetaCommand };