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 * Assigns the component module and makes it available for the client
* *
* @param {Component} component Component to load * @param component Component to load
* @param {string} directory The directory in which the component resides * @param directory The directory in which the component resides
* @param {boolean} [silent=false] Whether to emit a component update event * @param [silent=false] Whether to emit a component update event
* @return {Component}
* @memberof Registry * @memberof Registry
*/ */
async loadComponent<T extends Component> (component: T, directory?: string, silent = false): Promise<T> 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. { // Sets modules or "groups" for each component, specified by their properties.
let module = this.#components.get(`module:${component.moduleName}`) as Module; let module = this.#components.get(`module:${component.moduleName}`) as Module;
if (!module) if (!module)
{
module = await this.loadComponent(new Module(this.#client, { name: component.moduleName })); 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; component.module = module;
module.components.set(component.resolveable, component); 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 Emojis from '../../../../constants/Emojis.js';
import { PermissionSet } from '../../../../../@types/Guild.js'; import { PermissionSet } from '../../../../../@types/Guild.js';
const filterInexact = (search: string) => (comp: Component) => comp.id.toLowerCase().includes(search) const filterInexact = (search: string) => (comp: Component) =>
|| comp.resolveable.toLowerCase().includes(search); {
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 class PermissionsCommand extends SlashCommand
{ {
@ -116,7 +121,6 @@ class PermissionsCommand extends SlashCommand
} }
] ]
}); });
} }
async execute (invoker: InvokerWrapper<true>, { role, channel, member, permission }: CommandParams) 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(' ')) for (const perm of permission.asString.split(' '))
{ {
const result = grantables.filter(filterInexact(perm)).first(); const result = grantables.filter(filterInexact(perm.toLowerCase())).first();
if (!result) if (!result)
continue; continue;
if (result.type === 'module') if (result.type === 'module')
{ {
const module = result as Module; const module = result as Module;
for (const component of module.components.values()) for (const component of module.components.values())
{
if (component.type === 'command') if (component.type === 'command')
{ {
if (component.module.id === 'administration') if (component.module.id === 'administration')
adminWarning = true; adminWarning = true;
parsed.push(component.resolveable); parsed.push(component.resolveable);
} }
}
} }
else else
{ {
if (result.module.id === 'administration') if (result.module.id === 'administration')
adminWarning = true; adminWarning = true;
parsed.push(result.resolveable); parsed.push(result.resolveable);
} }

View File

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