Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #32

Merged
merged 4 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 52 additions & 71 deletions Discord/createCartMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ module.exports = async (Discord, client, data) => {
if (serverData.bankData && serverData.bankData.mercadoPagoToken && serverData.bankData.mercadoPagoToken != '') {
paymentFields.unshift(
await new Discord.StringSelectMenuOptionBuilder()
.setLabel('PIX')
.setDescription('Método mais comum de pagamento no Brasil!')
.setValue('PIX')
.setLabel('PIX')
.setDescription('Método mais comum de pagamento no Brasil!')
.setValue('PIX')
)
}
if (serverData.bankData && serverData.bankData.bankID) {
Expand All @@ -27,39 +27,6 @@ module.exports = async (Discord, client, data) => {
.setValue('boleto')
)
}
const row = new Discord.ActionRowBuilder().addComponents(
new Discord.StringSelectMenuBuilder()
.setCustomId('payment')
.setPlaceholder('Selecione o método de pagamento desejado!')
.setMinValues(1)
.setMaxValues(1)
.addOptions(...paymentFields)
)
const row2 = new Discord.ActionRowBuilder()
.addComponents(
new Discord.ButtonBuilder()
.setCustomId(`confirm`)
.setLabel('Confirmar')
.setStyle('3'),
)
.addComponents(

new Discord.ButtonBuilder()
.setCustomId('cancel')
.setLabel('Cancelar')
.setStyle('4')
).addComponents(
new Discord.ButtonBuilder()
.setCustomId(`remove`)
.setLabel('Remover produto')
.setStyle('4')
)
// .addComponents(
// new Discord.ButtonBuilder()
// .setCustomId(`cupombutton`)
// .setLabel('Adicionar Cupom')
// .setStyle('1')
// );

let fields = []
let carrinhos = require('./discordIndex').carrinhos
Expand All @@ -79,67 +46,81 @@ module.exports = async (Discord, client, data) => {
let valorTotalFormatado = valorTotalReal.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' });
produtcs = produtcs.toString()
fields.unshift({ name: '\u200B', value: '\u200B' },)
fields.unshift({ name: `Quantidade de produtos: `, value: "` " + produtcs + " `", inline:true })
fields.unshift({ name: `Valor total: `, value: "` " + valorTotalFormatado + " `", inline:true })
fields.unshift({ name: `Quantidade de produtos: `, value: "` " + produtcs + " `", inline: true })
fields.unshift({ name: `Valor total: `, value: "` " + valorTotalFormatado + " `", inline: true })
} else {
DiscordChannel.delete()
return
}
let contentEmbend = {
embeds: [
new Discord.EmbedBuilder()
.setTitle('Selecione abaixo o metodo de pagamento depois confirme para gerar o seu link de pagamento!')
.setDescription(`Clique em cancelar caso desista de fazer a compra.

Abaixo são os itens do seu carrinho.`)
.setAuthor({ name: "SDKApps", iconURL: `https://res.cloudinary.com/dgcnfudya/image/upload/v1711769157/vyzyvzxajoboweorxh9s.png`})
.setTitle('Siga as etapas abaixo com os botões para concluir sua compra.')
.setDescription(`Abaixo temos o total de itens, o preço total do carrinho e cada produto que você adicionou no carrinho com a quantidade e seu preço base!`)
.setAuthor({ name: "SDKApps", iconURL: `https://res.cloudinary.com/dgcnfudya/image/upload/v1711769157/vyzyvzxajoboweorxh9s.png` })
.addFields(...[...fields, { name: '\u200B', value: '\u200B' },])
.setColor('personalize' in serverData && 'colorDest' in serverData.personalize ? serverData.personalize.colorDest : '#6E58C7')
.setThumbnail(`https://cdn.discordapp.com/icons/${DiscordServer.id}/${DiscordServer.icon}.webp`)
.setFooter({ text: DiscordServer.name, iconURL: `https://cdn.discordapp.com/icons/${DiscordServer.id}/${DiscordServer.icon}.webp` })
],
components: [row, row2],
components: [

new Discord.ActionRowBuilder()
.addComponents(
new Discord.ButtonBuilder()
.setCustomId(`cartEditQuantidade`)
.setLabel('Editar quantidade')
.setEmoji(await require('./emojisGet').editar)
.setStyle(Discord.ButtonStyle.Primary)
)
.addComponents(
new Discord.ButtonBuilder()
.setCustomId(`remove`)
.setEmoji(await require('./emojisGet').apagar)
.setLabel('Remover produto')
.setStyle('4')
),

// .addComponents(
// new Discord.ButtonBuilder()
// .setCustomId(`cupombutton`)
// .setLabel('Adicionar Cupom')
// .setStyle('1')
// );

new Discord.ActionRowBuilder()
.addComponents(
new Discord.ButtonBuilder()
.setCustomId(`paymentSelect`)
.setLabel('Ir para o pagamento')
.setEmoji(await require('./emojisGet').comprar)
.setStyle('3'),
)
.addComponents(

new Discord.ButtonBuilder()
.setCustomId('cancelCart')
.setLabel('Cancelar')
.setEmoji(await require('./emojisGet').cancelar)
.setStyle('4')
),

],
files: []
}

if (data.edit == true) {
const botMessages = await DiscordChannel.messages.cache.filter(msg => msg.author.id === client.user.id);

// Pegue a última mensagem enviada pelo bot
const lastBotMessage = await botMessages.first();
lastBotMessage.edit(contentEmbend)
} else {
await DiscordChannel.send(contentEmbend);
}
if ('personalize' in serverData && 'lembreteMensage' in serverData.personalize && serverData.personalize.lembreteMensage.active == true) {
let discordChannel = await DiscordServer.channels.cache.get(data.channelID)
if (discordChannel && !carrinhosMensage.includes(data.channelID)) {
setTimeout(async()=>{
try {
const userD = await client.users.fetch(user)
require('../Discord/discordIndex').sendDiscordMensageUser(userD,serverData.personalize.lembreteMensage.title,serverData.personalize.lembreteMensage.mensage,`https://discord.com/channels/${DiscordServer.id}/${data.channelID}`,'🛒・Ir para o carrinho')
carrinhosMensage.push(data.channelID)
} catch (error) {}
},600000)
}

}
setTimeout(async()=>{
try {
await DiscordServer.channels.cache.get(data.channelID).delete()
const userD = await client.users.fetch(user)
userD.send(`O seu ultimo carrinho no servidor ${DiscordServer.name} foi expirado!`)
} catch (error) {}
},1000000)
} catch (error) {
console.log("MainCartERROR: ",error);
console.log("MainCartERROR: ", error);
}


