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

Commit

Permalink
quickfix
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonGamerBot-QK committed Feb 23, 2024
1 parent 10c806a commit 90ab674
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 224 deletions.
27 changes: 26 additions & 1 deletion commands/misc/tickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,20 @@ module.exports = {
.setDescription("The category to create tickets in")
.setRequired(true)
.addChannelTypes(ChannelType.GuildCategory),
),
)
.addChannelOption((option) =>
option
.setName("closecategory")
.setDescription("The category to where closed tickets are moved to")
.setRequired(true)
.addChannelTypes(ChannelType.GuildCategory),
)
.addRoleOption((option) => {
return option
.setName("supportrole")
.setDescription("Support Role")
.setRequired(true);
}),
)
.addSubcommand((subcommand) => {
return subcommand
Expand Down Expand Up @@ -271,6 +284,11 @@ module.exports = {
})
.addSubcommand((subcommand) => {
return subcommand.setName("unclaim").setDescription("Unclaim a ticket");
})
.addSubcommand((subcommand) => {
return subcommand
.setName("disable")
.setDescription("Disable ticket system");
}),
// last subcommand statemendt CTRL+F shortcut
async execute(interaction) {
Expand Down Expand Up @@ -766,6 +784,13 @@ module.exports = {
// catagory.id,
// );
ticketsDB.set("ticketCategory_" + interaction.guild.id, catagory.id);
const closeCatagory = interaction.options.getChannel("closecategory");
ticketsDB.set(
"closedTicketCategory_" + interaction.guild.id,
closeCatagory.id,
);
const supportRole = interaction.options.getRole("supportrole");
ticketsDB.set("supportRole_" + interaction.guild.id, supportRole.id);
await interaction.reply({
content: "Ticket system has been enabled",
empheral: true,
Expand Down
160 changes: 84 additions & 76 deletions commands/system/timeout.js
Original file line number Diff line number Diff line change
@@ -1,174 +1,182 @@
const { PermissionFlagsBits } = require('discord.js')
const { EmbedBuilder, SlashCommandBuilder } = require('@discordjs/builders')
const ms = require('ms')
const { Color } = require('discord-image-generation')
const { PermissionFlagsBits } = require("discord.js");
const { EmbedBuilder, SlashCommandBuilder } = require("@discordjs/builders");
const ms = require("ms");
// const { Color } = require('discord-image-generation')

module.exports = {
data: new SlashCommandBuilder()
.setName('timeout')
.setName("timeout")
.setDMPermission(false)
.setDescription('Timeout a user')
.setDescription("Timeout a user")
.addUserOption((option) =>
option
.setName('user')
.setDescription('The user you want to timeout')
.setRequired(true)
.setName("user")
.setDescription("The user you want to timeout")
.setRequired(true),
)
.addStringOption((option) =>
option
.setName('duration')
.setDescription('Duration of the timeout')
.setRequired(true)
.setName("duration")
.setDescription("Duration of the timeout")
.setRequired(true),
)
.addStringOption((option) =>
option
.setName('reason')
.setDescription('Reason for the timeout')
.setRequired(false)
.setName("reason")
.setDescription("Reason for the timeout")
.setRequired(false),
)
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers),

async execute(interaction) {
try {
await interaction.deferReply()
await interaction.deferReply();

const targetUserID = interaction.options.getUser('user')
const targetUser = await interaction.guild.members.fetch(targetUserID)
const duration = interaction.options.getString('duration')
const targetUserID = interaction.options.getUser("user");
const targetUser = await interaction.guild.members.fetch(targetUserID);
const duration = interaction.options.getString("duration");
const reason =
interaction.options.getString('reason') || 'No reason provided.'
interaction.options.getString("reason") || "No reason provided.";

const errEmbed = new EmbedBuilder().setTitle('ERROR').setColor(15548997)
const errEmbed = new EmbedBuilder().setTitle("ERROR").setColor(15548997);

if (!targetUser) {
errEmbed.setDescription(`Looks like that user isn't in this server`)
errEmbed.setDescription(`Looks like that user isn't in this server`);
await interaction.editReply({
embeds: [errEmbed],
})
return
});
return;
}

if (targetUser.bot) {
errEmbed.setDescription(`You cannot timeout a bot`)
errEmbed.setDescription(`You cannot timeout a bot`);
await interaction.editReply({
embeds: [errEmbed],
})
return
});
return;
}

if (targetUser.id == interaction.member.id) {
errEmbed.setDescription(`You cannot timeout yourself`)
errEmbed.setDescription(`You cannot timeout yourself`);
await interaction.editReply({
embeds: [errEmbed],
})
return
});
return;
}

if (targetUser.id === interaction.guild.ownerId) {
errEmbed.setDescription(
`You are not allowed to timeout that user. They are the server owner`
)
`You are not allowed to timeout that user. They are the server owner`,
);
await interaction.editReply({
embeds: [errEmbed],
})
return
});
return;
}

