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 5, 2024
1 parent 9b1d794 commit 9b602fd
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 8 deletions.
28 changes: 28 additions & 0 deletions Discord/discordIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,34 @@ module.exports.sendProductPayment = async (params, id, type) => {
files: fields
});

if ('configs' in serverData && 'publicBuyChannel' in serverData.configs && serverData.configs.publicBuyChannel ) {
let findChannelPublic = DiscordServer.channels.cache.find(c => c.id === serverData.configs.publicBuyChannel)
let fieldsPublic = { name: `Carrinho:`, value: `\n` }
let valorTotal = 0
await carrinho.forEach(async(element,index) => {
var product = await serverData.products.find(product => product.productID == element)
valorTotal = valorTotal + parseInt(product.price)
fieldsPublic.value += `${index + 1} - ${product.productName}\n`
});
let allfieldsPublic = [ { name: '\u200B', value: '\u200B' },
{ name: 'Cliente:', value: user.username, inline: true },
{ name: 'Valor total:', value: await functions.formatarMoeda(valorTotal), inline: true },
fieldsPublic,
{ name: 'Data e hora da compra', value: dataHoraFormatada },
{ name: '\u200B', value: '\u200B' }]
findChannelPublic.send({
embeds: [
new Discord.EmbedBuilder()
.setTitle(`🛍️ | Nova compra!`)
.setDescription(`Uma nova compra foi feita abaixo está os dados da compra:`)
.addFields(...allfieldsPublic)
.setAuthor({ name: "SDKApps", iconURL: `https://res.cloudinary.com/dgcnfudya/image/upload/v1711769157/vyzyvzxajoboweorxh9s.png`, url: 'https://discord.gg/sdkapps' })
.setColor("#6E58C7")
.setFooter({ text: DiscordServer.name, iconURL: `https://cdn.discordapp.com/icons/${DiscordServer.id}/${DiscordServer.icon}.webp` })
],
})
}

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

if (analytics.error == false) {
Expand Down
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,16 @@ app.post('/config/change', async (req, res) => {
try {
let server = await db.findOne({ colecao: "servers", doc: req.body.serverID })
if (server.error == false) {
let configs = server.configs
let configs = {
noticeChannel:null,
publicBuyChannel:null
}
if ('configs' in server) {
configs = server.configs
}
configs.publicBuyChannel
configs.noticeChannel = req.body.noticeChannel
configs.publicBuyChannel = req.body.publicBuyChannel
db.update('servers', req.body.serverID, {
configs: configs
})
Expand Down Expand Up @@ -733,7 +741,6 @@ app.use('/', stripeRoutes);
//TODO PRODUTOS ROUTES

const produtoRoutes = require('./stripe/productsRoutes.js');

app.use('/', produtoRoutes);


Expand Down
20 changes: 17 additions & 3 deletions public/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,30 @@ let serverID = location.pathname.replace('/server/config/', "")
document.getElementById('save-configs').addEventListener('click', async () => {
const opcoes = document.getElementById('bot-config-channel-list').querySelectorAll('option');
let channelID = null;
console.log(1);

await opcoes.forEach(option => {
if (option.value === document.getElementById('bot-config-channel').value) {
channelID = option.getAttribute('data-channel');
}
});
console.log(channelID);

let channelIDBuy = null
const opcoesBuy = document.getElementById('bot-config-channel-buy-list').querySelectorAll('option');
await opcoesBuy.forEach(option => {
if (option.value === document.getElementById('bot-config-channel-buy').value) {
channelIDBuy = option.getAttribute('data-channel');
}
});

let session = await fetch('/config/change', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
serverID: serverID,
noticeChannel:channelID
noticeChannel:channelID,
publicBuyChannel:channelIDBuy
}),
}).then(response => { return response.json() })
if (session.success == true) {
Expand All @@ -28,6 +37,11 @@ document.getElementById('save-configs').addEventListener('click', async () => {
}
})

document.getElementById('cancel-configs').addEventListener('click',()=>{
document.getElementById('bot-config-channel').value = ''
document.getElementById('bot-config-channel-buy').value = ''
})

document.getElementById('changePaymentMethod').addEventListener('click', async () => {
try {
let session = await fetch('/subscription/update', {
Expand Down
3 changes: 1 addition & 2 deletions stripe/productsRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,9 @@ router.post('/product/estoqueAdd', async (req, res) => {
})
res.status(200).json({ success: true, data: '' })
} else {
res.status(200).json({ success: false, data: '' })
res.status(200).json({ success: true, data: '' })
}
} catch (error) {
res.status(200).json({ success: false, data: '' })
console.log(error);
}
})
Expand Down
11 changes: 10 additions & 1 deletion views/config.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,23 @@
</datalist>
</div>
<div class="bot-config-inputs-containner" id="bot-config-notice-channel">
<label class="lable-padrao" for="bot-config-idioma">Canal para as noticias do bot</label>
<label class="lable-padrao" for="bot-config-channel">Canal para as noticias do bot</label>
<input required type="text" class="input-padrao" list="bot-config-channel-list" placeholder="canal" id="bot-config-channel">
<datalist id="bot-config-channel-list">
<% channels.forEach(element => { %>
<option data-channel="<%= element.id %>" value="<%= element.name %>"></option>
<% }) %>
</datalist>
</div>
<div class="bot-config-inputs-containner" id="bot-config-buy-channel">
<label class="lable-padrao" for="bot-config-channel-buy">Canal para exibir compras para o publico</label>
<input required type="text" class="input-padrao" list="bot-config-channel-list" placeholder="canal" id="bot-config-channel-buy">
<datalist id="bot-config-channel-buy-list">
<% channels.forEach(element => { %>
<option data-channel="<%= element.id %>" value="<%= element.name %>"></option>
<% }) %>
</datalist>
</div>
</div>
</div>
<div id="plan-config-containner">
Expand Down

0 comments on commit 9b602fd

Please sign in to comment.