Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Merge admin verify rate limit (#58)
Browse files Browse the repository at this point in the history
* Better Verify Success Output

* Add warning embed

* Add errorEmbed when get no paginatedInscriptions

* Allow admins to use the tool

* Text updates.

* Update message.

* Attempted fix.

* Another attempt.

* Null the attributes.

* Tiny text update.

---------

Co-authored-by: rk1129 <[email protected]>
  • Loading branch information
captain-munch and rk1129 authored Apr 10, 2023
1 parent a87895e commit adb0250
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 99 deletions.
4 changes: 2 additions & 2 deletions button/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {

const signatureInput = new TextInputBuilder()
.setCustomId(SIGNATURE_ID)
.setLabel('BIP-322 signature')
.setLabel('BIP-322 Signature')
.setStyle(TextInputStyle.Short)
.setMaxLength(120)

Expand Down Expand Up @@ -68,7 +68,7 @@ module.exports = {

const bipMessageInput = new TextInputBuilder()
.setCustomId('bipMessage')
.setLabel('BIP-322 message')
.setLabel('BIP-322 Message')
.setStyle(TextInputStyle.Short)
.setValue(message)
.setRequired(false)
Expand Down
52 changes: 25 additions & 27 deletions commands/channel-add.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
const { SlashCommandBuilder, ButtonBuilder, ActionRowBuilder, ButtonStyle } = require('discord.js')
const { SlashCommandBuilder, ButtonBuilder, ActionRowBuilder, ButtonStyle, PermissionFlagsBits } = require('discord.js')
const errorEmbed = require('../embed/error-embed')
const successEmbed = require('../embed/success-embed')
const infoEmbed = require('../embed/info-embed')
const warningEmbed = require('../embed/warning-embed')
const ManageChannels = require('../db/manage-channels')
const { COMMON_ERROR } = require('../embed/error-messages')

module.exports = {
data: new SlashCommandBuilder().setName('channel-add').setDescription('Add the verify bot to this channel.'),
data: new SlashCommandBuilder()
.setName('channel-add')
.setDescription('Add the verify bot to this channel.')
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild),
async execute(interaction) {
try {
if (interaction.user.id === interaction.member.guild.ownerId) {
await ManageChannels.create({
channelId: interaction.channelId,
})
await ManageChannels.create({
channelId: interaction.channelId,
})

const row = new ActionRowBuilder().addComponents(
new ButtonBuilder().setCustomId('verifyNFT').setLabel('Verify').setStyle(ButtonStyle.Primary)
)
const row = new ActionRowBuilder().addComponents(
new ButtonBuilder().setCustomId('verifyNFT').setLabel('Verify').setStyle(ButtonStyle.Primary)
)

const info = infoEmbed(
'Verify your ownership',
'Use a BIP-322 signature to prove that you own an inscription to receive a special holder role.'
)
const info = infoEmbed(
'Verify your ownership',
'Use a BIP-322 signature to prove that you own an inscription to receive a special holder role.'
)

await interaction.channel.send({
message: '',
components: [row],
embeds: [info],
})
await interaction.channel.send({
message: '',
components: [row],
embeds: [info],
})

const embed = successEmbed('Add verify bot', 'Successfully added the bot to this channel.')
const embed = successEmbed('Add verify bot', 'Successfully added the bot to this channel.')

return interaction.reply({
embeds: [embed],
ephemeral: true,
})
}
const embed = errorEmbed(COMMON_ERROR)
return interaction.reply({ embeds: [embed], ephemeral: true })
return interaction.reply({
embeds: [embed],
ephemeral: true,
})
} catch (error) {
if (error.name === 'SequelizeUniqueConstraintError') {
const embed = warningEmbed('Add verify bot', 'The bot is already in the channel.')
Expand Down
34 changes: 15 additions & 19 deletions commands/channel-check.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
const { SlashCommandBuilder } = require('discord.js')
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js')
const errorEmbed = require('../embed/error-embed')
const successEmbed = require('../embed/success-embed')
const warningEmbed = require('../embed/warning-embed')
const { COMMON_ERROR } = require('../embed/error-messages')
const ManageChannels = require('../db/manage-channels')

module.exports = {
data: new SlashCommandBuilder()
.setName('channel-check')
.setDescription('Check if the verify bot is available in this channel'),
.setDescription('Check if the verify bot is available in this channel')
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild),
async execute(interaction) {
try {
if (interaction.user.id === interaction.member.guild.ownerId) {
const channelId = await ManageChannels.findOne({
where: {
channelId: interaction.channelId,
},
})
if (channelId) {
const embed = successEmbed('Check channel', 'The bot is available in this channel.')
return interaction.reply({
embeds: [embed],
ephemeral: true,
})
}
const embed = warningEmbed('Check channel', 'The bot *is not available* in this channel.')
const channelId = await ManageChannels.findOne({
where: {
channelId: interaction.channelId,
},
})
if (channelId) {
const embed = successEmbed('Check channel', 'The bot is available in this channel.')
return interaction.reply({
embeds: [embed],
ephemeral: true,
})
}
const embed = errorEmbed(COMMON_ERROR)
return interaction.reply({ embeds: [embed], ephemeral: true })
const embed = warningEmbed('Check channel', 'The bot *is not available* in this channel.')
return interaction.reply({
embeds: [embed],
ephemeral: true,
})
} catch (error) {
const embed = errorEmbed(error)
return interaction.reply({ embeds: [embed], ephemeral: true })
Expand Down
31 changes: 14 additions & 17 deletions commands/channel-remove.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
const { SlashCommandBuilder } = require('discord.js')
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js')
const errorEmbed = require('../embed/error-embed')
const successEmbed = require('../embed/success-embed')
const warningEmbed = require('../embed/warning-embed')
const { COMMON_ERROR } = require('../embed/error-messages')
const ManageChannels = require('../db/manage-channels')

module.exports = {
data: new SlashCommandBuilder().setName('channel-remove').setDescription('Remove the verify bot from this channel'),
data: new SlashCommandBuilder()
.setName('channel-remove')
.setDescription('Remove the verify bot from this channel')
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild),
async execute(interaction) {
try {
if (interaction.user.id === interaction.member.guild.ownerId) {
const rowCount = await ManageChannels.destroy({
where: {
channelId: interaction.channelId,
},
})
if (!rowCount) {
const embed = warningEmbed('Remove Bot', "The bot doesn't exist in this channel.")
return interaction.reply({ embeds: [embed], ephemeral: true })
}

const embed = successEmbed('Removed Bot', 'The bot was removed from this channel.')

const rowCount = await ManageChannels.destroy({
where: {
channelId: interaction.channelId,
},
})
if (!rowCount) {
const embed = warningEmbed('Remove Bot', "The bot doesn't exist in this channel.")
return interaction.reply({ embeds: [embed], ephemeral: true })
}
const embed = errorEmbed(COMMON_ERROR)

const embed = successEmbed('Removed Bot', 'The bot was removed from this channel.')
return interaction.reply({ embeds: [embed], ephemeral: true })
} catch (error) {
const embed = errorEmbed(error)
Expand Down
14 changes: 11 additions & 3 deletions commands/collection-add.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
const { ActionRowBuilder, ModalBuilder, TextInputBuilder, TextInputStyle, SlashCommandBuilder } = require('discord.js')
const {
ActionRowBuilder,
ModalBuilder,
TextInputBuilder,
TextInputStyle,
SlashCommandBuilder,
PermissionFlagsBits,
} = require('discord.js')
const errorEmbed = require('../embed/error-embed')
const ManageChannels = require('../db/manage-channels')
const { COMMON_ERROR } = require('../embed/error-messages')
Expand All @@ -10,15 +17,16 @@ const INS_IDS_ID = 'insIds'
module.exports = {
data: new SlashCommandBuilder()
.setName('collection-add')
.setDescription('Manually add collection details and assign role'),
.setDescription('Manually add collection details and assign role')
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild),
async execute(interaction) {
try {
const channelId = await ManageChannels.findOne({
where: {
channelId: interaction.channelId,
},
})
if (interaction.user.id === interaction.member.guild.ownerId && channelId) {
if (channelId) {
const modal = new ModalBuilder().setCustomId(MODAL_ID).setTitle('Add Collection')

const nameInput = new TextInputBuilder()
Expand Down
17 changes: 14 additions & 3 deletions commands/collection-marketplace.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { SlashCommandBuilder } = require('discord.js')
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js')
const errorEmbed = require('../embed/error-embed')
const successEmbed = require('../embed/success-embed')
const warningEmbed = require('../embed/warning-embed')
Expand Down Expand Up @@ -60,15 +60,17 @@ module.exports = {
.addStringOption((option) => option.setName('link').setDescription('The link to the collection').setRequired(true))
.addStringOption((option) =>
option.setName('name').setDescription('Override the collection name').setRequired(false)
),
)
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild),

async execute(interaction) {
try {
const channelId = await ManageChannels.findOne({
where: {
channelId: interaction.channelId,
},
})
if (interaction.user.id === interaction.member.guild.ownerId && channelId) {
if (channelId) {
const venue = interaction.options.getString('venue')
const role = interaction.options.getRole('role')
const url = interaction.options.getString('link')
Expand Down Expand Up @@ -128,6 +130,15 @@ module.exports = {
offset,
collectionSymbol
)

// This usually happens if API is down or rate limit is hit
if (paginatedInscriptions.length === 0) {
const embed = errorEmbed('The marketplace api is not responding, it may be unavailable or rate limited.')
return interaction.editReply({
embeds: [embed],
ephemeral: true,
})
}
inscriptions.push(...paginatedInscriptions)
const embed = infoEmbed(
'Fetching Inscriptions',
Expand Down
10 changes: 7 additions & 3 deletions commands/collection-remove.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { SlashCommandBuilder, ActionRowBuilder, StringSelectMenuBuilder } = require('discord.js')
const { SlashCommandBuilder, ActionRowBuilder, StringSelectMenuBuilder, PermissionFlagsBits } = require('discord.js')
const errorEmbed = require('../embed/error-embed')
const successEmbed = require('../embed/success-embed')
const { Collections } = require('../db/collections-inscriptions')
Expand All @@ -8,15 +8,19 @@ const { COMMON_ERROR } = require('../embed/error-messages')
const REMOVE_COLLECTION_SELECTOR = 'removeCollectionSelector'

module.exports = {
data: new SlashCommandBuilder().setName('collection-remove').setDescription('Remove a collection from the server'),
data: new SlashCommandBuilder()
.setName('collection-remove')
.setDescription('Remove a collection from the server')
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild),

async execute(interaction) {
try {
const channelId = await ManageChannels.findOne({
where: {
channelId: interaction.channelId,
},
})
if (interaction.user.id === interaction.member.guild.ownerId && channelId) {
if (channelId) {
const collections = await Collections.findAll({
attributes: ['name', 'role', 'id'],
where: {
Expand Down
8 changes: 6 additions & 2 deletions commands/collection-view.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { SlashCommandBuilder } = require('discord.js')
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js')
const errorEmbed = require('../embed/error-embed')
const infoEmbed = require('../embed/info-embed')
const roleEmbed = require('../embed/role-embed')
Expand All @@ -7,7 +7,11 @@ const sequelize = require('../db/db-connect')
const commaNumber = require('comma-number')

module.exports = {
data: new SlashCommandBuilder().setName('collection-view').setDescription('View all collections'),
data: new SlashCommandBuilder()
.setName('collection-view')
.setDescription('View all collections')
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild),

async execute(interaction) {
try {
const collections = await Collections.findAll({
Expand Down
Loading

0 comments on commit adb0250

Please sign in to comment.