//remove product



};


73 changes: 0 additions & 73 deletions Discord/createMultiProductMensage.js

This file was deleted.

74 changes: 36 additions & 38 deletions Discord/createProductMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ registerFont(fontNormal, { family: 'Poppins' });
registerFont(fontSemiBold, { family: 'Poppins_Semi' })
registerFont(fontBold, { family: 'Poppins_Bold' })
let Discord = require('discord.js')
const functions = require('../functions');
module.exports = async (Discord2, client, data) => {

try {
Expand Down Expand Up @@ -230,52 +231,49 @@ module.exports = async (Discord2, client, data) => {
let serverDb = await db.findOne({ colecao: 'servers', doc: serverId })
let produtos = await serverDb.products
let productId = await data.productID

var produto = await serverDb.products.find(product => product.productID == productId)
let typeProduct = 'typeProduct' in produto ? produto.typeProduct : 'normal'
var index = await serverDb.products.findIndex(product => product.productID == productId)
let preco = await (produto.price / 100).toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' });
let preco = ''
if (typeProduct != 'multiple' && produto.preco && produto.preco != '') {
preco = (produto.price / 100).toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' });
}
let background = fs.readFileSync(produto.backGround == null ? path.join(__dirname, "..", 'public/img/LOGOFUNDO.png') : path.join(__dirname, "..", produto.backGround))
let buffer = await createImage(produto.productName, produto.producDesc, background, produto.productLogo, await preco, produto.estoque.length,serverDb.bankData.mercadoPagoToken ? true : false, serverDb.bankData.bankID ? true : false)
let buffer = await createImage(produto.productName, produto.producDesc, background, produto.productLogo, await preco, data.numberEstoque,serverDb.bankData.mercadoPagoToken ? true : false, serverDb.bankData.bankID ? true : false)
const attachment = new Discord.AttachmentBuilder(buffer, { name: 'ProductImage.jpeg' })
let totalEstoque = []
if (produto.estoque.length > 0) {
let estoque = produto.estoque.length > 25 ? 25 : produto.estoque.length
for (let index = 0; index < estoque; index++) {
let indexSring1 = `${index + 1}`
if (index == 0) {
totalEstoque.push(new Discord.StringSelectMenuOptionBuilder().setLabel(indexSring1).setValue(indexSring1).setDefault(true),)
}else{
totalEstoque.push(new Discord.StringSelectMenuOptionBuilder().setLabel(indexSring1).setValue(indexSring1),)
}



let components = []

if (typeProduct == 'multiple') {
let productsArrayOptions = []
let productList = produto.multipleProducts
for (let index = 0; index < productList.length; index++) {
const element = await productList[index];
let produto = await serverDb.products.find(product => product.productID == element)
await productsArrayOptions.push(
await new Discord.StringSelectMenuOptionBuilder().setLabel(produto.productName).setDescription(`${functions.formatarMoeda(produto.price)} • Estoque: ${'typeProduct' in produto ? produto.typeProduct == 'normal' ? produto.estoque.length : produto.estoque : produto.estoque.length}`).setValue(produto.productID)
)
}
components = [await new Discord.ActionRowBuilder().addComponents(
new Discord.StringSelectMenuBuilder()
.setCustomId(`quantidadeEdit_${data.productID}`)
.setOptions(productsArrayOptions)
)]
}else{
components = [new Discord.ActionRowBuilder().addComponents(
new Discord.ButtonBuilder()
.setCustomId(`quantidadeEdit_${data.productID}`)
.setLabel('Comprar')
.setEmoji(await require('./emojisGet').comprar)
.setStyle('3'),
)]
}
if (totalEstoque.length > 25) {
const numToRemove = totalEstoque.length - 25;
await totalEstoque.splice(-numToRemove);
}
if (totalEstoque.length <= 0) {
totalEstoque.push(new Discord.StringSelectMenuOptionBuilder().setLabel('Sem estoque').setValue('null').setDefault(true),)
}


let embed = await DiscordChannel.send({
files: [attachment],
components: [
new Discord.ActionRowBuilder().addComponents(
new Discord.StringSelectMenuBuilder()
.setCustomId(`qntProduct_${data.productID}`)
.setPlaceholder('Selecione a quantidade!')
.setMinValues(1)
.setMaxValues(1)
.addOptions(...totalEstoque)
.setDisabled(produto.estoque.length <= 0 ? true : false)
),
new Discord.ActionRowBuilder().addComponents(
new Discord.ButtonBuilder()
.setCustomId(`comprar_${data.productID}`)
.setLabel('Comprar')
.setStyle('3'),
)
]
components: components
});
try {
DiscordChannel.setTopic(data.productID)
Expand Down
Loading
Loading