fix ticket cmd perms, updated djs & added dump cmd
This commit is contained in:
@@ -91,66 +91,18 @@ export class ODPermissionManager extends ODManager<ODPermission> {
|
||||
else throw new ODSystemError("Invalid minimum permission type at ODPermissionManager.hasPermissions()")
|
||||
}
|
||||
async #defaultCalculation(user:discord.User,channel?:discord.Channel|null,guild?:discord.Guild|null, settings?:ODPermissionSettings|null): Promise<ODPermissionResult> {
|
||||
const globalCalc = await this.#defaultGlobalCalculation(user,channel,guild,settings)
|
||||
const channelCalc = await this.#defaultChannelCalculation(user,channel,guild,settings)
|
||||
|
||||
if (globalCalc.level > channelCalc.level) return globalCalc
|
||||
else return channelCalc
|
||||
}
|
||||
/**Check for global permissions. Then this result can be compared with the channel one. */
|
||||
async #defaultGlobalCalculation(user:discord.User,channel?:discord.Channel|null,guild?:discord.Guild|null, settings?:ODPermissionSettings|null): Promise<ODPermissionResult> {
|
||||
const idRegex = (settings && typeof settings.idRegex != "undefined") ? settings.idRegex : null
|
||||
const allowChannelUserScope = (settings && typeof settings.allowChannelUserScope != "undefined") ? settings.allowChannelUserScope : true
|
||||
const allowChannelRoleScope = (settings && typeof settings.allowChannelRoleScope != "undefined") ? settings.allowChannelRoleScope : true
|
||||
const allowGlobalUserScope = (settings && typeof settings.allowGlobalUserScope != "undefined") ? settings.allowGlobalUserScope : true
|
||||
const allowGlobalRoleScope = (settings && typeof settings.allowGlobalRoleScope != "undefined") ? settings.allowGlobalRoleScope : true
|
||||
|
||||
if (guild && channel && !channel.isDMBased()){
|
||||
//check for channel user permissions
|
||||
if (allowChannelUserScope){
|
||||
const users = this.getFiltered((permission) => (!idRegex || (idRegex && idRegex.test(permission.id.value))) && permission.scope == "channel-user" && permission.channel && (permission.channel.id == channel.id) && (permission.value instanceof discord.User) && permission.value.id == user.id)
|
||||
|
||||
if (users.length > 0){
|
||||
//sort all permisions from highest to lowest
|
||||
users.sort((a,b) => {
|
||||
const levelA = ODPermissionLevel[a.permission]
|
||||
const levelB = ODPermissionLevel[b.permission]
|
||||
|
||||
if (levelB > levelA) return 1
|
||||
else if (levelA > levelB) return -1
|
||||
else return 0
|
||||
})
|
||||
|
||||
return {
|
||||
type:users[0].permission,
|
||||
scope:"channel-user",
|
||||
level:ODPermissionLevel[users[0].permission],
|
||||
source:users[0] ?? null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//check for channel role permissions
|
||||
if (allowChannelRoleScope){
|
||||
const member = await guild.members.fetch(user.id)
|
||||
if (member){
|
||||
const memberRoles = member.roles.cache.map((role) => role.id)
|
||||
const roles = this.getFiltered((permission) => (!idRegex || (idRegex && idRegex.test(permission.id.value))) && permission.scope == "channel-role" && permission.channel && (permission.channel.id == channel.id) && (permission.value instanceof discord.Role) && memberRoles.includes(permission.value.id) && permission.value.guild.id == guild.id)
|
||||
|
||||
if (roles.length > 0){
|
||||
//sort all permisions from highest to lowest
|
||||
roles.sort((a,b) => {
|
||||
const levelA = ODPermissionLevel[a.permission]
|
||||
const levelB = ODPermissionLevel[b.permission]
|
||||
|
||||
if (levelB > levelA) return 1
|
||||
else if (levelA > levelB) return -1
|
||||
else return 0
|
||||
})
|
||||
|
||||
return {
|
||||
type:roles[0].permission,
|
||||
scope:"channel-role",
|
||||
level:ODPermissionLevel[roles[0].permission],
|
||||
source:roles[0] ?? null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//check for global user permissions
|
||||
if (allowGlobalUserScope){
|
||||
const users = this.getFiltered((permission) => (!idRegex || (idRegex && idRegex.test(permission.id.value))) && permission.scope == "global-user" && (permission.value instanceof discord.User) && permission.value.id == user.id)
|
||||
@@ -205,6 +157,69 @@ export class ODPermissionManager extends ODManager<ODPermission> {
|
||||
}
|
||||
}
|
||||
|
||||
//spread result to prevent accidental referencing
|
||||
return {...this.defaultResult}
|
||||
}
|
||||
/**Check for channel permissions. Then this result can be compared with the global one. */
|
||||
async #defaultChannelCalculation(user:discord.User,channel?:discord.Channel|null,guild?:discord.Guild|null, settings?:ODPermissionSettings|null): Promise<ODPermissionResult> {
|
||||
const idRegex = (settings && typeof settings.idRegex != "undefined") ? settings.idRegex : null
|
||||
const allowChannelUserScope = (settings && typeof settings.allowChannelUserScope != "undefined") ? settings.allowChannelUserScope : true
|
||||
const allowChannelRoleScope = (settings && typeof settings.allowChannelRoleScope != "undefined") ? settings.allowChannelRoleScope : true
|
||||
|
||||
if (guild && channel && !channel.isDMBased()){
|
||||
//check for channel user permissions
|
||||
if (allowChannelUserScope){
|
||||
const users = this.getFiltered((permission) => (!idRegex || (idRegex && idRegex.test(permission.id.value))) && permission.scope == "channel-user" && permission.channel && (permission.channel.id == channel.id) && (permission.value instanceof discord.User) && permission.value.id == user.id)
|
||||
|
||||
if (users.length > 0){
|
||||
//sort all permisions from highest to lowest
|
||||
users.sort((a,b) => {
|
||||
const levelA = ODPermissionLevel[a.permission]
|
||||
const levelB = ODPermissionLevel[b.permission]
|
||||
|
||||
if (levelB > levelA) return 1
|
||||
else if (levelA > levelB) return -1
|
||||
else return 0
|
||||
})
|
||||
|
||||
return {
|
||||
type:users[0].permission,
|
||||
scope:"channel-user",
|
||||
level:ODPermissionLevel[users[0].permission],
|
||||
source:users[0] ?? null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//check for channel role permissions
|
||||
if (allowChannelRoleScope){
|
||||
const member = await guild.members.fetch(user.id)
|
||||
if (member){
|
||||
const memberRoles = member.roles.cache.map((role) => role.id)
|
||||
const roles = this.getFiltered((permission) => (!idRegex || (idRegex && idRegex.test(permission.id.value))) && permission.scope == "channel-role" && permission.channel && (permission.channel.id == channel.id) && (permission.value instanceof discord.Role) && memberRoles.includes(permission.value.id) && permission.value.guild.id == guild.id)
|
||||
|
||||
if (roles.length > 0){
|
||||
//sort all permisions from highest to lowest
|
||||
roles.sort((a,b) => {
|
||||
const levelA = ODPermissionLevel[a.permission]
|
||||
const levelB = ODPermissionLevel[b.permission]
|
||||
|
||||
if (levelB > levelA) return 1
|
||||
else if (levelA > levelB) return -1
|
||||
else return 0
|
||||
})
|
||||
|
||||
return {
|
||||
type:roles[0].permission,
|
||||
scope:"channel-role",
|
||||
level:ODPermissionLevel[roles[0].permission],
|
||||
source:roles[0] ?? null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//spread result to prevent accidental referencing
|
||||
return {...this.defaultResult}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user