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

Commit

Permalink
feat: update announcement system
Browse files Browse the repository at this point in the history
  • Loading branch information
wdhdev committed Jun 27, 2023
1 parent 3182eb0 commit dcb74ea
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 54 deletions.
61 changes: 61 additions & 0 deletions src/buttons/announcements/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const announce = require("../../util/announcement");
const emoji = require("../../config.json").emojis;

const devSchema = require("../../models/devSchema");

module.exports = {
name: "create-announcement",
startsWith: false,
async execute(interaction, client, Discord) {
try {
const dev = await devSchema.exists({ _id: interaction.user.id });

if(!dev) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.error} You do not have permission to run this command!`)

await interaction.editReply({ embeds: [error], ephemeral: true });
return;
}

const modal = new Discord.ModalBuilder()
.setCustomId(`modal-${interaction.id}`)
.setTitle("Create Announcement")

const modalText = new Discord.TextInputBuilder()
.setCustomId(`modal-text-${interaction.id}`)
.setStyle(Discord.TextInputStyle.Paragraph)
.setLabel("Content")
.setMinLength(10)
.setMaxLength(1000)
.setRequired(true)

const row = new Discord.ActionRowBuilder().addComponents(modalText);

modal.addComponents(row);

await interaction.showModal(modal);

client.on("interactionCreate", async i => {
if(!i.isModalSubmit()) return;

if(i.customId === `modal-${interaction.id}`) {
const text = i.fields.getTextInputValue(`modal-text-${interaction.id}`);

await announce(text, interaction, client, Discord);

const sent = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
.setDescription(`${emoji.successful} The announcement has been sent!`)

await interaction.message.edit({ embeds: [sent], components: [], ephemeral: true });

await i.deferUpdate();
}
})
} catch(err) {
client.logButtonError(err, interaction, Discord);
}
}
}
30 changes: 15 additions & 15 deletions src/buttons/announcement.js → src/buttons/announcements/info.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module.exports = {
name: "announcement",
startsWith: false,
async execute(interaction, client, Discord) {
try {
const info = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
.setDescription("ℹ️ This is an official announcement made by the Global Chat Developers.")

await interaction.reply({ embeds: [info], ephemeral: true });
} catch(err) {
client.logButtonError(err, interaction, Discord);
}
}
}
module.exports = {
name: "announcement",
startsWith: false,
async execute(interaction, client, Discord) {
try {
const info = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
.setDescription("ℹ️ This is an official announcement made by the Global Chat Developers.")

await interaction.reply({ embeds: [info], ephemeral: true });
} catch(err) {
client.logButtonError(err, interaction, Discord);
}
}
}
4 changes: 2 additions & 2 deletions src/buttons/appeals/approve.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ module.exports = {
.setMaxLength(250)
.setRequired(true)

const actionRow = new Discord.ActionRowBuilder().addComponents(modalReason);
const row = new Discord.ActionRowBuilder().addComponents(modalReason);

modal.addComponents(actionRow);
modal.addComponents(row);

await interaction.showModal(modal);

Expand Down
4 changes: 2 additions & 2 deletions src/buttons/appeals/deny.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ module.exports = {
.setMaxLength(250)
.setRequired(true)

const actionRow = new Discord.ActionRowBuilder().addComponents(modalReason);
const row = new Discord.ActionRowBuilder().addComponents(modalReason);

modal.addComponents(actionRow);
modal.addComponents(row);

await interaction.showModal(modal);

Expand Down
4 changes: 2 additions & 2 deletions src/buttons/logs/ban.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ module.exports = {
.setMaxLength(250)
.setRequired(true)

const actionRow = new Discord.ActionRowBuilder().addComponents(modalReason);
const row = new Discord.ActionRowBuilder().addComponents(modalReason);

modal.addComponents(actionRow);
modal.addComponents(row);

await interaction.showModal(modal);

Expand Down
4 changes: 2 additions & 2 deletions src/buttons/suggestions/approve.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ module.exports = {
.setMaxLength(250)
.setRequired(true)

const actionRow = new Discord.ActionRowBuilder().addComponents(modalReason);
const row = new Discord.ActionRowBuilder().addComponents(modalReason);

modal.addComponents(actionRow);
modal.addComponents(row);

await interaction.showModal(modal);

Expand Down
4 changes: 2 additions & 2 deletions src/buttons/suggestions/deny.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ module.exports = {
.setMaxLength(250)
.setRequired(true)

const actionRow = new Discord.ActionRowBuilder().addComponents(modalReason);
const row = new Discord.ActionRowBuilder().addComponents(modalReason);

modal.addComponents(actionRow);
modal.addComponents(row);

await interaction.showModal(modal);

Expand Down
29 changes: 0 additions & 29 deletions src/commands/developer/admin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const announce = require("../../util/announcement");
const emoji = require("../../config.json").emojis;

const devSchema = require("../../models/devSchema");
Expand All @@ -10,21 +9,6 @@ module.exports = {
name: "admin",
description: "Admin Commands",
options: [
{
type: 1,
name: "announce",
description: "Send an announcement.",
options: [
{
type: 3,
name: "text",
description: "The text for the announcement to include.",
max_length: 1024,
required: true
}
]
},

{
type: 2,
name: "dev",
Expand Down Expand Up @@ -200,19 +184,6 @@ module.exports = {
return;
}

if(interaction.options.getSubcommand() === "announce") {
const text = interaction.options.getString("text");

await announce(text, interaction, client, Discord);

const sent = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
.setDescription(`${emoji.successful} The announcement has been sent!`)

await interaction.editReply({ embeds: [sent] });
return;
}

if(interaction.options.getSubcommandGroup() === "dev") {
const user = interaction.options.getUser("user");

Expand Down
40 changes: 40 additions & 0 deletions src/commands/developer/announcements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const emoji = require("../../config.json").emojis;

const devSchema = require("../../models/devSchema");

module.exports = {
name: "announcements",
description: "Manage the announcement system.",
options: [],
default_member_permissions: null,
botPermissions: [],
cooldown: 60,
enabled: true,
hidden: true,
async execute(interaction, client, Discord) {
try {
const dev = await devSchema.exists({ _id: interaction.user.id });

if(!dev) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.error} You do not have permission to run this command!`)

await interaction.editReply({ embeds: [error], ephemeral: true });
return;
}

const button = new Discord.ActionRowBuilder()
.addComponents (
new Discord.ButtonBuilder()
.setStyle(Discord.ButtonStyle.Success)
.setCustomId("create-announcement")
.setLabel("Create")
)

await interaction.editReply({ components: [button] });
} catch(err) {
client.logCommandError(err, interaction, Discord);
}
}
}

0 comments on commit dcb74ea

Please sign in to comment.