Skip to content

Commit

Permalink
removed uncessary methods and more
Browse files Browse the repository at this point in the history
  • Loading branch information
catplvsplus committed May 30, 2024
1 parent 18cf19c commit 5c8beea
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 43 deletions.
61 changes: 19 additions & 42 deletions packages/core/src/classes/managers/CommandManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { RecipleClient } from '../structures/RecipleClient.js';
import { CommandType } from '../../types/constants.js';
import { Utils } from '../structures/Utils.js';
import defaultsDeep from 'lodash.defaultsdeep';
import { CommandHalt, CommandHaltResultData } from '../structures/CommandHalt.js';
import { CommandHalt, CommandHaltResolvable, CommandHaltResultData } from '../structures/CommandHalt.js';

export interface CommandManagerRegisterCommandsOptions extends Omit<Exclude<RecipleClientConfig['applicationCommandRegister'], undefined>, 'enabled'> {
contextMenuCommands?: Partial<RecipleClientInteractionBasedCommandConfigOptions> & {
Expand Down Expand Up @@ -49,47 +49,9 @@ export class CommandManager {
return preconditions;
}

public removePreconditions(...data: RestOrArray<string>): CommandPrecondition[] {
const ids = normalizeArray(data);
const preconditions: CommandPrecondition[] = [];

for (const id of ids) {
const precondition = this.preconditions.get(id);
if (!precondition) continue;

preconditions.push(precondition);
this.preconditions.delete(id);
}

return preconditions;
}

public disablePreconditions(...data: RestOrArray<string|CommandPreconditionResolvable>): CommandPrecondition[] {
const ids = normalizeArray(data).map(id => typeof id === 'string' ? id : CommandPrecondition.resolve(id).id);
const preconditions: CommandPrecondition[] = [];

for (const id of ids) {
const precondition = this.preconditions.get(id);
if (!precondition) continue;

precondition.setDisabled(false);
}

return preconditions;
}

public enablePreconditions(...data: RestOrArray<string|CommandPreconditionResolvable>): CommandPrecondition[] {
const ids = normalizeArray(data).map(id => typeof id === 'string' ? id : CommandPrecondition.resolve(id).id);
const preconditions: CommandPrecondition[] = [];

for (const id of ids) {
const precondition = this.preconditions.get(id);
if (!precondition) continue;

precondition.setDisabled(false);
}

return preconditions;
public setPreconditions(...data: RestOrArray<CommandPreconditionResolvable>): CommandPrecondition[] {
this.preconditions.clear();
return this.addPreconditions(normalizeArray(data));
}

public async executePreconditions<T extends AnyCommandExecuteData = AnyCommandExecuteData>(executeData: T): Promise<CommandPreconditionResultData<T>|null> {
Expand All @@ -113,6 +75,21 @@ export class CommandManager {
return null;
}

public addHalts(...data: RestOrArray<CommandHaltResolvable>): CommandHalt[] {
const halts = normalizeArray(data).map(h => CommandHalt.resolve(h));

for (const halt of halts) {
this.halts.set(halt.id, halt);
}

return halts;
}

public setHalts(...data: RestOrArray<CommandHaltResolvable>): CommandHalt[] {
this.halts.clear();
return this.addHalts(normalizeArray(data));
}

public async executeHalts<T extends AnyCommandHaltTriggerData = AnyCommandHaltTriggerData>(trigger: T): Promise<CommandHaltResultData<T['commandType']>|null> {
const halts: CommandHalt<T['commandType']>[] = [];
const disabledHalts = trigger.executeData.builder.disabled_halts;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/classes/structures/RecipleClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class RecipleClient<Ready extends boolean = boolean> extends Client<Ready
this.cooldowns?.setCooldownSweeper(this.config.cooldownSweeperOptions ?? { timer: 1000 * 60 * 60 });

if (this.config.preconditions) this.commands?.addPreconditions(this.config.preconditions);
if (this.config.commandHalts) this.commands?.addHalts(this.config.commandHalts);

token = await super.login(this.config.token);

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/types/structures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MessageCommandOptionValue } from '../classes/structures/MessageCommandO
import { CooldownSweeperOptions } from '../classes/managers/CooldownManager.js';
import { CommandHaltReason, CommandType } from './constants.js';
import { Cooldown } from '../classes/structures/Cooldown.js';
import { CommandHaltResultData } from '../classes/structures/CommandHalt.js';
import { CommandHaltResolvable, CommandHaltResultData } from '../classes/structures/CommandHalt.js';

// Config
export interface RecipleClientConfig {
Expand All @@ -29,6 +29,7 @@ export interface RecipleClientConfig {
};
cooldownSweeperOptions?: CooldownSweeperOptions;
preconditions?: CommandPreconditionResolvable[];
commandHalts?: CommandHaltResolvable[];
client: ClientOptions;
}

Expand Down

0 comments on commit 5c8beea

Please sign in to comment.