-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.js
107 lines (68 loc) · 2.57 KB
/
Utils.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
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
class Utils {
generateRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
generateRandomNumbers(numPlayers, min, max) {
const randomNumbers = [];
for (let i = 0; i < numPlayers; i++) {
randomNumbers.push(this.generateRandomNumber(min, max));
}
return randomNumbers;
}
formatGameArea(gameArea) {
return gameArea.map(row => row.join(' ')).join('\n');
}
getPlayersTemplate() {
const playersWithEmoji = new Memory().getPlayers();
var playersTemplate = '';
playersWithEmoji.forEach(element => {
const elem = element.split("##")
const player = elem[0]
const emoji = elem[1]
playersTemplate += `👤 ${player} : ${emoji}\n`
});
return playersTemplate
}
generateValuesTemplate() {
const arrayOfValues = this.generateRandomNumbers(5, 1, 15);
var valueTemplate = '';
const markup = {
inline_keyboard: [[]],
};
const value = arrayOfValues[0];
arrayOfValues.forEach((elem, index) => {
const emojis = ["🌟", "➡️", "⬅️", "⬆️", "⬇️"]
valueTemplate += ` ${emojis[index]} : ${elem} ${(!index) ? '*' : ''}\n`
markup.inline_keyboard[0].push({
text: value * elem,
callback_data: emojis[index],
})
})
CONFIG.markup = markup;
return valueTemplate;
}
shuffleInlineKeyboard(inlineKeyboard) {
// Assuming inlineKeyboard is an array with one row
if (Array.isArray(inlineKeyboard) && inlineKeyboard.length === 1 && Array.isArray(inlineKeyboard[0])) {
// Shuffle the inner array (inline keyboard row)
for (let i = inlineKeyboard[0].length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[inlineKeyboard[0][i], inlineKeyboard[0][j]] = [inlineKeyboard[0][j], inlineKeyboard[0][i]];
}
}
return inlineKeyboard;
}
findDeletedEmoji(originalString = '👋📺📷🚀', modifiedString = '👋📷🚀') {
// Extract emojis from the original and modified strings
const originalEmojis = originalString.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || [];
const modifiedEmojis = modifiedString.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || [];
// Find the deleted emoji
const deletedEmojis = originalEmojis.filter(emoji => !modifiedEmojis.includes(emoji));
return deletedEmojis;
}
searchCharacterInArray(array, character) {
// Filter elements that contain the specified character
const matchingElements = array.filter(element => element.includes(character));
return matchingElements;
}
}