Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-Santana-j committed May 15, 2024
1 parent 586ad8e commit adeb766
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 39 deletions.
18 changes: 14 additions & 4 deletions Discord/createCartMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,22 @@ module.exports = async (Discord, client, data) => {
let carrinhos = require('./discordIndex').carrinhos

if (carrinhos[user]) {
let total = 0
let produtcs = 0
await carrinhos[user].forEach(async (element, index) => {
let produto = await serverData.products.find(product => product.productID == element.product)
const valorReal = produto.price / 100;
let valorReal = parseInt(produto.price) / 100;
let valorFormatado = valorReal.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' });
total = total + (parseInt(produto.price) * element.quantidade)
produtcs = produtcs + parseInt(element.quantidade)
fields.push({ name: `${index + 1} - ${produto.productName} - ${element.quantidade}x`, value: valorFormatado },)
});
let valorTotalReal = total / 100;
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 })
} else {
DiscordChannel.delete()
return
Expand All @@ -80,8 +90,8 @@ module.exports = async (Discord, client, data) => {
Abaixo são os itens do seu carrinho.`)

.setAuthor({ name: "SDKApps", iconURL: `https://res.cloudinary.com/dgcnfudya/image/upload/v1711769157/vyzyvzxajoboweorxh9s.png`, url: 'https://discord.gg/sdkapps' })
.addFields(...[{ name: '\u200B', value: '\u200B' }, ...fields, { name: '\u200B', value: '\u200B' },])
.setColor("#6E58C7")
.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` })
],
Expand All @@ -101,7 +111,7 @@ module.exports = async (Discord, client, data) => {


} catch (error) {

console.log("MainCartERROR: ",error);
}


Expand Down
4 changes: 4 additions & 0 deletions Discord/createProductMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ module.exports = async (Discord2, client, data) => {

}
}
if (totalEstoque.length > 25) {
const numToRemove = totalEstoque.length - 25;
await totalEstoque.splice(-numToRemove);
}
let embed = await DiscordChannel.send({
files: [attachment],
components: [
Expand Down
41 changes: 25 additions & 16 deletions Discord/discordIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module.exports = (Discord, client) => {
.setTitle('Selecione abaixo o item que deseja excluir!')
.setDescription(`Clique em cancelar caso desista de excluir um item!`)
.setAuthor({ name: "SDKApps", iconURL: `https://res.cloudinary.com/dgcnfudya/image/upload/v1711769157/vyzyvzxajoboweorxh9s.png`, url: 'https://discord.gg/sdkapps' })
.setColor("#6E58C7")
.setColor('personalize' in server && 'colorDest' in server.personalize ? server.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` })
],
Expand Down Expand Up @@ -242,13 +242,12 @@ module.exports = (Discord, client) => {
content: `🛒 | Criando o Carrinho...`,
ephemeral: true
})

setTimeout(() => {
interaction.editReply({
content: ` `,
embeds: [
new Discord.EmbedBuilder()
.setColor("#6E58C7")
.setColor('personalize' in server && 'colorDest' in server.personalize ? server.personalize.colorDest : '#6E58C7')
.setTitle(`😍 | Carrinho Criado!`)
.setDescription(`<@${interaction.user.id}> **Seu carrinho foi criado com sucesso, fique avontade para adicionar mais produtos.**`)
],
Expand Down Expand Up @@ -388,7 +387,7 @@ module.exports = (Discord, client) => {
content: getData.isProduct1n == true ? '⚠️ 1 ou mais produtos tem o valor inferior a 1 real no pix para cobrir as taxas do cartão temos que reajustar o valor para no minimo 1 real' : '',
embeds: [
new Discord.EmbedBuilder()
.setColor("#6E58C7")
.setColor('personalize' in server && 'colorDest' in server.personalize ? server.personalize.colorDest : '#6E58C7')
.setTitle(`💕 | Produto Criado!`)
.setDescription(`<@${interaction.user.id}> **Acesse o link abaixo para fazer o pagamento do seu produto.**`)
],
Expand Down Expand Up @@ -501,10 +500,7 @@ module.exports = (Discord, client) => {
})
}
}





if (interaction.customId && interaction.customId.includes('remove')) {
if (!carrinhos[interaction.user.id]) {
await DiscordChannel.delete()
Expand Down Expand Up @@ -597,7 +593,7 @@ module.exports = (Discord, client) => {
.setDescription(`Você recebeu um novo produto de ${SendUser.globalName}`)
.addFields(...fields)
.setAuthor({ name: "SDKApps", iconURL: `https://res.cloudinary.com/dgcnfudya/image/upload/v1711769157/vyzyvzxajoboweorxh9s.png`, url: 'https://discord.gg/sdkapps' })
.setColor("#6E58C7")
.setColor('personalize' in server && 'colorDest' in server.personalize ? server.personalize.colorDest : '#6E58C7' )
.setTimestamp()
.setFooter({ text: DiscordServer.name, iconURL: `https://cdn.discordapp.com/icons/${DiscordServer.id}/${DiscordServer.icon}.webp ` })
],
Expand All @@ -609,7 +605,7 @@ module.exports = (Discord, client) => {
.setDescription(`Você enviou um produto para ${user.globalName} Abaixo esta uma copia do que foi enviado:`)
.addFields(...fields)
.setAuthor({ name: "SDKApps", iconURL: `https://res.cloudinary.com/dgcnfudya/image/upload/v1711769157/vyzyvzxajoboweorxh9s.png`, url: 'https://discord.gg/sdkapps' })
.setColor("#6E58C7")
.setColor('personalize' in server && 'colorDest' in server.personalize ? server.personalize.colorDest : '#6E58C7')
.setTimestamp()
.setFooter({ text: DiscordServer.name, iconURL: `https://cdn.discordapp.com/icons/${DiscordServer.id}/${DiscordServer.icon}.webp ` })
],
Expand Down Expand Up @@ -877,7 +873,7 @@ module.exports.sendProductPayment = async (params, id, type) => {
...fields
)
.setAuthor({ name: "SDKApps", iconURL: `https://res.cloudinary.com/dgcnfudya/image/upload/v1711769157/vyzyvzxajoboweorxh9s.png`, url: 'https://discord.gg/sdkapps' })
.setColor("#6E58C7")
.setColor('personalize' in serverData && 'colorDest' in serverData.personalize ? serverData.personalize.colorDest : '#6E58C7')
.setFooter({ text: DiscordServer.name, iconURL: `https://cdn.discordapp.com/icons/${DiscordServer.id}/${DiscordServer.icon}.webp` })
],
}).catch(() => { })
Expand All @@ -887,7 +883,7 @@ module.exports.sendProductPayment = async (params, id, type) => {
.setTitle('📦 | Sua entrega chegou!')
.setDescription(`Abaixo estão os dados da sua entrega:`)
.setAuthor({ name: "SDKApps", iconURL: `https://res.cloudinary.com/dgcnfudya/image/upload/v1711769157/vyzyvzxajoboweorxh9s.png`, url: 'https://discord.gg/sdkapps' })
.setColor("#6E58C7")
.setColor('personalize' in serverData && 'colorDest' in serverData.personalize ? serverData.personalize.colorDest : '#6E58C7')
.addFields(...fields)
.setFooter({ text: DiscordServer.name, iconURL: `https://cdn.discordapp.com/icons/${DiscordServer.id}/${DiscordServer.icon}.webp` })
],
Expand All @@ -900,7 +896,7 @@ module.exports.sendProductPayment = async (params, id, type) => {
.setTitle('📦 | Sua entrega chegou!')
.setDescription(`Enviamos a entrega no seu privado caso não tenha recebido o seu privado pode esta bloqueado então tenha certeza de baixar os arquivos antes que o carrinho seja fechado`)
.setAuthor({ name: "SDKApps", iconURL: `https://res.cloudinary.com/dgcnfudya/image/upload/v1711769157/vyzyvzxajoboweorxh9s.png`, url: 'https://discord.gg/sdkapps' })
.setColor("#6E58C7")
.setColor('personalize' in serverData && 'colorDest' in serverData.personalize ? serverData.personalize.colorDest : '#6E58C7')
.addFields(...fields)
.setFooter({ text: DiscordServer.name, iconURL: `https://cdn.discordapp.com/icons/${DiscordServer.id}/${DiscordServer.icon}.webp` })
],
Expand All @@ -925,7 +921,7 @@ module.exports.sendProductPayment = async (params, id, type) => {
let valorTotal = 0
await carrinho.forEach(async (element, index) => {
var product = await serverData.products.find(product => product.productID == element.product)
valorTotal = valorTotal + parseInt(product.price)
valorTotal = valorTotal + (parseInt(product.price) * element.quantidade)
fieldsPublic.value += `${index + 1} - ${product.productName} - ${element.quantidade}x\n`
});
fieldsPublic = { name: fieldsPublic.name, value: "`" + fieldsPublic.value + "`" }
Expand All @@ -951,7 +947,7 @@ module.exports.sendProductPayment = async (params, id, type) => {
.setDescription(`Uma nova compra foi feita abaixo está os dados da compra:`)
.addFields(...allfieldsPublic)
.setAuthor({ name: user.globalName, iconURL: userPic })
.setColor("#6E58C7")
.setColor('personalize' in serverData && 'colorDest' in serverData.personalize ? serverData.personalize.colorDest : '#6E58C7')
.setTimestamp()
.setFooter({ text: DiscordServer.name, iconURL: `https://cdn.discordapp.com/icons/${DiscordServer.id}/${DiscordServer.icon}.webp ` })
],
Expand All @@ -963,6 +959,18 @@ module.exports.sendProductPayment = async (params, id, type) => {
}
}

