Ender Yee'kkay
Ender Yee'kkay
DIAdiscord.js - Imagine an app
Created by Ender Yee'kkay on 10/8/2023 in #djs-questions
Very slow working code
I've got a problem:
const coordinate_types = require('../constants.json').coordinate_types;
module.exports = {
name: 'get_standard_coordinates_arrow_left',

async execute (client, interaction) {
try {
interaction.deferUpdate()
const pageSize = 10
const footer_text = interaction.message.embeds[0].footer.text
const sliced = footer_text.slice(9, footer_text.length)
console.log(sliced)
const lastPageNum = sliced.split(' из ')[0]
const lastPageMax = sliced.split(' из ')[1]
const query_res = await client.pg.query(`
SELECT * FROM standard_coordinates
WHERE ${client.calcClearanceLevel(interaction.member)} >= clearance
ORDER BY object
`)
const pageMax = Math.ceil(query_res.rowCount / 10) + Number(query_res.rowCount % 10 != 0)
const pageNum = (lastPageNum > 1) ? lastPageNum - 1 : pageMax
const result = query_res.rows.slice((pageNum - 1) * 10, pageNum * 10)
const newEmbed = EmbedBuilder.from(interaction.message.embeds[0])
.setFooter({text: `Страница ${pageNum} из ${pageMax}`})
.setFields([])
console.log(newEmbed);
for (var i = 0; i < result.length; i++) {
const emoji = coordinate_types.find(coordinateType => coordinateType.value == result[i].object).emoji
const object = coordinate_types.find(coordinateType => coordinateType.value == result[i].object).name
const id = result[i].id
newEmbed.data.fields.push({
name: `<:${result[i].object}:${emoji}> - ${object} #${result[i].id} (${result[i].name})`,
value: `\`\`\`${result[i].description}\nGPS:${result[i].name}:${result[i].vector.x}:${result[i].vector.y}:${result[i].vector.z}:#${result[i].rgb}:\`\`\``
})
}
await interaction.message.edit({
embeds: [
newEmbed
]
})
} catch (error) {
console.error(error)

}
}
}
const coordinate_types = require('../constants.json').coordinate_types;
module.exports = {
name: 'get_standard_coordinates_arrow_left',

async execute (client, interaction) {
try {
interaction.deferUpdate()
const pageSize = 10
const footer_text = interaction.message.embeds[0].footer.text
const sliced = footer_text.slice(9, footer_text.length)
console.log(sliced)
const lastPageNum = sliced.split(' из ')[0]
const lastPageMax = sliced.split(' из ')[1]
const query_res = await client.pg.query(`
SELECT * FROM standard_coordinates
WHERE ${client.calcClearanceLevel(interaction.member)} >= clearance
ORDER BY object
`)
const pageMax = Math.ceil(query_res.rowCount / 10) + Number(query_res.rowCount % 10 != 0)
const pageNum = (lastPageNum > 1) ? lastPageNum - 1 : pageMax
const result = query_res.rows.slice((pageNum - 1) * 10, pageNum * 10)
const newEmbed = EmbedBuilder.from(interaction.message.embeds[0])
.setFooter({text: `Страница ${pageNum} из ${pageMax}`})
.setFields([])
console.log(newEmbed);
for (var i = 0; i < result.length; i++) {
const emoji = coordinate_types.find(coordinateType => coordinateType.value == result[i].object).emoji
const object = coordinate_types.find(coordinateType => coordinateType.value == result[i].object).name
const id = result[i].id
newEmbed.data.fields.push({
name: `<:${result[i].object}:${emoji}> - ${object} #${result[i].id} (${result[i].name})`,
value: `\`\`\`${result[i].description}\nGPS:${result[i].name}:${result[i].vector.x}:${result[i].vector.y}:${result[i].vector.z}:#${result[i].rgb}:\`\`\``
})
}
await interaction.message.edit({
embeds: [
newEmbed
]
})
} catch (error) {
console.error(error)

}
}
}
30 replies