-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodules.js
More file actions
58 lines (51 loc) · 1.84 KB
/
modules.js
File metadata and controls
58 lines (51 loc) · 1.84 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
const d = require('discord.js')
/**
* Compares two strings.
* @param {string} str1
* @param {string} str2
* @returns {number} a number between 0 and 1 representing the percentage of similarity between the two strings
*/
function CompareStrings(str1, str2) {
for (var result = 0, i = str1.length; i--;) {
if (typeof str2[i] == 'undefined' || str1[i] == str2[i]);
else if (str1[i].toLowerCase() == str2[i].toLowerCase())
result++;
else
result += 4;
}
return 1 - (result + 4 * Math.abs(str1.length - str2.length)) / (2 * (str1.length + str2.length));
}
/**
* Sends a message with the verb to translate
* @param {Discord.Guild} guild
* @param {Discord.TextChannel} channel - the channel where the message will be sent
* @param {Object} verbList - the list of verbs
* @returns {List} [the message sent, the id of the language of translation]
*/
async function SendVerbMessage(guild, channel, verbList, langTrad) {
// Choisi un nombre aléatoire entre 0 et la longueur de la liste
const randomVerb = Math.floor(Math.random() * verbList.verbs.length)
// Crée le bouton
const infButton = new d.ActionRowBuilder()
.addComponents(
new d.ButtonBuilder()
.setCustomId('infButton')
.setLabel(`${language(guild, "GIVE_ANSW")}`)
.setStyle(d.ButtonStyle.Success)
)
// Get the traduction language
let lan = 0
if(langTrad === "french") lan = 3
else if(langTrad === "english" || "dutch") lan = 0
// Envoie le message
const message = await channel.send({
content: `${language(guild, "INFINITIVE").replace("{0}", langTrad)
.replace("{1}", verbList.verbs[randomVerb][lan])}`,
components: [infButton]
})
return [message, lan]
}
module.exports = {
CompareStrings,
SendVerbMessage
}