fix ticket cmd perms, updated djs & added dump cmd

This commit is contained in:
DJj123dj
2024-09-04 20:13:13 +02:00
parent 39099a0dfe
commit 55bcff8030
10 changed files with 113 additions and 63 deletions
+1 -3
View File
@@ -82,6 +82,7 @@ export class ODSlashCommandManager_Default extends ODSlashCommandManager {
* It's used to generate typescript declarations for this class.
*/
export interface ODTextCommandManagerIds_Default {
"openticket:dump":ODTextCommand,
"openticket:help":ODTextCommand,
"openticket:panel":ODTextCommand,
"openticket:close":ODTextCommand,
@@ -138,9 +139,6 @@ export class ODTextCommandManager_Default extends ODTextCommandManager {
return super.exists(id)
}
onInteraction(prefix:string, id:keyof ODTextCommandManagerIds_Default, callback:ODTextCommandInteractionCallback): void
onInteraction(commandPrefix:string, commandName:string|RegExp, callback:ODTextCommandInteractionCallback): void
onInteraction(commandPrefix:string, commandName:string|RegExp, callback:ODTextCommandInteractionCallback): void {
return super.onInteraction(commandPrefix,commandName,callback)
}
+1 -1
View File
@@ -996,7 +996,7 @@ export class ODTextCommandManager extends ODManager<ODTextCommand> {
//filter commands for correct name
const validNameCommands: {cmd:ODTextCommand,newContent:string}[] = []
validPrefixCommands.forEach((cmd) => {
if (cmd.newContent.startsWith(cmd.cmd.builder.name)) validNameCommands.push({
if (cmd.newContent.startsWith(cmd.cmd.builder.name+" ") || cmd.newContent == cmd.cmd.builder.name) validNameCommands.push({
cmd:cmd.cmd,
newContent:cmd.newContent.substring(cmd.cmd.builder.name.length+1) //+1 because of space after command name
})
+3
View File
@@ -13,6 +13,8 @@ export interface ODDefaults {
crashOnError:boolean,
/**Enable the system responsible for the `--debug` flag. */
debugLoading:boolean,
/**When enabled, you're able to use the "!OPENTICKET:dump" command to send the OT debug file. This is only possible when you're the owner of the bot. */
allowDumpCommand:boolean,
/**Enable loading all Open Ticket plugins, sadly enough is only useful for the system :) */
pluginLoading:boolean,
/**Don't crash the bot when a plugin crashes! */
@@ -219,6 +221,7 @@ export class ODDefaultsManager {
errorHandling:true,
crashOnError:false,
debugLoading:true,
allowDumpCommand:true,
pluginLoading:true,
softPluginLoading:false,
+71 -56
View File
@@ -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}
}
+1 -1
View File
@@ -325,7 +325,7 @@ export class ODCommandResponderInstance {
this.didReply = true
return {success:true,message:await sent.fetch()}
}
}else if (this.type == "message" && this.interaction instanceof discord.Message){
}else if (this.type == "message" && this.interaction instanceof discord.Message && this.interaction.channel.type != discord.ChannelType.GroupDM){
const sent = await this.interaction.channel.send(msg.message)
this.didReply = true
return {success:true,message:sent}