Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const {SlashCommandBuilder} = require('@discordjs/builders');
- const {EmbedBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder, PermissionFlagsBits, ChannelType} = require('discord.js')
- const config = require('../../config.json')
- const {buildEmbed} = require('../../functions/errorEmbed')
- const emojis = require('../../util/emojis.json')
- const {checkManager} = require('../../functions/isManager')
- const posted = []
- const cooldown = []
- const missingperms = []
- const missingchannel = []
- const missingserver = []
- const lessamount = []
- exports.run = async (client, interaction) => {
- const {options, member, guild} = interaction
- const invite = options.getString('invite')
- let manager = await checkManager(client, guild, member)
- if (!manager) return interaction.reply({
- ephemeral: true,
- embeds: [buildEmbed('You are not authorized to run this command.')]
- })
- //validating invite from slash command itself
- if (!isInvite(invite)) return interaction.reply({
- ephemeral: true,
- embeds: [buildEmbed('Invalid invite code format, learn more about invites [here](https://support.discord.com/hc/en-us/articles/208866998-Invites-101)')]
- })
- const inv = await client.fetchInvite(invite)
- if (!inv) return interaction.reply({
- ephemeral: true,
- embeds: [buildEmbed('I couldn\'t find that invite, please try again later.')]
- })
- if (inv.guild.id != interaction.guild.id) return interaction.reply({
- ephemeral: true,
- embeds: [buildEmbed(`[Server Invite](${invite}) you have specified doesn't belong this server, please try with this server invite`)]
- })
- await client.rclient.hSet(`guild${guild.id}`, "invitelink", invite)
- //making buttons for invites
- const bt = []
- const b = new ButtonBuilder()
- .setURL(invite)
- .setStyle(ButtonStyle.Link)
- .setLabel('Invite')
- bt.push(b)
- const appeal = options.getString('appeal')
- if (appeal) {
- const bb = new ButtonBuilder()
- .setStyle(ButtonStyle.Link)
- .setLabel('Appeals')
- .setURL(appeal)
- bt.push(bb)
- }
- const row = new ActionRowBuilder().addComponents(bt)
- //heist amount
- let coins = options.getString('amount')
- let amount = 0
- const conditions = ['k', 'm', 'b'];
- if (conditions.some((el) => coins.includes(el))) {
- let object = {
- k: 'e3',
- m: 'e6',
- b: 'e9',
- }
- amount = coins.replace(/k|m|b/g, function (m) {
- return object[m];
- })
- } else amount = Number(coins)
- amount = Number(amount)
- let ad = options.getString('ad')
- ad = ad.split('\\n')
- const type = options.getString('adtype')
- if(type != 'heist') {
- return interaction.reply({
- ephemeral: true,
- embeds: [buildEmbed(`Posting advertisements for other than Dankmemer heists is an upcoming feature, please join our [support server](${config.supportserver.Invite}) to know more.`)]
- })
- }
- const s = {
- 'heist': "Dankmemer heist",
- 'broheist': "Bro heist",
- 'minigame': "Minigame"
- }
- const em = new EmbedBuilder()
- .setColor(client.config.embedHex)
- .setDescription(`${ad.join('\n')}`)
- .setTitle('Preview of your **' + s[type] + '** ad')
- .setFooter({text: "You have 30 seconds to respond, server invite and appeals link won't be displayed."})
- .setImage("https://media.discordapp.net/attachments/883293909093068833/1044666862170030160/Picsart_22-11-22_18-32-52-233.jpg")
- const e = new ActionRowBuilder().addComponents(
- new ButtonBuilder()
- .setStyle(ButtonStyle.Danger)
- .setCustomId(`${interaction.id}-heistad_cancel`)
- .setLabel('Cancel')
- .setEmoji(emojis.fail),
- new ButtonBuilder()
- .setStyle(ButtonStyle.Success)
- .setCustomId(`${interaction.id}-heistad_confirm`)
- .setLabel('Confirm')
- .setEmoji(emojis.success)
- )
- let msg = await interaction.reply({embeds: [em], components: [e], fetchReply: true})
- const filter = async res => {
- if (res.user.id != interaction.user.id) {
- return interaction.followUp({ephemeral: true, embeds: [buildEmbed("This is not your advertise menu.")]})
- } else {
- await res.deferUpdate();
- return true;
- }
- }
- const collector = await msg.createMessageComponentCollector({time: 30000, filter})
- collector.on('collect', async int => {
- let customId = int.customId
- customId = customId.split('-')[1]
- customId = customId.split('_')[1]
- if (customId === 'cancel') {
- await collector.stop()
- msg.edit({embeds: [buildEmbed("Invoke cancelled.")], components: []})
- } else if (customId === 'confirm') {
- await advertise(client, guild, amount, msg)
- }
- })
- }
- exports.help = {
- name: "advertise",
- description: "posts your advertisement among your partner servers",
- usage: ["advertise"],
- example: ["advertise"]
- }
- exports.conf = {
- aliases: [],
- cooldown: 10,
- data: new SlashCommandBuilder()
- .setName(exports.help.name)
- .setDescription(exports.help.description)
- .addStringOption(opt => {
- return opt
- .setName('adtype')
- .setDescription('enter what type of advertisement you are posting.')
- .addChoices(
- {name: 'Dankmemer Heists', value: 'heist'},
- {name: 'Brobot Heists', value: 'broheist'},
- {name: 'Minigames', value: 'minigame'}
- )
- .setRequired(true)
- })
- .addStringOption(opt => {
- return opt
- .setName('amount')
- .setDescription('enter your heist amount (can be a number like "250" or a shorthand like "50k")')
- .setRequired(true)
- })
- .addStringOption(opt => {
- return opt
- .setName('invite')
- .setDescription('please specify your server invite, this will be displayed with heist ad')
- .setRequired(true)
- })
- .addStringOption(opt => {
- return opt
- .setName('ad')
- .setDescription('specify your ad, make sure to include all details (invite, time ..etc)')
- .setRequired(true)
- })
- .addStringOption(opt => {
- return opt
- .setName('appeal')
- .setDescription('specify ban appeals link here, It could be server or forms')
- .setRequired(false)
- })
- }
- function isInvite(string) {
- const regex = /(https?:\/\/)?(www\.)?(discord\.(gg|io|me|li)|discordapp\.com\/invite)\/.+[a-z]/
- return regex.test(string)
- }
- async function sleep(ms) {
- return new Promise(resolve => setTimeout(resolve, ms));
- }
- async function advertise(client, guild, amount, mess) {
- await mess.edit({embeds: [buildEmbed(`${emojis.loading} please wait while your heist ad is being posted.`)]})
- const partners = await client.rclient.hGetAll(`partdeals${guild.id}`)
- for(const partner in partners) {
- try {
- const pguild = await client.guilds.fetch(partner)
- const deal = await client.rclient.hGet(`partdeals${guild.id}`, `${pguild.id}`)
- let chid = deal.split('/')[0]
- try {
- let channel = await pguild.channels.fetch(chid)
- console.log(channel)
- if(!checkPerms(client, channel)) return missingperms.push(pguild.id)
- if(!await client.rclient.EXISTS(`heistadcd${guild.id}${pguild.id}`)) return cooldown.push(pguild.id)
- const db = await client.rclient.HGETALL(`guild ${pguild.id}`)
- const minamt = db.minheistamount ?? 0
- if(minamt > amount) return lessamount.push(pguild.id)
- let pings = deal.split('/')[1]
- let mm
- if(!posted.includes(pguild.id)) {
- channel.send({content: `${mess}\n${pings}`})
- }
- posted.push(pguild.id)
- if(channel.type === ChannelType.GuildNews) mm.crosspost()
- }
- catch(e) {
- console.log(e)
- missingchannel.push(pguild.id)
- }
- }
- catch(e) {
- console.log(e)
- missingserver.push(partner)
- }
- }
- }
- function checkPerms(client, channel) {
- //assumptions is channel exist
- let hasperms = false
- if(channel.permissionsFor(client.user.id).has(PermissionFlagsBits.ViewChannel)) {
- if(channel.permissionsFor(client.user.id).has(PermissionFlagsBits.SendMessages)) {
- if(channel.permissionsFor(client.user.id).has(PermissionFlagsBits.MentionEveryone)) {
- hasperms = true
- }
- }
- }
- return hasperms;
- }
Advertisement
Add Comment
Please, Sign In to add comment