purge work and general fixes

pull/5/head
pineafan 4 years ago
parent 8b4b17f93e
commit 5d1908eea0
No known key found for this signature in database
GPG Key ID: 0BC8D3DCC20E96FE

@ -33,9 +33,10 @@ const callback = async (interaction: CommandInteraction) => {
// const pluralize = (word: string, count: number) => { return count === 1 ? word : word + "s" } // const pluralize = (word: string, count: number) => { return count === 1 ? word : word + "s" }
.send()) { .send()) {
let dmd = false let dmd = false
let dm;
try { try {
if (interaction.options.getString("notify") != "no") { if (interaction.options.getString("notify") != "no") {
await (interaction.options.getMember("user") as GuildMember).send({ dm = await (interaction.options.getMember("user") as GuildMember).send({
embeds: [new EmojiEmbed() embeds: [new EmojiEmbed()
.setEmoji("PUNISH.BAN.RED") .setEmoji("PUNISH.BAN.RED")
.setTitle("Banned") .setTitle("Banned")
@ -52,13 +53,6 @@ const callback = async (interaction: CommandInteraction) => {
days: Number(interaction.options.getInteger("delete") ?? 0), days: Number(interaction.options.getInteger("delete") ?? 0),
reason: interaction.options.getString("reason") ?? "No reason provided" reason: interaction.options.getString("reason") ?? "No reason provided"
}) })
let failed = (dmd == false && interaction.options.getString("notify") != "no")
await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji(`PUNISH.BAN.${failed ? "YELLOW" : "GREEN"}`)
.setTitle(`Ban`)
.setDescription("The member was banned" + (failed ? ", but could not be notified" : ""))
.setStatus(failed ? "Warning" : "Success")
], components: []})
} catch { } catch {
await interaction.editReply({embeds: [new EmojiEmbed() await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("PUNISH.BAN.RED") .setEmoji("PUNISH.BAN.RED")
@ -66,7 +60,16 @@ const callback = async (interaction: CommandInteraction) => {
.setDescription("Something went wrong and the user was not banned") .setDescription("Something went wrong and the user was not banned")
.setStatus("Danger") .setStatus("Danger")
], components: []}) ], components: []})
if (dmd) await dm.delete()
return
} }
let failed = (dmd == false && interaction.options.getString("notify") != "no")
await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji(`PUNISH.BAN.${failed ? "YELLOW" : "GREEN"}`)
.setTitle(`Ban`)
.setDescription("The member was banned" + (failed ? ", but could not be notified" : ""))
.setStatus(failed ? "Warning" : "Success")
], components: []})
} else { } else {
await interaction.editReply({embeds: [new EmojiEmbed() await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("PUNISH.BAN.GREEN") .setEmoji("PUNISH.BAN.GREEN")
@ -78,8 +81,15 @@ const callback = async (interaction: CommandInteraction) => {
} }
const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => { const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
let member = (interaction.member as GuildMember)
let me = (interaction.guild.me as GuildMember)
let apply = (interaction.options.getMember("user") as GuildMember)
if (member == null || me == null || apply == null) throw "That member is not in the server"
let memberPos = member.roles ? member.roles.highest.position : 0
let mePos = me.roles ? me.roles.highest.position : 0
let applyPos = apply.roles ? apply.roles.highest.position : 0
// Check if Nucleus can ban the member // Check if Nucleus can ban the member
if (! (interaction.guild.me.roles.highest.position > (interaction.member as GuildMember).roles.highest.position)) throw "I do not have a role higher than that member" if (! (mePos > applyPos)) throw "I do not have a role higher than that member"
// Check if Nucleus has permission to ban // Check if Nucleus has permission to ban
if (! interaction.guild.me.permissions.has("BAN_MEMBERS")) throw "I do not have the `ban_members` permission"; if (! interaction.guild.me.permissions.has("BAN_MEMBERS")) throw "I do not have the `ban_members` permission";
// Do not allow banning Nucleus // Do not allow banning Nucleus
@ -89,7 +99,7 @@ const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
// Check if the user has ban_members permission // Check if the user has ban_members permission
if (! (interaction.member as GuildMember).permissions.has("BAN_MEMBERS")) throw "You do not have the `ban_members` permission"; if (! (interaction.member as GuildMember).permissions.has("BAN_MEMBERS")) throw "You do not have the `ban_members` permission";
// Check if the user is below on the role list // Check if the user is below on the role list
if (! ((interaction.member as GuildMember).roles.highest.position > (interaction.options.getMember("user") as GuildMember).roles.highest.position)) throw "You do not have a role higher than that member" if (! (memberPos > applyPos)) throw "You do not have a role higher than that member"
// Allow ban // Allow ban
return true return true
} }

@ -31,9 +31,10 @@ const callback = async (interaction: CommandInteraction) => {
// const pluralize = (word: string, count: number) => { return count === 1 ? word : word + "s" } // const pluralize = (word: string, count: number) => { return count === 1 ? word : word + "s" }
.send()) { .send()) {
let dmd = false let dmd = false
let dm;
try { try {
if (interaction.options.getString("notify") != "no") { if (interaction.options.getString("notify") != "no") {
await (interaction.options.getMember("user") as GuildMember).send({ dm = await (interaction.options.getMember("user") as GuildMember).send({
embeds: [new EmojiEmbed() embeds: [new EmojiEmbed()
.setEmoji("PUNISH.KICK.RED") .setEmoji("PUNISH.KICK.RED")
.setTitle("Kicked") .setTitle("Kicked")
@ -47,13 +48,6 @@ const callback = async (interaction: CommandInteraction) => {
} catch {} } catch {}
try { try {
(interaction.options.getMember("user") as GuildMember).kick(interaction.options.getString("reason") ?? "No reason provided.") (interaction.options.getMember("user") as GuildMember).kick(interaction.options.getString("reason") ?? "No reason provided.")
let failed = (dmd == false && interaction.options.getString("notify") != "no")
await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji(`PUNISH.KICK.${failed ? "YELLOW" : "GREEN"}`)
.setTitle(`Kick`)
.setDescription("The member was kicked" + (failed ? ", but could not be notified" : ""))
.setStatus(failed ? "Warning" : "Success")
], components: []})
} catch { } catch {
await interaction.editReply({embeds: [new EmojiEmbed() await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("PUNISH.KICK.RED") .setEmoji("PUNISH.KICK.RED")
@ -61,7 +55,16 @@ const callback = async (interaction: CommandInteraction) => {
.setDescription("Something went wrong and the user was not kicked") .setDescription("Something went wrong and the user was not kicked")
.setStatus("Danger") .setStatus("Danger")
], components: []}) ], components: []})
if (dmd) await dm.delete()
return
} }
let failed = (dmd == false && interaction.options.getString("notify") != "no")
await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji(`PUNISH.KICK.${failed ? "YELLOW" : "GREEN"}`)
.setTitle(`Kick`)
.setDescription("The member was kicked" + (failed ? ", but could not be notified" : ""))
.setStatus(failed ? "Warning" : "Success")
], components: []})
} else { } else {
await interaction.editReply({embeds: [new EmojiEmbed() await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("PUNISH.KICK.GREEN") .setEmoji("PUNISH.KICK.GREEN")
@ -73,8 +76,15 @@ const callback = async (interaction: CommandInteraction) => {
} }
const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => { const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
let member = (interaction.member as GuildMember)
let me = (interaction.guild.me as GuildMember)
let apply = (interaction.options.getMember("user") as GuildMember)
if (member == null || me == null || apply == null) throw "That member is not in the server"
let memberPos = member.roles ? member.roles.highest.position : 0
let mePos = me.roles ? me.roles.highest.position : 0
let applyPos = apply.roles ? apply.roles.highest.position : 0
// Check if Nucleus can kick the member // Check if Nucleus can kick the member
if (! (interaction.guild.me.roles.highest.position > (interaction.member as GuildMember).roles.highest.position)) throw "I do not have a role higher than that member" if (! (mePos > applyPos)) throw "I do not have a role higher than that member"
// Check if Nucleus has permission to kick // Check if Nucleus has permission to kick
if (! interaction.guild.me.permissions.has("KICK_MEMBERS")) throw "I do not have the `kick_members` permission"; if (! interaction.guild.me.permissions.has("KICK_MEMBERS")) throw "I do not have the `kick_members` permission";
// Do not allow kicking Nucleus // Do not allow kicking Nucleus
@ -84,7 +94,7 @@ const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
// Check if the user has kick_members permission // Check if the user has kick_members permission
if (! (interaction.member as GuildMember).permissions.has("KICK_MEMBERS")) throw "You do not have the `kick_members` permission"; if (! (interaction.member as GuildMember).permissions.has("KICK_MEMBERS")) throw "You do not have the `kick_members` permission";
// Check if the user is below on the role list // Check if the user is below on the role list
if (! ((interaction.member as GuildMember).roles.highest.position > (interaction.options.getMember("user") as GuildMember).roles.highest.position)) throw "You do not have a role higher than that member" if (! (memberPos > applyPos)) throw "You do not have a role higher than that member"
// Allow kick // Allow kick
return true return true
} }

@ -17,7 +17,8 @@ const command = (builder: SlashCommandSubcommandBuilder) =>
.addIntegerOption(option => option.setName("minutes").setDescription("The number of minutes to mute the user for | Default 0").setMinValue(0).setMaxValue(59).setRequired(false)) .addIntegerOption(option => option.setName("minutes").setDescription("The number of minutes to mute the user for | Default 0").setMinValue(0).setMaxValue(59).setRequired(false))
.addIntegerOption(option => option.setName("seconds").setDescription("The number of seconds to mute the user for | Default 0").setMinValue(0).setMaxValue(59).setRequired(false)) .addIntegerOption(option => option.setName("seconds").setDescription("The number of seconds to mute the user for | Default 0").setMinValue(0).setMaxValue(59).setRequired(false))
.addStringOption(option => option.setName("reason").setDescription("The reason for the mute").setRequired(false)) .addStringOption(option => option.setName("reason").setDescription("The reason for the mute").setRequired(false))
.addStringOption(option => option.setName("notify").setDescription("The user to notify they have been muted").setRequired(false)) .addStringOption(option => option.setName("notify").setDescription("If the user should get a message when they are kicked | Default yes").setRequired(false)
.addChoices([["Yes", "yes"], ["No", "no"]]))
// TODO: notify the user when the mute is lifted // TODO: notify the user when the mute is lifted
const callback = async (interaction: CommandInteraction) => { const callback = async (interaction: CommandInteraction) => {
@ -112,13 +113,14 @@ const callback = async (interaction: CommandInteraction) => {
.setStatus("Success") .setStatus("Success")
], ephemeral: true, fetchReply: true}) ], ephemeral: true, fetchReply: true})
} }
// TODO:[Modals] Replace this with a modal
if (await new confirmationMessage(interaction) if (await new confirmationMessage(interaction)
.setEmoji("PUNISH.MUTE.RED") .setEmoji("PUNISH.MUTE.RED")
.setTitle("Mute") .setTitle("Mute")
.setDescription(keyValueList({ .setDescription(keyValueList({
"user": `<@!${user.id}> (${user.user.username})`, "user": `<@!${user.id}> (${user.user.username})`,
"time": `${humanizeDuration(muteTime * 1000, {round: true})}`, "time": `${humanizeDuration(muteTime * 1000, {round: true})}`,
"reason": `\n> ${interaction.options.getString("reason") ? interaction.options.getString("reason") : "*No reason provided*"}` "reason": `\n> ${reason ? reason : "*No reason provided*"}`
}) })
+ `The user **will${interaction.options.getString("notify") === "no" ? ' not' : ''}** be notified\n\n` + `The user **will${interaction.options.getString("notify") === "no" ? ' not' : ''}** be notified\n\n`
+ `Are you sure you want to mute <@!${(interaction.options.getMember("user") as GuildMember).id}>?`) + `Are you sure you want to mute <@!${(interaction.options.getMember("user") as GuildMember).id}>?`)
@ -127,9 +129,10 @@ const callback = async (interaction: CommandInteraction) => {
// const pluralize = (word: string, count: number) => { return count === 1 ? word : word + "s" } // const pluralize = (word: string, count: number) => { return count === 1 ? word : word + "s" }
.send(true)) { .send(true)) {
let dmd = false let dmd = false
let dm;
try { try {
if (interaction.options.getString("notify") != "no") { if (interaction.options.getString("notify") != "no") {
await (interaction.options.getMember("user") as GuildMember).send({ dm = await (interaction.options.getMember("user") as GuildMember).send({
embeds: [new EmojiEmbed() embeds: [new EmojiEmbed()
.setEmoji("PUNISH.MUTE.RED") .setEmoji("PUNISH.MUTE.RED")
.setTitle("Muted") .setTitle("Muted")
@ -144,13 +147,6 @@ const callback = async (interaction: CommandInteraction) => {
} catch {} } catch {}
try { try {
(interaction.options.getMember("user") as GuildMember).timeout(muteTime * 1000, interaction.options.getString("reason") || "No reason provided") (interaction.options.getMember("user") as GuildMember).timeout(muteTime * 1000, interaction.options.getString("reason") || "No reason provided")
let failed = (dmd == false && interaction.options.getString("notify") != "no")
await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji(`PUNISH.MUTE.${failed ? "YELLOW" : "GREEN"}`)
.setTitle(`Mute`)
.setDescription("The member was muted" + (failed ? ", but could not be notified" : ""))
.setStatus(failed ? "Warning" : "Success")
], components: []})
} catch { } catch {
await interaction.editReply({embeds: [new EmojiEmbed() await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("PUNISH.MUTE.RED") .setEmoji("PUNISH.MUTE.RED")
@ -158,7 +154,16 @@ const callback = async (interaction: CommandInteraction) => {
.setDescription("Something went wrong and the user was not kicked") .setDescription("Something went wrong and the user was not kicked")
.setStatus("Danger") .setStatus("Danger")
], components: []}) ], components: []})
if (dmd) await dm.delete()
return
} }
let failed = (dmd == false && interaction.options.getString("notify") != "no")
await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji(`PUNISH.MUTE.${failed ? "YELLOW" : "GREEN"}`)
.setTitle(`Mute`)
.setDescription("The member was muted" + (failed ? ", but could not be notified" : ""))
.setStatus(failed ? "Warning" : "Success")
], components: []})
} else { } else {
await interaction.editReply({embeds: [new EmojiEmbed() await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("PUNISH.MUTE.GREEN") .setEmoji("PUNISH.MUTE.GREEN")
@ -170,8 +175,15 @@ const callback = async (interaction: CommandInteraction) => {
} }
const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => { const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
let member = (interaction.member as GuildMember)
let me = (interaction.guild.me as GuildMember)
let apply = (interaction.options.getMember("user") as GuildMember)
if (member == null || me == null || apply == null) throw "That member is not in the server"
let memberPos = member.roles ? member.roles.highest.position : 0
let mePos = me.roles ? me.roles.highest.position : 0
let applyPos = apply.roles ? apply.roles.highest.position : 0
// Check if Nucleus can mute the member // Check if Nucleus can mute the member
if (! (interaction.guild.me.roles.highest.position > (interaction.member as GuildMember).roles.highest.position)) throw "I do not have a role higher than that member" if (! (mePos > applyPos)) throw "I do not have a role higher than that member"
// Check if Nucleus has permission to mute // Check if Nucleus has permission to mute
if (! interaction.guild.me.permissions.has("MODERATE_MEMBERS")) throw "I do not have the `moderate_members` permission"; if (! interaction.guild.me.permissions.has("MODERATE_MEMBERS")) throw "I do not have the `moderate_members` permission";
// Do not allow the user to have admin or be the owner // Do not allow the user to have admin or be the owner
@ -183,7 +195,7 @@ const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
// Check if the user has moderate_members permission // Check if the user has moderate_members permission
if (! (interaction.member as GuildMember).permissions.has("MODERATE_MEMBERS")) throw "You do not have the `moderate_members` permission"; if (! (interaction.member as GuildMember).permissions.has("MODERATE_MEMBERS")) throw "You do not have the `moderate_members` permission";
// Check if the user is below on the role list // Check if the user is below on the role list
if (! ((interaction.member as GuildMember).roles.highest.position > (interaction.options.getMember("user") as GuildMember).roles.highest.position)) throw "You do not have a role higher than that member" if (! (memberPos > applyPos)) throw "You do not have a role higher than that member"
// Allow mute // Allow mute
return true return true
} }

@ -21,6 +21,7 @@ const command = (builder: SlashCommandSubcommandBuilder) =>
.addStringOption(option => option.setName("reason").setDescription("The reason for the purge").setRequired(false)) .addStringOption(option => option.setName("reason").setDescription("The reason for the purge").setRequired(false))
const callback = async (interaction: CommandInteraction) => { const callback = async (interaction: CommandInteraction) => {
let user = interaction.options.getMember("user") as GuildMember ?? null
let channel = (interaction.options.getChannel("channel") as GuildChannel) ?? interaction.channel let channel = (interaction.options.getChannel("channel") as GuildChannel) ?? interaction.channel
let thischannel let thischannel
if ((interaction.options.getChannel("channel") as GuildChannel) == null) { if ((interaction.options.getChannel("channel") as GuildChannel) == null) {
@ -55,7 +56,7 @@ const callback = async (interaction: CommandInteraction) => {
ephemeral: true, ephemeral: true,
fetchReply: true fetchReply: true
}) })
let deleted = [] let deleted = [] as Discord.Message[]
while (true) { while (true) {
let m = await interaction.editReply({ let m = await interaction.editReply({
embeds: [ embeds: [
@ -111,7 +112,15 @@ const callback = async (interaction: CommandInteraction) => {
if (component.customId === "done") break; if (component.customId === "done") break;
let amount; let amount;
try { amount = parseInt(component.customId); } catch { break; } try { amount = parseInt(component.customId); } catch { break; }
await (channel as TextChannel).bulkDelete(amount, true); // TODO: Add to deleted list | TODO: Support for users let messages;
(interaction.channel as TextChannel).messages.fetch({limit: amount}).then(async (ms) => {
if (user) {
ms = ms.filter(m => m.author.id === user.id)
}
messages = await (channel as TextChannel).bulkDelete(ms, true);
})
deleted = deleted.concat(messages.map(m => m)) // TODO: .values doesnt work so using .map
// TODO: Support for users
} }
if (deleted.length === 0) return await interaction.editReply({ if (deleted.length === 0) return await interaction.editReply({
embeds: [ embeds: [
@ -123,16 +132,53 @@ const callback = async (interaction: CommandInteraction) => {
], ],
components: [] components: []
}) })
return await interaction.editReply({ let attachmentObject;
embeds: [ try {
new EmojiEmbed() let out = ""
.setEmoji("CHANNEL.PURGE.GREEN") deleted.reverse().forEach(message => {
.setTitle("Purge") out += `${message.author.username}#${message.author.discriminator} (${message.author.id}) [${new Date(message.createdTimestamp).toISOString()}]\n`
.setDescription(`Deleted ${deleted.length} messages`) let lines = message.content.split("\n")
.setStatus("Success") lines.forEach(line => {out += `> ${line}\n`})
], out += `\n\n`
components: [] })
}) attachmentObject = {
attachment: Buffer.from(out),
name: `purge-${channel.id}-${Date.now()}.txt`,
description: "Purge log"
}
} catch {}
let m = await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji(`CHANNEL.PURGE.GREEN`)
.setTitle(`Purge`)
.setDescription("Messages cleared")
.setStatus("Success")
], components: [new Discord.MessageActionRow().addComponents([
new Discord.MessageButton()
.setCustomId("download")
.setLabel("Download transcript")
.setStyle("SUCCESS")
.setEmoji(getEmojiByName("CONTROL.DOWNLOAD", "id"))
])]})
let component;
try {
component = await (m as Discord.Message).awaitMessageComponent({filter: (m) => m.user.id === interaction.user.id, time: 2.5 * 60 * 1000});
} catch {}
if (component && component.customId === "download") {
interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("CHANNEL.PURGE.GREEN")
.setTitle(`Purge`)
.setDescription("Uploaded")
.setStatus("Success")
], components: [], files: [attachmentObject]})
} else {
interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("CHANNEL.PURGE.GREEN")
.setTitle(`Purge`)
.setDescription("Messages cleared")
.setStatus("Success")
], components: []})
}
return
} else { } else {
if (await new confirmationMessage(interaction) if (await new confirmationMessage(interaction)
.setEmoji("CHANNEL.PURGE.RED") .setEmoji("CHANNEL.PURGE.RED")
@ -146,27 +192,67 @@ const callback = async (interaction: CommandInteraction) => {
// pluralize("day", interaction.options.getInteger("amount")) // pluralize("day", interaction.options.getInteger("amount"))
// const pluralize = (word: string, count: number) => { return count === 1 ? word : word + "s" } // const pluralize = (word: string, count: number) => { return count === 1 ? word : word + "s" }
.send()) { .send()) {
let messages;
try {
(interaction.channel as TextChannel).messages.fetch({limit: interaction.options.getInteger("amount")}).then(async (ms) => {
if (user) {
ms = ms.filter(m => m.author.id === user.id)
}
messages = await (channel as TextChannel).bulkDelete(ms, true);
}) // TODO: fix for purge amount by user, not just checking x
} catch(e) {
console.log(e)
await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("CHANNEL.PURGE.RED")
.setTitle(`Purge`)
.setDescription("Something went wrong and no messages were deleted")
.setStatus("Danger")
], components: []})
}
let attachmentObject;
try { try {
let messages = await (channel as TextChannel).bulkDelete(interaction.options.getInteger("amount"), true) // TODO: Support for users
let out = "" let out = ""
messages.reverse().forEach(message => { messages.reverse().forEach(message => {
out += `${message.author.username}#${message.author.discriminator} (${message.author.id})\n` out += `${message.author.username}#${message.author.discriminator} (${message.author.id}) [${new Date(message.createdTimestamp).toISOString()}]\n`
let lines = message.content.split("\n") let lines = message.content.split("\n")
lines.forEach(line => {out += `> ${line}\n`}) // TODO: Humanize timestamp lines.forEach(line => {out += `> ${line}\n`})
out += `\n\n` out += `\n\n`
}) // TODO: Upload as file })
await interaction.editReply({embeds: [new EmojiEmbed() attachmentObject = {
.setEmoji(`CHANNEL.PURGE.GREEN`) attachment: Buffer.from(out),
name: `purge-${channel.id}-${Date.now()}.txt`,
description: `Purge log`
}
} catch {}
let m = await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji(`CHANNEL.PURGE.GREEN`)
.setTitle(`Purge`)
.setDescription("Messages cleared")
.setStatus("Success")
], components: [new Discord.MessageActionRow().addComponents([
new Discord.MessageButton()
.setCustomId("download")
.setLabel("Download transcript")
.setStyle("SUCCESS")
.setEmoji(getEmojiByName("CONTROL.DOWNLOAD", "id"))
])]})
let component;
try {
component = await (m as Discord.Message).awaitMessageComponent({filter: (m) => m.user.id === interaction.user.id, time: 2.5 * 60 * 1000});
} catch {}
if (component && component.customId === "download") {
interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("CHANNEL.PURGE.GREEN")
.setTitle(`Purge`) .setTitle(`Purge`)
.setDescription("Messages cleared") .setDescription("Uploaded")
.setStatus("Success") .setStatus("Success")
], components: []}) ], components: [], files: [attachmentObject]})
} catch { } else {
await interaction.editReply({embeds: [new EmojiEmbed() interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("CHANNEL.PURGE.RED") .setEmoji("CHANNEL.PURGE.GREEN")
.setTitle(`Purge`) .setTitle(`Purge`)
.setDescription("Something went wrong and no messages were deleted") .setDescription("Messages cleared")
.setStatus("Danger") .setStatus("Success")
], components: []}) ], components: []})
} }
} else { } else {

@ -38,8 +38,8 @@ const callback = async (interaction: CommandInteraction) => {
await (interaction.options.getMember("user") as GuildMember).send({ await (interaction.options.getMember("user") as GuildMember).send({
embeds: [new EmojiEmbed() embeds: [new EmojiEmbed()
.setEmoji("PUNISH.BAN.RED") .setEmoji("PUNISH.BAN.RED")
.setTitle("Kick") .setTitle("Softbanned")
.setDescription(`You have been kicked from ${interaction.guild.name}` + .setDescription(`You have been softbanned from ${interaction.guild.name}` +
(interaction.options.getString("reason") ? ` for:\n> ${interaction.options.getString("reason")}` : " with no reason provided.")) (interaction.options.getString("reason") ? ` for:\n> ${interaction.options.getString("reason")}` : " with no reason provided."))
.setStatus("Danger") .setStatus("Danger")
] ]
@ -48,17 +48,11 @@ const callback = async (interaction: CommandInteraction) => {
} }
} catch {} } catch {}
try { try {
(interaction.options.getMember("user") as GuildMember).ban({ await (interaction.options.getMember("user") as GuildMember).ban({
days: Number(interaction.options.getInteger("delete") ?? 0), days: Number(interaction.options.getInteger("delete") ?? 0),
reason: interaction.options.getString("reason") reason: interaction.options.getString("reason")
}) // TODO: unban here });
let failed = (dmd == false && interaction.options.getString("notify") != "no") await interaction.guild.members.unban(interaction.options.getMember("user") as GuildMember, "Softban");
await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji(`PUNISH.BAN.${failed ? "YELLOW" : "GREEN"}`)
.setTitle(`Softban`)
.setDescription("The member was softbanned" + (failed ? ", but could not be notified" : ""))
.setStatus(failed ? "Warning" : "Success")
], components: []})
} catch { } catch {
await interaction.editReply({embeds: [new EmojiEmbed() await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("PUNISH.BAN.RED") .setEmoji("PUNISH.BAN.RED")
@ -67,6 +61,13 @@ const callback = async (interaction: CommandInteraction) => {
.setStatus("Danger") .setStatus("Danger")
], components: []}) ], components: []})
} }
let failed = (dmd == false && interaction.options.getString("notify") != "no")
await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji(`PUNISH.BAN.${failed ? "YELLOW" : "GREEN"}`)
.setTitle(`Softban`)
.setDescription("The member was softbanned" + (failed ? ", but could not be notified" : ""))
.setStatus(failed ? "Warning" : "Success")
], components: []})
} else { } else {
await interaction.editReply({embeds: [new EmojiEmbed() await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("PUNISH.BAN.GREEN") .setEmoji("PUNISH.BAN.GREEN")
@ -78,8 +79,15 @@ const callback = async (interaction: CommandInteraction) => {
} }
const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => { const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
let member = (interaction.member as GuildMember)
let me = (interaction.guild.me as GuildMember)
let apply = (interaction.options.getMember("user") as GuildMember)
if (member == null || me == null || apply == null) throw "That member is not in the server"
let memberPos = member.roles ? member.roles.highest.position : 0
let mePos = me.roles ? me.roles.highest.position : 0
let applyPos = apply.roles ? apply.roles.highest.position : 0
// Check if Nucleus can ban the member // Check if Nucleus can ban the member
if (! (interaction.guild.me.roles.highest.position > (interaction.member as GuildMember).roles.highest.position)) throw "I do not have a role higher than that member" if (! (mePos > applyPos)) throw "I do not have a role higher than that member"
// Check if Nucleus has permission to ban // Check if Nucleus has permission to ban
if (! interaction.guild.me.permissions.has("BAN_MEMBERS")) throw "I do not have the `ban_members` permission"; if (! interaction.guild.me.permissions.has("BAN_MEMBERS")) throw "I do not have the `ban_members` permission";
// Do not allow softbanning Nucleus // Do not allow softbanning Nucleus
@ -89,7 +97,7 @@ const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
// Check if the user has ban_members permission // Check if the user has ban_members permission
if (! (interaction.member as GuildMember).permissions.has("BAN_MEMBERS")) throw "You do not have the `ban_members` permission"; if (! (interaction.member as GuildMember).permissions.has("BAN_MEMBERS")) throw "You do not have the `ban_members` permission";
// Check if the user is below on the role list // Check if the user is below on the role list
if (! ((interaction.member as GuildMember).roles.highest.position > (interaction.options.getMember("user") as GuildMember).roles.highest.position)) throw "You do not have a role higher than that member" if (! (memberPos > applyPos)) throw "You do not have a role higher than that member"
// Allow softban // Allow softban
return true return true
} }

@ -1,18 +1,102 @@
import { CommandInteraction } from "discord.js"; import { CommandInteraction, GuildMember } from "discord.js";
import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import { WrappedCheck } from "jshaiku"; import { WrappedCheck } from "jshaiku";
import confirmationMessage from "../../utils/confirmationMessage.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import keyValueList from "../../utils/generateKeyValueList.js";
const command = (builder: SlashCommandSubcommandBuilder) => const command = (builder: SlashCommandSubcommandBuilder) =>
builder builder
.setName("unmute") .setName("unmute")
.setDescription("Unmutes a member") .setDescription("Unmutes a user")
.addUserOption(option => option.setName("user").setDescription("The user to unmute").setRequired(true))
.addStringOption(option => option.setName("reason").setDescription("The reason for the unmute").setRequired(false))
.addStringOption(option => option.setName("notify").setDescription("If the user should get a message when they are unmuted | Default no").setRequired(false)
.addChoices([["Yes", "yes"], ["No", "no"]])
)
const callback = (interaction: CommandInteraction) => { const callback = async (interaction: CommandInteraction) => {
interaction.reply("Command incomplete [mod/unmute]"); // TODO:[Modals] Replace this with a modal
if (await new confirmationMessage(interaction)
.setEmoji("PUNISH.MUTE.RED")
.setTitle("Unmute")
.setDescription(keyValueList({
"user": `<@!${(interaction.options.getMember("user") as GuildMember).id}> (${(interaction.options.getMember("user") as GuildMember).user.username})`,
"reason": `\n> ${interaction.options.getString("reason") ? interaction.options.getString("reason") : "*No reason provided*"}`
})
+ `The user **will${interaction.options.getString("notify") === "yes" ? '' : ' not'}** be notified\n\n`
+ `Are you sure you want to unmute <@!${(interaction.options.getMember("user") as GuildMember).id}>?`)
.setColor("Danger")
// pluralize("day", interaction.options.getInteger("delete"))
// const pluralize = (word: string, count: number) => { return count === 1 ? word : word + "s" }
.send()) {
let dmd = false
let dm;
try {
if (interaction.options.getString("notify") != "no") {
dm = await (interaction.options.getMember("user") as GuildMember).send({
embeds: [new EmojiEmbed()
.setEmoji("PUNISH.MUTE.GREEN")
.setTitle("Unmuted")
.setDescription(`You have been unmuted in ${interaction.guild.name}` +
(interaction.options.getString("reason") ? ` for:\n> ${interaction.options.getString("reason")}` : " with no reason provided."))
.setStatus("Success")
]
})
dmd = true
}
} catch {}
try {
(interaction.options.getMember("user") as GuildMember).timeout(0, interaction.options.getString("reason") || "No reason provided")
} catch {
await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("PUNISH.MUTE.RED")
.setTitle(`Unmute`)
.setDescription("Something went wrong and the user was not unmuted")
.setStatus("Danger")
], components: []})
if (dmd) await dm.delete()
return
}
let failed = (dmd == false && interaction.options.getString("notify") != "no")
await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji(`PUNISH.MUTE.${failed ? "YELLOW" : "GREEN"}`)
.setTitle(`Unmute`)
.setDescription("The member was unmuted" + (failed ? ", but could not be notified" : ""))
.setStatus(failed ? "Warning" : "Success")
], components: []})
} else {
await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("PUNISH.MUTE.GREEN")
.setTitle(`Unmute`)
.setDescription("No changes were made")
.setStatus("Success")
], components: []})
}
} }
const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => { const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
return true; let member = (interaction.member as GuildMember)
let me = (interaction.guild.me as GuildMember)
let apply = (interaction.options.getMember("user") as GuildMember)
if (member == null || me == null || apply == null) throw "That member is not in the server"
let memberPos = member.roles ? member.roles.highest.position : 0
let mePos = me.roles ? me.roles.highest.position : 0
let applyPos = apply.roles ? apply.roles.highest.position : 0
// Check if Nucleus can unmute the member
if (! (mePos > applyPos)) throw "I do not have a role higher than that member"
// Check if Nucleus has permission to unmute
if (! interaction.guild.me.permissions.has("MODERATE_MEMBERS")) throw "I do not have the `moderate_members` permission";
// Do not allow the user to have admin or be the owner
if ((interaction.options.getMember("user") as GuildMember).permissions.has("ADMINISTRATOR") || (interaction.options.getMember("user") as GuildMember).id == interaction.guild.ownerId) throw "You cannot unmute an admin or the owner"
// Allow the owner to unmute anyone
if ((interaction.member as GuildMember).id == interaction.guild.ownerId) return true
// Check if the user has moderate_members permission
if (! (interaction.member as GuildMember).permissions.has("MODERATE_MEMBERS")) throw "You do not have the `moderate_members` permission";
// Check if the user is below on the role list
if (! (memberPos > applyPos)) throw "You do not have a role higher than that member"
// Allow unmute
return true
} }
export { command, callback, check }; export { command, callback, check };

