Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

staff roles ping once ticket is open fix #501

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
129 changes: 129 additions & 0 deletions src/commands/admin/say.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
const {
EmbedBuilder,
ApplicationCommandOptionType,
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
ComponentType,
} = require("discord.js");

module.exports = {
name: "say",
description: "Says a message as the bot to a channel you choose",
category: "ADMIN",
botPermissions: ["SendMessages"],
userPermissions: ["ManageMessages"],
slashCommand: {
enabled: true,
ephemeral: true,
description: "Says a message as the bot to a channel you choose",
options: [
{
name: "message",
description: "The message to be sent.",
type: 3,
required: true,
},
{
name: "channel",
description: "The channel where the message will be sent.",
type: 7,
required: false,
},
{
name: "message_id",
description: "The ID of the message to edit or reply to.",
type: 3,
required: false,
},
{
name: "edit",
description: "Whether to edit the message specified by message_id instead of sending a new message.",
type: 5,
required: false,
},
{
name: "ping",
description: "Whether to ping everyone in the channel after sending the message.",
type: 5,
required: false,
},
],
},
async execute(interaction) {
const { options } = interaction;

// Retrieve the message content
const message = options.getString("message").replace(/\\n/g, '\n');

// Retrieve the channel where the message will be sent
const channel = options.getChannel("channel") || interaction.channel;

// Retrieve the message ID to edit or reply to
const message_id = options.getString("message_id");

// Retrieve whether to edit the message specified by message_id
const edit = options.getBoolean("edit");

// Retrieve whether to ping everyone in the channel after sending the message
const ping = options.getBoolean("ping");

try {
// If a message ID is provided, retrieve the message and edit or reply to it
if (message_id) {
const replyMessage = await channel.messages.fetch(message_id).catch(() => null);

if (!replyMessage) {
await interaction.followUp({ content: "Invalid message ID.", ephemeral: true });
}

if (edit) {
await replyMessage.edit(message);
} else {
await replyMessage.reply({ content: `${message}\n${ping ? "@everyone" : ""}`, allowedMentions: { parse: ["everyone", "roles", "users"] } });
}

// Send the final reply
await interaction.followUp({ content: edit ? "Message edited" : "Message sent", ephemeral: true });
} else {
// If no message ID is provided, send a new message
const taggedChannel = options.getChannel("channel");

if (taggedChannel) {
await taggedChannel.send({ content: message, allowedMentions: { parse: ["everyone", "roles", "users"] } });
if (ping) {
setTimeout(async () => {
await taggedChannel.send({ content: "@everyone", allowedMentions: { parse: ["everyone", "roles", "users"] } });
}, 2000); // wait 2 seconds before sending the second message
}
} else {
await interaction.channel.send({ content: message, allowedMentions: { parse: ["everyone", "roles", "users"] } });
if (ping) {
setTimeout(async () => {
await interaction.channel.send({ content: "@everyone", allowedMentions: { parse: ["everyone", "roles", "users"] } });
}, 2000); // wait 2 seconds before sending the second message
}
}


// Send the final reply
await interaction.followUp({ content: "Message sent", ephemeral: true });
}
} catch (error) {
console.error(error);
await interaction.followUp({ content: "An error occurred while processing this command.", ephemeral: true });
}
},

async messageRun(message, args, data) {
const replyEmbed = new EmbedBuilder()
.setTitle("Command Deprecated")
.setDescription("Please use the slash command instead.\n\n**Usage:** /say <message> [channel] [message_id] [edit] [ping]");

return message.reply({ embeds: [replyEmbed], ephemeral: true });
},

async interactionRun(interaction) {
await this.execute(interaction);
},
};
31 changes: 25 additions & 6 deletions src/commands/ticket/ticket.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const {
} = require("discord.js");
const { EMBED_COLORS } = require("@root/config.js");
const { isTicketChannel, closeTicket, closeAllTickets } = require("@handlers/ticket");