const msDuration = ms(duration)
const msDuration = ms(duration);
if (isNaN(msDuration)) {
errEmbed.setDescription(`Please provide a valid time duration`)
await interaction.editReply({ embeds: [errEmbed] })
return
errEmbed.setDescription(`Please provide a valid time duration`);
await interaction.editReply({ embeds: [errEmbed] });
return;
}

if (msDuration < 5000 || msDuration > 2419200000) {
errEmbed.setDescription(
`The timeout duration must be between 5 seconds and 28 days`
)
await interaction.editReply({ embeds: [errEmbed] })
return
`The timeout duration must be between 5 seconds and 28 days`,
);
await interaction.editReply({ embeds: [errEmbed] });
return;
}

const targetUserRolePosition = targetUser.roles.highest.position
const requestUserRolePosition = interaction.member.roles.highest.position
const targetUserRolePosition = targetUser.roles.highest.position;
const requestUserRolePosition = interaction.member.roles.highest.position;
const botRolePosition =
interaction.guild.members.me.roles.highest.position
interaction.guild.members.me.roles.highest.position;

if (targetUserRolePosition >= requestUserRolePosition) {
errEmbed.setDescription(
'You cannot timeout someone higher than or equal to you'
)
"You cannot timeout someone higher than or equal to you",
);
await interaction.editReply({
embeds: [errEmbed],
})
return
});
return;
}

if (targetUserRolePosition >= botRolePosition) {
errEmbed.setDescription(
'I cannot timeout someone higher than or equal to me'
)
"I cannot timeout someone higher than or equal to me",
);
await interaction.editReply({
embeds: [errEmbed],
})
return
});
return;
}

const { default: prettyMs } = await import('pretty-ms')
const { default: prettyMs } = await import("pretty-ms");
const embed = new EmbedBuilder().setColor(15548997).setFooter({
text: `Reason: ${reason}\nModerator: ${
interaction.user.username
}\nDuration: ${prettyMs(msDuration)}`,
})
});

const dmEmbed = new EmbedBuilder()
.setColor(15548997)
.setTitle(`You have been timed out!`)
.setDescription(
`Reason: ${reason}\nServer: ${
interaction.guild.name
}\nDuration: ${prettyMs(msDuration)}`
)
}\nDuration: ${prettyMs(msDuration)}`,
);

if (!targetUser.dmChannel) await targetUser.createDM()
if (!targetUser.dmChannel) await targetUser.createDM();

await targetUser.dmChannel.send({
embeds: [dmEmbed],
})
});

if (targetUser.isCommunicationDisabled()) {
await targetUser.timeout(msDuration, reason)
await targetUser.timeout(msDuration, reason);
await interaction.editReply({
content: `**${targetUser}'s timeout has been updated!**`,
embeds: [embed],
})
return
});
return;
}

if ((interaction.guild.roles.cache.find(role => role.name ==='muted')) === null) {
if (
interaction.guild.roles.cache.find((role) => role.name === "muted") ===
null
) {
await interaction.editReply({
content: `**There is no muted role in this server!**`,
embeds: [embed],
})
return
});
return;
}

await targetUser.roles.add(interaction.guild.roles.cache.find(role => role.name === 'muted'))
await targetUser.timeout(msDuration, reason)
await targetUser.roles.add(
interaction.guild.roles.cache.find((role) => role.name === "muted"),
);
await targetUser.timeout(msDuration, reason);
await interaction.editReply({
content: `**${targetUser} has been timed out!**`,
embeds: [embed],
})
});
await setTimeout(() => {
targetUser.roles.remove(interaction.guild.roles.cache.find(role => role.name ==='muted'))
targetUser.roles.remove(
interaction.guild.roles.cache.find((role) => role.name === "muted"),
);
}, msDuration);
} catch (error) {
await interaction.editReply('Oops! There was an error.').then((msg) => {
}
catch (error) {
await interaction.editReply("Oops! There was an error.").then((msg) => {
setTimeout(() => {
msg.delete()
}, 10000)
})
console.log(error)
msg.delete();
}, 10000);
});
console.log(error);
}
},
}
};
Loading

0 comments on commit 90ab674

Please sign in to comment.