if ('personalize' in serverData && 'cargoPay' in serverData.personalize) {
try {
const member = await DiscordServer.members.fetch(params.userID);
const role = await DiscordServer.roles.cache.get(serverData.personalize.cargoPay);
await member.roles.add(role)

} catch (error) {

}
}


let analytics = await db.findOne({ colecao: "analytics", doc: serverData.id })

if (analytics.error == false) {
Expand Down Expand Up @@ -1016,6 +1024,7 @@ module.exports.sendProductPayment = async (params, id, type) => {

module.exports.sendDiscordMensageChannel = async (server, channel, title, mensage, user, deleteChannel = false) => {
try {
let serverData = await db.findOne({colecao:'servers',doc:server})
var DiscordServer = await client.guilds.cache.get(server);
var DiscordChannel
if (user) {
Expand All @@ -1028,7 +1037,7 @@ module.exports.sendDiscordMensageChannel = async (server, channel, title, mensag
new Discord.EmbedBuilder()
.setTitle(`${DiscordServer.name} | ${title}`)
.setDescription(mensage)
.setColor("#6E58C7")
.setColor('personalize' in serverData && 'colorDest' in serverData.personalize ? serverData.personalize.colorDest : '#6E58C7')
]
}).catch(() => { })

Expand Down
2 changes: 1 addition & 1 deletion handler/commands/util/aprovar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ module.exports = {
try {
let carrinhos = require("../../../Discord/discordIndex").carrinhos
let carrinho = carrinhos[DiscordChannel.topic]
interaction.reply('Compra Aprovada!')
await require("../../../Discord/discordIndex").sendProductPayment({
serverID:interaction.guildId,
userID:DiscordChannel.topic,
carrinhos:JSON.stringify(carrinho),
}, null, 'aprovado')
interaction.reply('Compra Aprovada!')
} catch (error) {
console.log(error);
}
Expand Down
84 changes: 69 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ client.on("interactionCreate", async (interaction) => {


client.on(Events.ShardError, error => {
console.error('A websocket connection encountered an error:', error);
console.error('A websocket connection encountered an error:', error);
});

process.on('unhandledRejection', error => {
console.error('Unhandled promise rejection:', error);
console.error('Unhandled promise rejection:', error);
});

//TODO------------WEB PAGE--------------
Expand Down Expand Up @@ -402,7 +402,25 @@ app.get('/server/personalize/:id', functions.subscriptionStatus, async (req, res
return
}

res.render('personalize', { host: `${webConfig.host}`, user: user, server: server })
const guilds = client.guilds.cache;
const isBotInServer = guilds.has(serverID);
if (!isBotInServer) {
res.redirect(`/addbot/${serverID}`)
return
}
let guild = guilds.get(serverID)
const roles = guild.roles.cache;
const filteredRoles = roles.filter(role => {
return role.name !== '@everyone' && role.managed !== true;
});
const roleObjects = filteredRoles.map(role => {
return {
name: role.name,
id: role.id
};
});

res.render('personalize', { host: `${webConfig.host}`, cargos: roleObjects, user: user, server: server })
})

app.get('/server/analytics/:id', functions.subscriptionStatus, async (req, res) => {
Expand Down Expand Up @@ -585,8 +603,8 @@ app.post('/config/change', async (req, res) => {
let server = await db.findOne({ colecao: "servers", doc: req.body.serverID })
if (server.error == false) {
let configs = {
noticeChannel:null,
publicBuyChannel:null
noticeChannel: null,
publicBuyChannel: null
}
if ('configs' in server) {
configs = server.configs
Expand All @@ -605,19 +623,19 @@ app.post('/config/change', async (req, res) => {
}
})

app.post('/config/blockbank',async(req,res)=>{
app.post('/config/blockbank', async (req, res) => {
try {
let bank = req.body.bank
let possiveisBanks = ['Banco Inter S.A.',"Picpay Serviços S.A."]
let possiveisBanks = ['Banco Inter S.A.', "Picpay Serviços S.A."]
if (!possiveisBanks.includes(bank)) {
res.status(200).json({ success: false, data:'Banco invalido!' })
res.status(200).json({ success: false, data: 'Banco invalido!' })
return
}

let server = await db.findOne({colecao:"servers",doc:req.body.serverID})
let server = await db.findOne({ colecao: "servers", doc: req.body.serverID })

if (!server) {
res.status(200).json({ success: false, data:'Erro ao bloquear o banco!' })
res.status(200).json({ success: false, data: 'Erro ao bloquear o banco!' })
return
}

Expand All @@ -627,20 +645,20 @@ app.post('/config/blockbank',async(req,res)=>{
}

if (blockBank.includes(bank)) {
res.status(200).json({ success: false, data:'Este banco ja foi bloqueado!' })
return
res.status(200).json({ success: false, data: 'Este banco ja foi bloqueado!' })
return
}


blockBank.push(bank)

db.update('servers',req.body.serverID,{
blockBank:blockBank
db.update('servers', req.body.serverID, {
blockBank: blockBank
})
res.status(200).json({ success: true })
} catch (error) {
console.log(error);
res.status(200).json({ success: false, data:'Erro ao bloquear o banco!' })
res.status(200).json({ success: false, data: 'Erro ao bloquear o banco!' })
}


Expand Down Expand Up @@ -729,7 +747,43 @@ app.post('/perms/get', async (req, res) => {
}
})

app.post('/personalize/change',async(req,res)=>{
try {
let server = await db.findOne({ colecao: "servers", doc: req.body.serverID })
if (server) {
let Newpersonalize = {
colorDest:null,
cargoPay:null
}
if ('personalize' in server) {
Newpersonalize = server.personalize
}

if ('colorDest' in req.body) {
Newpersonalize.colorDest = req.body.colorDest
}
if ('cargoPay' in req.body) {
Newpersonalize.cargoPay = req.body.cargoPay
}

db.update('servers',req.body.serverID,{
personalize:Newpersonalize
})
if (!res.headersSent) {
res.status(200).json({success:true,})
}
}else{
if (!res.headersSent) {
res.status(200).json({success:false,data:'Erro ao tentar recuperar o servidor!'})
}
}
} catch (error) {
console.log("PersonalizeChangeERROR: ",error);
if (!res.headersSent) {
res.status(200).json({success:false,data:'Erro ao tentar mudar a personalização!'})
}
}
})



Expand Down
Loading

0 comments on commit adeb766

Please sign in to comment.