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

Update covid.js #430

Open
wants to merge 15 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);
},
};
25 changes: 20 additions & 5 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,11 @@ async function ticketModalSetup({ guild, channel, member }, targetChannel, setti
new ButtonBuilder().setLabel("Open a ticket").setCustomId("TICKET_CREATE").setStyle(ButtonStyle.Success)
);


// save configuration
settings.ticket.staff_roles = staffRoles;
await settings.save();

await targetChannel.send({ embeds: [embed], components: [tktBtnRow] });
await modal.deleteReply();
await sentMsg.edit({ content: "Done! Ticket Message Created", components: [] });
Expand Down
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
76 changes: 50 additions & 26 deletions src/handlers/ticket.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const { error } = require("@helpers/Logger");

const OPEN_PERMS = ["ManageChannels"];
const CLOSE_PERMS = ["ManageChannels", "ReadMessageHistory"];

/**
* @param {import('discord.js').Channel} channel
*/
Expand Down Expand Up @@ -76,7 +75,7 @@ async function closeTicket(channel, closedBy, reason) {

let content = "";
reversed.forEach((m) => {
content += `[${new Date(m.createdAt).toLocaleString("en-US")}] - ${m.author.username}\n`;
content += `[${new Date(m.createdAt).toLocaleString("en-US")}] - ${m.author.tag}\n`;
if (m.cleanContent !== "") content += `${m.cleanContent}\n`;
if (m.attachments.size > 0) content += `${m.attachments.map((att) => att.proxyURL).join(", ")}\n`;
content += "\n";
Expand All @@ -96,19 +95,19 @@ async function closeTicket(channel, closedBy, reason) {

if (channel.deletable) await channel.delete();

const embed = new EmbedBuilder().setAuthor({ name: "Ticket Closed" }).setColor(TICKET.CLOSE_EMBED);
const embed = new EmbedBuilder().setAuthor({ name: "Ticket Closed & deleted" }).setColor(TICKET.CLOSE_EMBED);
const fields = [];

if (reason) fields.push({ name: "Reason", value: reason, inline: false });
fields.push(
{
name: "Opened By",
value: ticketDetails.user ? ticketDetails.user.username : "Unknown",
value: ticketDetails.user ? ticketDetails.user.tag : "Unknown",
inline: true,
},
{
name: "Closed By",
value: closedBy ? closedBy.username : "Unknown",
value: closedBy ? closedBy.tag : "Unknown",
inline: true,
}
);
Expand Down Expand Up @@ -207,20 +206,34 @@ async function handleTicketOpen(interaction) {

try {
const ticketNumber = (existing + 1).toString();
const permissionOverwrites = [
{
id: guild.roles.everyone,
deny: ["ViewChannel"],
},
{
id: user.id,
allow: ["ViewChannel", "SendMessages", "ReadMessageHistory"],
},
{
id: guild.members.me.roles.highest.id,
allow: ["ViewChannel", "SendMessages", "ReadMessageHistory"],
},
];
const permissionOverwrites = [
{
id: guild.roles.everyone.id,
deny: ["ViewChannel"],
},
{
id: user.id,
allow: ["ViewChannel", "SendMessages", "ReadMessageHistory"],
},
];

// Get staff roles from settings
const staffRoles = settings.ticket?.staff_roles || [];


// Loop through each staff role ID
staffRoles.forEach(roleId => {
const role = guild.roles.cache.get(roleId);
if (role) {
permissionOverwrites.push({
id: role.id,
allow: ["ViewChannel", "SendMessages", "ReadMessageHistory"],
});
}
});




if (catPerms?.length > 0) {
catPerms?.forEach((roleId) => {
Expand All @@ -233,32 +246,43 @@ async function handleTicketOpen(interaction) {
});
}

const username = interaction.user.username;

const tktChannel = await guild.channels.create({
name: `tіcket-${ticketNumber}`,
name: `${username}-${ticketNumber}`,
type: ChannelType.GuildText,
topic: `tіcket|${user.id}|${catName || "Default"}`,
topic: `${username}|${user.id}|${catName || "Default"}`,
permissionOverwrites,
});


const staffRolesPing = staffRoles.map(roleId => `<@&${roleId}>`).join(' ');
const embed = new EmbedBuilder()
.setAuthor({ name: `Ticket #${ticketNumber}` })
.setDescription(
`Hello ${user.toString()}
Support will be with you shortly
${staffRolesPing} will be with you shortly
${catName ? `\n**Category:** ${catName}` : ""}
`
)
.setFooter({ text: "You may close your ticket anytime by clicking the button below" });

let buttonsRow = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setLabel("Close Ticket")
.setLabel("Close & delete Ticket")
.setCustomId("TICKET_CLOSE")
.setEmoji("🔒")
.setStyle(ButtonStyle.Primary)
);

const sent = await tktChannel.send({ content: user.toString(), embeds: [embed], components: [buttonsRow] });
// Ping staff roles if present
if (staffRoles.length > 0) {
const staffRolesPing = staffRoles.map(roleId => `<@&${roleId}>`).join(' ');
const messageContent = `**New ticket**\n${staffRolesPing}`;
await tktChannel.send({ content: messageContent, allowedMentions: { parse: ["everyone", "roles", "users"] } });
} else {
await tktChannel.send("**New ticket**");
}
const sent = await tktChannel.send({ content: user.toString(), embeds: [embed], components: [buttonsRow], allowedMentions: { parse: ["users"] } });

const dmEmbed = new EmbedBuilder()
.setColor(TICKET.CREATE_EMBED)
Expand All @@ -276,7 +300,7 @@ async function handleTicketOpen(interaction) {

user.send({ embeds: [dmEmbed], components: [row] }).catch((ex) => {});

await interaction.editReply(`Ticket created! 🔥`);
await interaction.editReply(`💯 Ticket created! in\n${tktChannel}`);
} catch (ex) {
error("handleTicketOpen", ex);
return interaction.editReply("Failed to create ticket channel, an error occurred!");
Expand Down