@ -1,4 +1,4 @@
import { CommandInteraction, GuildMember } from "discord.js"; import Discord, { CommandInteraction, GuildMember, MessageActionRow } from "discord.js";
import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import { WrappedCheck } from "jshaiku"; import { WrappedCheck } from "jshaiku";
import confirmationMessage from "../../utils/confirmationMessage.js"; import confirmationMessage from "../../utils/confirmationMessage.js";
@ -43,15 +43,6 @@ const callback = async (interaction: CommandInteraction) => {
}) })
dmd = true dmd = true
} }
} catch {}
try {
let failed = (dmd == false && interaction.options.getString("notify") != "no") // TODO: some way of dealing with not DMing users
await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji(`PUNISH.WARN.${failed ? "YELLOW" : "GREEN"}`)
.setTitle(`Warn`)
.setDescription(failed ? "The user cannot be messaged and was not warned" : "The user was warned")
.setStatus(failed ? "Warning" : "Success")
], components: []})
} catch { } catch {
await interaction.editReply({embeds: [new EmojiEmbed() await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("PUNISH.WARN.RED") .setEmoji("PUNISH.WARN.RED")
@ -60,6 +51,73 @@ const callback = async (interaction: CommandInteraction) => {
.setStatus("Danger") .setStatus("Danger")
], components: []}) ], components: []})
} }
let failed = (dmd == false && interaction.options.getString("notify") != "no")
if (!failed) {
await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji(`PUNISH.WARN.GREEN`)
.setTitle(`Warn`)
.setDescription("The user was warned")
.setStatus("Success")
], components: []})
} else {
let m = await interaction.editReply({
embeds: [new EmojiEmbed()
.setEmoji(`PUNISH.WARN.RED`)
.setTitle(`Warn`)
.setDescription("The user's DMs are not open\n\nWhat would you like to do?")
.setStatus("Danger")
], components: [
new MessageActionRow().addComponents([
new Discord.MessageButton()
.setCustomId("log")
.setLabel("Ignore and log")
.setStyle("SECONDARY"),
new Discord.MessageButton()
.setCustomId("here")
.setLabel("Warn here")
.setStyle("SECONDARY")
.setDisabled((interaction.options.getMember("user") as GuildMember).permissionsIn(interaction.channel as Discord.TextChannel).has("VIEW_CHANNEL") === false),
])
],
})
let component;
try {
component = await (m as Discord.Message).awaitMessageComponent({filter: (m) => m.user.id === interaction.user.id, time: 2.5 * 60 * 1000});
} catch (e) {
return await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji(`PUNISH.WARN.GREEN`)
.setTitle(`Warn`)
.setDescription("No changes were made")
.setStatus("Success")
], components: []})
}
if ( component.customId == "here" ) {
await interaction.channel.send({
embeds: [new EmojiEmbed()
.setEmoji(`PUNISH.WARN.RED`)
.setTitle(`Warn`)
.setDescription(`You have been warned` +
(interaction.options.getString("reason") ? ` for:\n> ${interaction.options.getString("reason")}` : " with no reason provided."))
.setStatus("Danger")
],
content: `<@!${(interaction.options.getMember("user") as GuildMember).id}>`,
allowedMentions: {users: [(interaction.options.getMember("user") as GuildMember).id]}
})
return await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji(`PUNISH.WARN.GREEN`)
.setTitle(`Warn`)
.setDescription("The user was warned")
.setStatus("Success")
], components: []})
} else {
await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji(`PUNISH.WARN.GREEN`)
.setTitle(`Warn`)
.setDescription("The warn was logged")
.setStatus("Success")
], components: []})
}
}
} else { } else {
await interaction.editReply({embeds: [new EmojiEmbed() await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("PUNISH.WARN.GREEN") .setEmoji("PUNISH.WARN.GREEN")
@ -71,6 +129,14 @@ const callback = async (interaction: CommandInteraction) => {
} }
const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => { const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
return true
let member = (interaction.member as GuildMember)
let me = (interaction.guild.me as GuildMember)
let apply = (interaction.options.getMember("user") as GuildMember)
if (member == null || me == null || apply == null) throw "That member is not in the server"
let memberPos = member.roles ? member.roles.highest.position : 0
let mePos = me.roles ? me.roles.highest.position : 0
let applyPos = apply.roles ? apply.roles.highest.position : 0
// Do not allow warning bots // Do not allow warning bots
if ((interaction.member as GuildMember).user.bot) throw "I cannot warn bots" if ((interaction.member as GuildMember).user.bot) throw "I cannot warn bots"
// Allow the owner to warn anyone // Allow the owner to warn anyone
@ -78,7 +144,7 @@ const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
// Check if the user has moderate_members permission // Check if the user has moderate_members permission
if (! (interaction.member as GuildMember).permissions.has("MODERATE_MEMBERS")) throw "You do not have the `moderate_members` permission"; if (! (interaction.member as GuildMember).permissions.has("MODERATE_MEMBERS")) throw "You do not have the `moderate_members` permission";
// Check if the user is below on the role list // Check if the user is below on the role list
if (! ((interaction.member as GuildMember).roles.highest.position > (interaction.options.getMember("user") as GuildMember).roles.highest.position)) throw "You do not have a role higher than that member" if (! (memberPos > applyPos)) throw "You do not have a role higher than that member"
// Allow warn // Allow warn
return true return true
} }

@ -32,6 +32,7 @@
"CROSS": "947441948543815720", "CROSS": "947441948543815720",
"LEFT": "947441951148486728", "LEFT": "947441951148486728",
"RIGHT": "947441957473488916", "RIGHT": "947441957473488916",
"DOWNLOAD": "947959513032585236",
"PILL": { "PILL": {
"TICK": "753314339082993832", "TICK": "753314339082993832",
"CROSS": "753314339389309100" "CROSS": "753314339389309100"

@ -61,6 +61,7 @@ class confirmationMessage {
} catch (e) { } catch (e) {
return false; // TODO: Check the type of the error; change the error message here return false; // TODO: Check the type of the error; change the error message here
} }
component.deferUpdate();
return component.customId === "yes" return component.customId === "yes"
} }

Loading…
Cancel
Save