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);
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,23 +152,25 @@ class PermissionsCommand extends SlashCommand
{
for (const perm of permission.asString.split(' '))
{
const result = grantables.filter(filterInexact(perm)).first();
if (!result)
const result = grantables.filter(filterInexact(perm.toLowerCase())).first();
if (!result)
continue;
if (result.type === 'module')
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')
if (component.module.id === 'administration')
adminWarning = true;
parsed.push(component.resolveable);
}
}
}
else
else
{
if (result.module.id === 'administration')
if (result.module.id === 'administration')
adminWarning = true;
parsed.push(result.resolveable);
}

View File

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