//index.js
const { Telegraf, Markup, Scenes, session } = require('telegraf');
const firstScene = require('./controllers/first');
const secondScene = require('./controllers/second');
const bot = new Telegraf(token, {});
const stage = new Scenes.Stage([
firstScene,
secondScene
]);
bot.use(stage.middleware());
// controllers/first/index.js
const { Scenes } = require('telegraf');
const first = new Scenes.BaseScene('first');
first.enter(async ctx => {});
module.exports = first;
const arr = [{ name: "Creeper's Cruel Painsaw", price: '2.53', rarity: 'Common' },
{ name: "Creeper's Cruel Painsaw", price: '2.50', rarity: 'Common' },
{ name: 'Cuffs of Oak and Yew', price: '3.94', rarity: 'Rare' },
{ name: 'Cuffs of Oak and Yew', price: '4.99', rarity: 'Rare' },
{ name: 'Curled Root-Staff', price: '2.91', rarity: 'Common' },
{ name: 'Curled Root-Staff', price: '3.33', rarity: 'Common' }];
const sorted = [...arr].sort((a, b) => a.price - b.price).slice(1);
console.log(sorted); /* [
{ name: "Creeper's Cruel Painsaw", price: "2.53", rarity: "Common" },
{ name: "Curled Root-Staff", price: "2.91", rarity: "Common" },
{ name: "Curled Root-Staff", price: "3.33", rarity: "Common" },
{ name: "Cuffs of Oak and Yew", price: "3.94", rarity: "Rare" },
{ name: "Cuffs of Oak and Yew", price: "4.99", rarity: "Rare" }
] */
document.addEventListener('DOMContentLoaded', () => {
const buttonOpen = document.querySelector('.ob-widget-btn');
const buttonClose = document.querySelector('.ob-widget-container__header__close__cross');
buttonOpen.addEventListener('click', () => {
document.body.classList.add('darken');
});
buttonClose.addEventListener('click', () => {
document.body.classList.remove('darken');
});
});
const array = ['a', 'b', 'c', 'd', 'e', '1', '2', 'a', 'b', 'c', 'd', 'f', 'g', 'h', 'j'];
const getRandowPairs = arr => {
const sorted = [...new Set(arr)].sort((a, b) => Math.round(Math.random()) || -1);
let res = [];
for (let i = 0; i + 1 < sorted.length; i += 2){
res.push([sorted[i], sorted[i + 1]]);
}
return res;
};
const getRandomArr = arr => {
const index = Math.floor(Math.random() * arr.length);
const item = arr[index];
arr.splice(index, 1);
arr = arr.flatMap(e => e);
const set = new Set();
while (set.size < 5){
let i = Math.floor(Math.random() * arr.length);
if (!item.includes(arr[i])){
set.add(arr[i]);
}
}
return [item[1], ...set];
};
console.log(getRandomArr(getRandowPairs(array))); // [ "c", "e", "h", "a", "1", "2" ]
console.log(getRandomArr(getRandowPairs(array))); // [ "1", "a", "d", "f", "h", "c" ]
console.log(getRandomArr(getRandowPairs(array))); // [ "f", "b", "j", "g", "a", "2" ]
const array = ['a', 'b', 'c', 'd', 'e', '1', '2', 'a', 'b', 'c', 'd', 'f', 'g', 'h', 'j'];
const getRandowPair = arr => {
const sorted = [...new Set(arr)].sort((a, b) => Math.round(Math.random()) || -1);
let res = [];
for (let i = 0; i + 1 < sorted.length; i += 2){
res.push([sorted[i], sorted[i + 1]]);
}
return res[Math.floor(Math.random() * res.length)];
};
const item = getRandowPair(array);
const set = new Set();
while (set.size < 5){
let i = Math.floor(Math.random() * array.length);
if (!item.includes(array[i])){
set.add(array[i]);
}
}
const result = [item[1], ...set];
console.log(result); // [ "e", "h", "c", "2", "j", "b" ]