Changed a bunch of perms, shouldn't have any issues now

pull/8/head
pineafan 3 years ago
parent 9106564cf8
commit c1c1879834
No known key found for this signature in database
GPG Key ID: 0AEF25BAA0FB1C74

@ -3,7 +3,7 @@ import EmojiEmbed from '../utils/generateEmojiEmbed.js';
import getEmojiByName from "../utils/getEmojiByName.js"; import getEmojiByName from "../utils/getEmojiByName.js";
import client from "../utils/client.js"; import client from "../utils/client.js";
export async function create(guild: Discord.Guild, member: Discord.User, createdBy: Discord.User, reason: string) { export async function create(guild: Discord.Guild, member: Discord.User, createdBy: Discord.User, reason: string, customReason?: string) {
let config = await client.database.guilds.read(guild.id); let config = await client.database.guilds.read(guild.id);
const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger
let overwrites = [{ let overwrites = [{
@ -51,7 +51,7 @@ export async function create(guild: Discord.Guild, member: Discord.User, created
.setTitle("New Ticket") .setTitle("New Ticket")
.setDescription( .setDescription(
`Ticket created by a Moderator\n` + `Ticket created by a Moderator\n` +
`**Support type:** Appeal submission\n` + (reason !== null ? `**Reason:**\n> ${reason}\n` : "") + `**Support type:** ${customReason ? customReason : "Appeal submission"}\n` + (reason !== null ? `**Reason:**\n> ${reason}\n` : "") +
`**Ticket ID:** \`${c.id}\`\n` + `**Ticket ID:** \`${c.id}\`\n` +
`Type \`/ticket close\` to close this ticket.`, `Type \`/ticket close\` to close this ticket.`,
) )

@ -129,6 +129,8 @@ const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
let memberPos = member.roles ? member.roles.highest.position : 0 let memberPos = member.roles ? member.roles.highest.position : 0
let mePos = me.roles ? me.roles.highest.position : 0 let mePos = me.roles ? me.roles.highest.position : 0
let applyPos = apply.roles ? apply.roles.highest.position : 0 let applyPos = apply.roles ? apply.roles.highest.position : 0
// Do not allow banning the owner
if (member.id === interaction.guild.ownerId) throw "You cannot ban the owner of the server"
// Check if Nucleus can ban the member // Check if Nucleus can ban the member
if (! (mePos > applyPos)) 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

@ -128,6 +128,8 @@ const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
let memberPos = member.roles ? member.roles.highest.position : 0 let memberPos = member.roles ? member.roles.highest.position : 0
let mePos = me.roles ? me.roles.highest.position : 0 let mePos = me.roles ? me.roles.highest.position : 0
let applyPos = apply.roles ? apply.roles.highest.position : 0 let applyPos = apply.roles ? apply.roles.highest.position : 0
// Do not allow kicking the owner
if (member.id === interaction.guild.ownerId) throw "You cannot kick the owner of the server"
// Check if Nucleus can kick the member // Check if Nucleus can kick the member
if (! (mePos > applyPos)) 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

@ -252,12 +252,12 @@ const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
let memberPos = member.roles ? member.roles.highest.position : 0 let memberPos = member.roles ? member.roles.highest.position : 0
let mePos = me.roles ? me.roles.highest.position : 0 let mePos = me.roles ? me.roles.highest.position : 0
let applyPos = apply.roles ? apply.roles.highest.position : 0 let applyPos = apply.roles ? apply.roles.highest.position : 0
// Do not allow muting the owner
if (member.id === interaction.guild.ownerId) throw "You cannot mute the owner of the server"
// Check if Nucleus can mute the member // Check if Nucleus can mute the member
if (! (mePos > applyPos)) 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 (! me.permissions.has("MODERATE_MEMBERS")) throw "I do not have the *Moderate Members* permission"; if (! 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 (apply.permissions.has("ADMINISTRATOR") || (interaction.options.getMember("user") as GuildMember).id === interaction.guild.ownerId) throw "You cannot mute an admin or the owner"
// Do not allow muting Nucleus // Do not allow muting Nucleus
if (member.id === me.id) throw "I cannot mute myself" if (member.id === me.id) throw "I cannot mute myself"
// Allow the owner to mute anyone // Allow the owner to mute anyone

@ -121,6 +121,8 @@ const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
let memberPos = member.roles ? member.roles.highest.position : 0 let memberPos = member.roles ? member.roles.highest.position : 0
let mePos = me.roles ? me.roles.highest.position : 0 let mePos = me.roles ? me.roles.highest.position : 0
let applyPos = apply.roles ? apply.roles.highest.position : 0 let applyPos = apply.roles ? apply.roles.highest.position : 0
// Do not allow any changing of the owner
if (member.id === interaction.guild.ownerId) throw "You cannot change the owner's nickname"
// Check if Nucleus can change the nickname // Check if Nucleus can change the nickname
if (! (mePos > applyPos)) 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 change the nickname // Check if Nucleus has permission to change the nickname

@ -313,13 +313,13 @@ const callback = async (interaction: CommandInteraction): Promise<any> => {
const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => { const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
let member = (interaction.member as GuildMember) let member = (interaction.member as GuildMember)
let me = (interaction.guild.me as GuildMember) let me = (interaction.guild.me as GuildMember)
// Check if nucleus has the manage_messages permission
if (! me.permissions.has("MANAGE_MESSAGES")) throw "I do not have the *Manage Messages* permission";
// Allow the owner to purge // Allow the owner to purge
if (member.id === interaction.guild.ownerId) return true if (member.id === interaction.guild.ownerId) return true
// Check if the user has manage_messages permission // Check if the user has manage_messages permission
if (! member.permissions.has("MANAGE_MESSAGES")) throw "You do not have the *Manage Messages* permission"; if (! member.permissions.has("MANAGE_MESSAGES")) throw "You do not have the *Manage Messages* permission";
// Check if nucleus has the manage_messages permission // Allow purge
if (! me.permissions.has("MANAGE_MESSAGES")) throw "I do not have the *Manage Messages* permission";
// Allow warn
return true return true
} }

@ -106,13 +106,15 @@ const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
let memberPos = member.roles ? member.roles.highest.position : 0 let memberPos = member.roles ? member.roles.highest.position : 0
let mePos = me.roles ? me.roles.highest.position : 0 let mePos = me.roles ? me.roles.highest.position : 0
let applyPos = apply.roles ? apply.roles.highest.position : 0 let applyPos = apply.roles ? apply.roles.highest.position : 0
// Do not allow softbanning the owner
if (member.id === interaction.guild.ownerId) throw "You cannot softban the owner of the server"
// Check if Nucleus can ban the member // Check if Nucleus can ban the member
if (! (mePos > applyPos)) 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 (!me.permissions.has("BAN_MEMBERS")) throw "I do not have the *Ban Members* permission"; if (!me.permissions.has("BAN_MEMBERS")) throw "I do not have the *Ban Members* permission";
// Do not allow softbanning Nucleus // Do not allow softbanning Nucleus
if (member.id === me.id) throw "I cannot softban myself" if (member.id === me.id) throw "I cannot softban myself"
// Allow the owner to ban anyone // Allow the owner to softban anyone
if (member.id === interaction.guild.ownerId) return true if (member.id === interaction.guild.ownerId) return true
// Check if the user has ban_members permission // Check if the user has ban_members permission
if (! member.permissions.has("BAN_MEMBERS")) throw "You do not have the *Ban Members* permission"; if (! member.permissions.has("BAN_MEMBERS")) throw "You do not have the *Ban Members* permission";

@ -114,12 +114,12 @@ const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
let memberPos = member.roles ? member.roles.highest.position : 0 let memberPos = member.roles ? member.roles.highest.position : 0
let mePos = me.roles ? me.roles.highest.position : 0 let mePos = me.roles ? me.roles.highest.position : 0
let applyPos = apply.roles ? apply.roles.highest.position : 0 let applyPos = apply.roles ? apply.roles.highest.position : 0
// Do not allow unmuting the owner
if (member.id === interaction.guild.ownerId) throw "You cannot unmute the owner of the server"
// Check if Nucleus can unmute the member // Check if Nucleus can unmute the member
if (! (mePos > applyPos)) 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 unmute // Check if Nucleus has permission to unmute
if (! me.permissions.has("MODERATE_MEMBERS")) throw "I do not have the *Moderate Members* permission"; if (! 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 (apply.permissions.has("ADMINISTRATOR") || apply.id === interaction.guild.ownerId) throw "You cannot unmute an admin or the owner"
// Allow the owner to unmute anyone // Allow the owner to unmute anyone
if (member.id === interaction.guild.ownerId) return true if (member.id === interaction.guild.ownerId) return true
// Check if the user has moderate_members permission // Check if the user has moderate_members permission

@ -107,6 +107,7 @@ const callback = async (interaction: CommandInteraction): Promise<any> => {
.setStatus("Success") .setStatus("Success")
], components: []}) ], components: []})
} else { } else {
let canSeeChannel = (interaction.options.getMember("user") as GuildMember).permissionsIn(interaction.channel as Discord.TextChannel).has("VIEW_CHANNEL")
let m = await interaction.editReply({ let m = await interaction.editReply({
embeds: [new EmojiEmbed() embeds: [new EmojiEmbed()
.setEmoji(`PUNISH.WARN.RED`) .setEmoji(`PUNISH.WARN.RED`)
@ -122,8 +123,12 @@ const callback = async (interaction: CommandInteraction): Promise<any> => {
new Discord.MessageButton() new Discord.MessageButton()
.setCustomId("here") .setCustomId("here")
.setLabel("Warn here") .setLabel("Warn here")
.setStyle("SECONDARY") .setStyle(canSeeChannel ? "PRIMARY" : "SECONDARY")
.setDisabled((interaction.options.getMember("user") as GuildMember).permissionsIn(interaction.channel as Discord.TextChannel).has("VIEW_CHANNEL") === false), .setDisabled(!canSeeChannel),
new Discord.MessageButton()
.setCustomId("ticket")
.setLabel("Create ticket")
.setStyle(canSeeChannel ? "SECONDARY" : "PRIMARY")
]) ])
] ]
}) })
@ -156,13 +161,29 @@ const callback = async (interaction: CommandInteraction): Promise<any> => {
.setDescription("The user was warned" + (confirmation.response ? ` and an appeal ticket was opened in <#${confirmation.response}>` : ``)) .setDescription("The user was warned" + (confirmation.response ? ` and an appeal ticket was opened in <#${confirmation.response}>` : ``))
.setStatus("Success") .setStatus("Success")
], components: []}) ], components: []})
} else { } else if (component.customId === "log") {
await interaction.editReply({embeds: [new EmojiEmbed() await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji(`PUNISH.WARN.GREEN`) .setEmoji(`PUNISH.WARN.GREEN`)
.setTitle(`Warn`) .setTitle(`Warn`)
.setDescription("The warn was logged") .setDescription("The warn was logged")
.setStatus("Success") .setStatus("Success")
], components: []}) ], components: []})
} else if (component.customId === "ticket") {
let ticketChannel = await create(interaction.guild, interaction.options.getUser("user"), interaction.user, reason, "Warn Notification")
if (ticketChannel === null) {
return await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji(`PUNISH.WARN.RED`)
.setTitle(`Warn`)
.setDescription("A ticket could not be created")
.setStatus("Danger")
], components: []})
}
await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji(`PUNISH.WARN.GREEN`)
.setTitle(`Warn`)
.setDescription(`A ticket was created in <#${ticketChannel}>`)
.setStatus("Success")
], components: []})
} }
} }
} else { } else {

@ -59,7 +59,7 @@ const callback = async (interaction: CommandInteraction): Promise<any> => {
await interaction.editReply({embeds: [new EmojiEmbed() await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("GUILD.ROLES.CREATE") .setEmoji("GUILD.ROLES.CREATE")
.setTitle("Role") .setTitle("Role")
.setDescription(`You have cancelled the role change.`) .setDescription(`No changes were made.`)
.setStatus("Danger") .setStatus("Danger")
], components: []}) ], components: []})
} }

