This commit is contained in:
Erik 2023-12-08 18:16:25 +02:00
parent b165568dd0
commit 6cee362340
3 changed files with 25 additions and 19 deletions

View File

@ -60,10 +60,9 @@ class Registry
/**
* Assigns the component module and makes it available for the client
*
* @param {Component} component Component to load
* @param {string} directory The directory in which the component resides
* @param {boolean} [silent=false] Whether to emit a component update event
* @return {Component}
* @param component Component to load
* @param directory The directory in which the component resides
* @param [silent=false] Whether to emit a component update event
* @memberof Registry
*/
async loadComponent<T extends Component> (component: T, directory?: string, silent = false): Promise<T>
@ -80,9 +79,11 @@ class Registry
{ // Sets modules or "groups" for each component, specified by their properties.
let module = this.#components.get(`module:${component.moduleName}`) as Module;
if (!module)
{
module = await this.loadComponent(new Module(this.#client, { name: component.moduleName }));
this.#components.set(module.resolveable, module);
}
component.module = module;
module.components.set(component.resolveable, component);
}

View File

@ -9,8 +9,13 @@ import InvokerWrapper from '../../wrappers/InvokerWrapper.js';
import Emojis from '../../../../constants/Emojis.js';
import { PermissionSet } from '../../../../../@types/Guild.js';
const filterInexact = (search: string) => (comp: Component) => comp.id.toLowerCase().includes(search)
|| comp.resolveable.toLowerCase().includes(search);
const filterInexact = (search: string) => (comp: Component) =>
{
const id = comp.id.toLowerCase().includes(search);
const res = comp.resolveable.toLowerCase().includes(search);
// console.log(search, comp.id, id, comp.resolveable, res);
return id || res;
};
class PermissionsCommand extends SlashCommand
{
@ -116,7 +121,6 @@ class PermissionsCommand extends SlashCommand
}
]
});
}
async execute (invoker: InvokerWrapper<true>, { role, channel, member, permission }: CommandParams)
@ -148,13 +152,14 @@ class PermissionsCommand extends SlashCommand
{
for (const perm of permission.asString.split(' '))
{
const result = grantables.filter(filterInexact(perm)).first();
const result = grantables.filter(filterInexact(perm.toLowerCase())).first();
if (!result)
continue;
if (result.type === 'module')
{
const module = result as Module;
for (const component of module.components.values())
{
if (component.type === 'command')
{
if (component.module.id === 'administration')
@ -162,6 +167,7 @@ class PermissionsCommand extends SlashCommand
parsed.push(component.resolveable);
}
}
}
else
{
if (result.module.id === 'administration')

View File

@ -12,7 +12,6 @@ import { ModuleOptions } from '../../../@types/Client.js';
class Module extends Component
{
#name: string;
#components: Collection<string, Component>;
@ -38,7 +37,7 @@ class Module extends Component
get components ()
{
return this.#components.clone();
return this.#components;
}
}