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 my brands #76

Merged
merged 5 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 74 additions & 9 deletions src/commands/developer/servers.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,19 @@ export default {
.setDescription('Show detailed server information')
.setRequired(false)
)
.addStringOption((option) =>
option
.setName('sort')
.setDescription('Sort servers by a specific criteria')
.setRequired(false)
.addChoices(
{ name: 'Name', value: 'name' },
{ name: 'Member Count', value: 'memberCount' },
{ name: 'Creation Date', value: 'createdAt' }
)
)
)

.addSubcommand((subcommand) =>
subcommand
.setName('leave')
Expand Down Expand Up @@ -110,7 +122,9 @@ export default {

async function handleListSubcommand(client, interaction) {
const isDetailed = interaction.options.getBoolean('detailed') ?? false;
const guilds = await Promise.all(
const sortOption = interaction.options.getString('sort') ?? 'name';

let guilds = await Promise.all(
client.guilds.cache.map(async (guild) => {
let inviteLink = 'No invite link available';
try {
Expand Down Expand Up @@ -144,6 +158,15 @@ async function handleListSubcommand(client, interaction) {
};
})
);
guilds.sort((a, b) => {
if (sortOption === 'memberCount') {
return b.memberCount - a.memberCount;
} else if (sortOption === 'createdAt') {
return b.createdAt - a.createdAt;
} else {
return a.name.localeCompare(b.name);
}
});

if (guilds.length === 0) {
return await interaction.editReply('The bot is not in any servers.');
Expand All @@ -153,20 +176,29 @@ async function handleListSubcommand(client, interaction) {
client,
interaction,
guilds,
isDetailed
isDetailed,
sortOption
);
await paginateEmbeds(interaction, embeds);
}

function createServerListEmbeds(client, interaction, guilds, isDetailed) {
function createServerListEmbeds(
client,
interaction,
guilds,
isDetailed,
sortOption
) {
const MAX_FIELDS = isDetailed ? 4 : 8;
const embeds = [];

for (let i = 0; i < guilds.length; i += MAX_FIELDS) {
const currentGuilds = guilds.slice(i, i + MAX_FIELDS);
const embed = new EmbedBuilder()
.setTitle('Servers List')
.setDescription(`The bot is in **${guilds.length}** servers.`)
.setDescription(
`The bot is in **${guilds.length}** servers. Sorted by: ${sortOption}`
)
.setColor(mconfig.embedColorSuccess)
.setThumbnail(client.user.displayAvatarURL())
.setFooter({
Expand Down Expand Up @@ -221,7 +253,6 @@ async function handleLeaveSubcommand(client, interaction) {
content: `Are you sure you want me to leave the server **${guild.name}** (ID: ${serverId})?`,
components: [row],
});

try {
const confirmation = await response.awaitMessageComponent({
filter: (i) => i.user.id === interaction.user.id,
Expand All @@ -242,7 +273,8 @@ async function handleLeaveSubcommand(client, interaction) {
}
} catch (error) {
await interaction.editReply({
content: 'No response received, cancelling server leave.',
content:
'No response received within 30 seconds, cancelling server leave.',
components: [],
});
throw error;
Expand All @@ -254,19 +286,52 @@ async function handleCheckSubcommand(client, interaction) {
.getString('server-ids')
.split(',')
.map((id) => id.trim());
if (serverIds.length > 10) {
return await interaction.editReply(
'Please provide 10 or fewer server IDs to check.'
);
}

const results = await Promise.all(
serverIds.map(async (serverId) => {
const guild = client.guilds.cache.get(serverId);
if (guild) {
const owner = await guild.fetchOwner();
return `The bot is in the server **${guild.name}** (ID: ${serverId}).\nOwner: ${owner.user.tag}\nMembers: ${guild.memberCount}`;
return new EmbedBuilder()
.setTitle(`Server Information: ${guild.name}`)
.setDescription(`The bot is in this server.`)
.addFields(
{ name: 'Server ID', value: serverId, inline: true },
{ name: 'Owner', value: owner.user.tag, inline: true },
{
name: 'Members',
value: guild.memberCount.toString(),
inline: true,
},
{
name: 'Created At',
value: guild.createdAt.toDateString(),
inline: true,
},
{
name: 'Boost Level',
value: guild.premiumTier.toString(),
inline: true,
}
)
.setColor(mconfig.embedColorSuccess);
} else {
return `The bot is not in a server with the ID ${serverId}.`;
return new EmbedBuilder()
.setTitle(`Server Not Found`)
.setDescription(
`The bot is not in a server with the ID ${serverId}.`
)
.setColor(mconfig.embedColorError);
}
})
);

await interaction.editReply(results.join('\n\n'));
await interaction.editReply({ embeds: results });
}

async function handleUserSubcommand(client, interaction) {
Expand Down
31 changes: 20 additions & 11 deletions src/commands/ticket/ticketSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@ export default {
.setRequired(true)
.addChannelTypes(ChannelType.GuildCategory)
)
.addRoleOption((option) =>
option
.setName('staff-role')
.setDescription('The role that will be able to see tickets.')
.setRequired(true)
)
.addChannelOption((option) =>
option
.setName('log-channel')
.setDescription('The channel where ticket logs will be sent')
.setRequired(true)
.addChannelTypes(ChannelType.GuildText)
)
.addRoleOption((option) =>
option
.setName('staff-role')
.setDescription('The role that will be able to see tickets.')
.setRequired(true)
)
.addStringOption((option) =>
option
.setName('ticket-type')
.setDescription('How tickets will be created')
.addChoices(
{ name: 'Modal', value: 'modal' },
{ name: 'Button', value: 'button' }
{ name: 'Select', value: 'select' }
)
.setRequired(true)
)
Expand Down Expand Up @@ -231,15 +231,16 @@ async function handleSetup(interaction) {

let component;

if (ticketType === 'button') {
if (ticketType === 'modal') {
component = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId('createTicket')
.setLabel('Open a ticket')
.setStyle(ButtonStyle.Primary)
.setEmoji('🎫')
);
} else {
}
else if(ticketType === 'select') {
component = new ActionRowBuilder().addComponents(
new StringSelectMenuBuilder()
.setCustomId('createTicket')
Expand All @@ -253,6 +254,9 @@ async function handleSetup(interaction) {
)
);
}
else{
return interaction.reply("Please select the correct")
}

const message = await ticketChannel.send({
embeds: [ticketCreateEmbed],
Expand Down Expand Up @@ -337,15 +341,16 @@ async function handleUpdate(interaction) {

let component;

if (setupTicket.ticketType === 'button') {
if (ticketType === 'modal') {
component = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId('createTicket')
.setLabel('Open a ticket')
.setStyle(ButtonStyle.Primary)
.setEmoji('🎫')
);
} else {
}
else if(ticketType === 'select') {
component = new ActionRowBuilder().addComponents(
new StringSelectMenuBuilder()
.setCustomId('createTicket')
Expand All @@ -359,6 +364,10 @@ async function handleUpdate(interaction) {
)
);
}
else{
return interaction.reply("Please select the correct")
}


await ticketMessage.edit({
embeds: [ticketCreateEmbed],
Expand Down