Skip to content

Commit

Permalink
🤑 Comando de cobrar (Ephemeral)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashu11-A committed Mar 8, 2024
1 parent d49b301 commit b36539a
Show file tree
Hide file tree
Showing 9 changed files with 385 additions and 184 deletions.
36 changes: 28 additions & 8 deletions src/discord/commands/configs/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import {
ActionRowBuilder,
ApplicationCommandOptionType,
ApplicationCommandType,
type ButtonBuilder,
ButtonStyle,
ChannelType,
EmbedBuilder,
TextChannel,
type CategoryChannel,
ButtonStyle
type ButtonBuilder
} from 'discord.js'

new Command({
Expand Down Expand Up @@ -153,6 +152,14 @@ new Command({
description: '[ ⚙️ ] Configurar sistemas de pagamentos desejado.',
type: ApplicationCommandOptionType.String,
choices: [{ name: 'Mercado Pago', value: 'mp' }]
},
{
name: 'logs',
description: '[ 📃 ] Configurar registro dos pagamentos',
type: ApplicationCommandOptionType.Channel,
channelTypes: [
ChannelType.GuildText
]
}
]
},
Expand Down Expand Up @@ -298,13 +305,18 @@ new Command({
break
}
case 'pagamentos': {
const addProduto = options.getChannel('add-produto') as TextChannel
const carrinho = options.getChannel('carrinho') as CategoryChannel
const addProduto = options.getChannel('add-produto')
const carrinho = options.getChannel('carrinho')
const config = options.getString('config')
const logs = options.getChannel('logs')

if (config !== null) {
await MpModalconfig({ interaction })
}

if (addProduto !== null) {
await interaction.deferReply({ ephemeral: true })
await sendEmbed(interaction, addProduto)
await sendEmbed(interaction, addProduto as TextChannel)
}
if (carrinho !== null) {
await interaction.deferReply({ ephemeral: true })
Expand All @@ -316,8 +328,16 @@ new Command({
data: carrinho.id
})
}
if (config !== null) {
await MpModalconfig({ interaction })

if (logs !== null) {
await interaction.deferReply({ ephemeral: true })
await new Database({
interaction,
pathDB: 'config.logs',
typeDB: 'payments'
}).set({
data: logs.id
})
}

break
Expand Down
16 changes: 0 additions & 16 deletions src/discord/commands/payments/buy.ts

This file was deleted.

64 changes: 64 additions & 0 deletions src/discord/commands/payments/charge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Command } from '@/discord/base'
import { createCart } from '@/discord/components/payments'
import { genv4 } from '@/functions'
import { ApplicationCommandOptionType, ApplicationCommandType, EmbedBuilder, TextChannel } from 'discord.js'

new Command({
name: 'cobrar',
nameLocalizations:
{
'en-US': 'charge'
},
description: '[ 🛒 Pagamentos ] Cobrar um determinado valor',
descriptionLocalizations: {
'en-US': '[ 🛒 Payments ] Charge a certain amount'
},
dmPermission,
type: ApplicationCommandType.ChatInput,
options: [
{
name: 'valor',
description: 'Valor a ser cobrado',
type: ApplicationCommandOptionType.Number,
required
},
{
name: 'user',
description: 'Usuário a ser cobrado',
type: ApplicationCommandOptionType.User,
required
}
],
async run (interaction) {
if (!interaction.inCachedGuild()) return
await interaction.deferReply({ ephemeral })
const { options, guild } = interaction
const value = options.getNumber('valor', true)
const user = options.getUser('user', true)

const name = `🛒-${user.id}`
const paymentChannel = guild.channels.cache.find((c) => c.name === name)
if (paymentChannel instanceof TextChannel) {
await interaction.editReply({
embeds: [
new EmbedBuilder({
title: `❌ | Usuário ${user.displayName ?? user.username}, já tem um carrinho, caso queira continuar, delete o carrinho atual.`
}).setColor('Red')
]
})
return
}

await createCart(interaction, {
product: {
amount: value,
quantity: 1,
id: genv4(),
name: `Cobrança para ${user.displayName ?? user.username}`,
isIncremental: false,
isEphemeral: true
},
user
})
}
})
11 changes: 8 additions & 3 deletions src/discord/components/payments/cart/cartCollectorButtons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@ export default async function cartCollectorButtons (options: {

const customIdHandlers: CustomIdHandlers = {
Verify: async () => { await PaymentBuilder.verifyPayment() },
DM: async () => { await PaymentBuilder.DM() },

WTF: async () => { await PaymentBuilder.WTF() },

Add: async () => { await PaymentBuilder.AddOrRem({ type: 'Add' }) },
Rem: async () => { await PaymentBuilder.AddOrRem({ type: 'Rem' }) },
Remove: async () => { await PaymentBuilder.RemoveItem() },
Pix: async () => { await createPayment({ interaction, method: 'pix' }) },
Cancelar: async () => { await PaymentBuilder.Cancelar() },

Next: async () => { await PaymentBuilder.NextOrBefore({ type: 'next' }) },
Before: async () => { await PaymentBuilder.NextOrBefore({ type: 'before' }) },
Cancelar: async () => { await PaymentBuilder.Cancelar() },

Pix: async () => { await createPayment({ interaction, method: 'pix' }) },
CardDebito: async () => { await createPayment({ interaction, method: 'debit_card' }) },
CardCredito: async () => { await createPayment({ interaction, method: 'credit_card' }) },

DM: async () => { await PaymentBuilder.DM() },
Registro: async () => { await PaymentBuilder.Registro() },
Login: async () => { await PaymentBuilder.Login() }
}
Expand Down
1 change: 1 addition & 0 deletions src/discord/components/payments/cart/cartCollectorModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default async function cartCollectorModal (options: {

const { guildId, user, channel, message, fields, channelId } = interaction
const { modalData, modalProperties } = getModalData(key)

let dataInfo: Record<string, string> = {}
for (const { customId } of modalData) {
dataInfo = ({ ...dataInfo, [customId]: fields.getTextInputValue(customId) })
Expand Down
Loading

0 comments on commit b36539a

Please sign in to comment.