@ -20,7 +20,7 @@ const callback = async (interaction: CommandInteraction): Promise<any> => {
const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => { const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
let member = (interaction.member as Discord.GuildMember) let member = (interaction.member as Discord.GuildMember)
if (!member.permissions.has("MANAGE_GUILD")) throw "You must have the *Manage Server* permission to use this command" if (!member.permissions.has("MANAGE_MESSAGES")) throw "You must have the *Manage Messages* permission to use this command"
return true; return true;
} }

@ -8,9 +8,9 @@ import client from "../../utils/client.js";
const command = (builder: SlashCommandSubcommandBuilder) => const command = (builder: SlashCommandSubcommandBuilder) =>
builder builder
.setName("role") .setName("rolemenu")
.setDescription("Sets or shows the role given to users after using /verify") .setDescription("rolemenu")// TODO
.addRoleOption(option => option.setName("role").setDescription("The role to give after verifying")) .addRoleOption(option => option.setName("role").setDescription("The role to give after verifying")) // TODO
const callback = async (interaction: CommandInteraction): Promise<any> => { const callback = async (interaction: CommandInteraction): Promise<any> => {
} }

@ -1,10 +1,8 @@
import { LoadingEmbed } from './../../utils/defaultEmbeds.js'; import { LoadingEmbed } from './../../utils/defaultEmbeds.js';
import { ChannelType } from 'discord-api-types'; import Discord, { CommandInteraction, MessageActionRow, MessageSelectMenu } from "discord.js";
import Discord, { AutocompleteInteraction, CommandInteraction, Message, MessageActionRow, MessageButton, MessageSelectMenu } from "discord.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import confirmationMessage from "../../utils/confirmationMessage.js"; import confirmationMessage from "../../utils/confirmationMessage.js";
import getEmojiByName from "../../utils/getEmojiByName.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import { SelectMenuOption, SlashCommandSubcommandBuilder } from "@discordjs/builders";
import { WrappedCheck } from "jshaiku"; import { WrappedCheck } from "jshaiku";
import client from "../../utils/client.js"; import client from "../../utils/client.js";
import convertCurlyBracketString from '../../utils/convertCurlyBracketString.js'; import convertCurlyBracketString from '../../utils/convertCurlyBracketString.js';
@ -149,7 +147,7 @@ const callback = async (interaction: CommandInteraction): Promise<any> => {
const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => { const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
let member = (interaction.member as Discord.GuildMember) let member = (interaction.member as Discord.GuildMember)
if (!member.permissions.has("MANAGE_GUILD")) throw "You must have the *Manage Server* permission to use this command" if (!member.permissions.has("MANAGE_CHANNELS")) throw "You must have the *Manage Channels* permission to use this command"
return true; return true;
} }