/**
* @type {import("@structures/Command")}
*/
Expand Down Expand Up @@ -276,7 +275,7 @@ async function ticketModalSetup({ guild, channel, member }, targetChannel, setti
);

const sentMsg = await channel.safeSend({
content: "Please click the button below to setup ticket message",
content: "Please click the button below to setup your ticket system!",
components: [buttonRow],
});

Expand All @@ -301,21 +300,28 @@ async function ticketModalSetup({ guild, channel, member }, targetChannel, setti
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId("title")
.setLabel("Embed Title")
.setLabel("ticket Title")
.setStyle(TextInputStyle.Short)
.setRequired(false)
),
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId("description")
.setLabel("Embed Description")
.setLabel("ticket Description")
.setStyle(TextInputStyle.Paragraph)
.setRequired(false)
),
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId("footer")
.setLabel("Embed Footer")
.setLabel("ticket Footer")
.setStyle(TextInputStyle.Short)
.setRequired(false)
),
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId("staff")
.setLabel("Staff Role (ID separate with ,)")
.setStyle(TextInputStyle.Short)
.setRequired(false)
),
Expand All @@ -337,6 +343,10 @@ async function ticketModalSetup({ guild, channel, member }, targetChannel, setti
const title = modal.fields.getTextInputValue("title");
const description = modal.fields.getTextInputValue("description");
const footer = modal.fields.getTextInputValue("footer");
const staffRoles = modal.fields
.getTextInputValue("staff")
.split(",")
.filter((s) => guild.roles.cache.has(s.trim()));

// send ticket message
const embed = new EmbedBuilder()
Expand All @@ -349,6 +359,15 @@ async function ticketModalSetup({ guild, channel, member }, targetChannel, setti
new ButtonBuilder().setLabel("Open a ticket").setCustomId("TICKET_CREATE").setStyle(ButtonStyle.Success)
);

const StaffRoles = require('@schemas/StaffRoles'); // Adjust the path as needed
// save configuration
// Save staff roles to the database
const staffRolesEntry = new StaffRoles({
guildId: guild.id,
roles: staffRoles
});
await staffRolesEntry.save();

await targetChannel.send({ embeds: [embed], components: [tktBtnRow] });
await modal.deleteReply();
await sentMsg.edit({ content: "Done! Ticket Message Created", components: [] });
Expand Down Expand Up @@ -414,4 +433,4 @@ async function removeFromTicket({ channel }, inputId) {
} catch (ex) {
return "Failed to remove user/role. Did you provide a valid ID?";
}
}
}
2 changes: 1 addition & 1 deletion src/commands/utility/covid.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {
};

async function getCovid(country) {
const response = await getJson(`https://disease.sh/v2/countries/${country}`);
const response = await getJson(`https://corona.lmao.ninja/v2/countries/${country}`);

if (response.status === 404) return "```css\nCountry with the provided name is not found```";
if (!response.success) return MESSAGES.API_ERROR;
Expand Down
6 changes: 4 additions & 2 deletions src/database/schemas/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const Schema = new mongoose.Schema({
staff_roles: [String],
},
],
staff_roles: [String], // Add this line
},
automod: {
debug: Boolean,
Expand Down Expand Up @@ -117,8 +118,9 @@ module.exports = {
* @param {import('discord.js').Guild} guild
*/
getSettings: async (guild) => {
if (!guild) throw new Error("Guild is undefined");
if (!guild.id) throw new Error("Guild Id is undefined");
if (!guild || !guild.id) {
throw new Error("Guild or Guild Id is undefined");
}

const cached = cache.get(guild.id);
if (cached) return cached;
Expand Down
12 changes: 12 additions & 0 deletions src/database/schemas/StaffRoles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// StaffRoles.js

const mongoose = require('mongoose');

const staffRolesSchema = new mongoose.Schema({
guildId: { type: String, required: true },
roles: { type: [String], default: [] }
});

const StaffRoles = mongoose.model('StaffRoles', staffRolesSchema);

module.exports = StaffRoles;
Loading