@ -22,13 +22,14 @@ const command = (builder: SlashCommandSubcommandBuilder) => builder
const callback = async (interaction: CommandInteraction): Promise<any> => { const callback = async (interaction: CommandInteraction): Promise<any> => {
let m; let m;
m = await interaction.reply({embeds: LoadingEmbed, ephemeral: true, fetchReply: true}); m = await interaction.reply({embeds: LoadingEmbed, ephemeral: true, fetchReply: true})
let options = { let options = {
enabled: interaction.options.getString("enabled") as string | boolean, enabled: interaction.options.getString("enabled") as string | boolean,
category: interaction.options.getChannel("category"), category: interaction.options.getChannel("category"),
maxtickets: interaction.options.getNumber("maxticketsperuser"), maxtickets: interaction.options.getNumber("maxticketsperuser"),
supportping: interaction.options.getRole("supportrole") supportping: interaction.options.getRole("supportrole")
} }
console.log(m)
if (options.enabled !== null || options.category || options.maxtickets || options.supportping) { if (options.enabled !== null || options.category || options.maxtickets || options.supportping) {
options.enabled = options.enabled === "yes" ? true : false; options.enabled = options.enabled === "yes" ? true : false;
if (options.category) { if (options.category) {

@ -166,10 +166,12 @@ const check = async (interaction: CommandInteraction, defaultCheck: WrappedCheck
if (member.id === interaction.guild.ownerId) return true if (member.id === interaction.guild.ownerId) return true
// Check if the user can manage any of the tracks // Check if the user can manage any of the tracks
let managed = false let managed = false
tracks.forEach(element => { for (const element of tracks) {
if (!element.track.manageableBy) return if (!element.track.manageableBy) continue
if (element.track.manageableBy.some(role => member.roles.cache.has(role))) managed = true if (!element.track.manageableBy.some(role => member.roles.cache.has(role))) continue
}); managed = true;
break;
};
// Check if the user has manage_roles permission // Check if the user has manage_roles permission
if (!managed && ! member.permissions.has("MANAGE_ROLES")) throw "You do not have the *Manage Roles* permission"; if (!managed && ! member.permissions.has("MANAGE_ROLES")) throw "You do not have the *Manage Roles* permission";
// Allow track // Allow track

Loading…
Cancel
Save