Skip to content

Commit

Permalink
Document some methods and things
Browse files Browse the repository at this point in the history
  • Loading branch information
catplvsplus committed May 30, 2024
1 parent b300951 commit a51c467
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/core/src/classes/managers/CooldownManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Cooldown, CooldownData } from '../structures/Cooldown.js';
import { RecipleClient } from '../structures/RecipleClient.js';
import { DataManager } from './DataManager.js';

export interface CooldownSweeperOptions {
Expand All @@ -10,6 +11,10 @@ export interface CooldownSweeperOptions {
export class CooldownManager extends DataManager<Cooldown> {
private _sweeper?: NodeJS.Timeout;

constructor(readonly client: RecipleClient) {
super();
}

public create(data: CooldownData): Cooldown {
const isExists = this.findCooldown(data);
if (isExists) return isExists;
Expand Down
26 changes: 26 additions & 0 deletions packages/core/src/classes/structures/CommandPrecondition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,32 @@ import { AnyCommandExecuteData } from '../../types/structures.js';
import { CommandType } from '../../types/constants.js';

export interface CommandPreconditionData {
/**
* The id of the precondition.
* The id only accepts lowercase letters and cannot contain spaces or special characters.
*/
id: string;
/**
* Whether the precondition is disabled.
*/
disabled?: boolean;
/**
* The execute function for context menu commands.
* @param execute Execute data for the command.
* @param precondition The precondition that is being executed.
*/
contextMenuCommandExecute?: (execute: ContextMenuCommandExecuteData, precondition: CommandPrecondition) => Awaitable<CommandPreconditionResultResolvable<ContextMenuCommandExecuteData>>;
/**
* The execute function for message commands.
* @param execute Execute data for the command.
* @param precondition The precondition that is being executed.
*/
messageCommandExecute?: (execute: MessageCommandExecuteData, precondition: CommandPrecondition) => Awaitable<CommandPreconditionResultResolvable<MessageCommandExecuteData>>;
/**
* The execute function for slash commands.
* @param execute Execute data for the command.
* @param precondition The precondition that is being executed.
*/
slashCommandExecute?: (execute: SlashCommandExecuteData, precondition: CommandPrecondition) => Awaitable<CommandPreconditionResultResolvable<SlashCommandExecuteData>>;
}

Expand Down Expand Up @@ -39,6 +61,10 @@ export class CommandPrecondition implements CommandPreconditionData {
this.slashCommandExecute = data.slashCommandExecute;
}

/**
* Sets the disabled state of the precondition.
* @param disabled Disabled state of the precondition.
*/
public setDisabled(disabled: boolean): this {
this.disabled = disabled;
return this;
Expand Down
21 changes: 21 additions & 0 deletions packages/core/src/classes/structures/Cooldown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,29 @@ import { CommandType } from '../../types/constants.js';
import { TextBasedChannel } from 'discord.js';

export interface CooldownData {
/**
* The user id of the user that the cooldown is for.
*/
userId: string;
/**
* The date that the cooldown ends at.
*/
endsAt: Date;
/**
* The channel id of the channel that the cooldown is for.
*/
channelId?: string;
/**
* The guild id of the guild that the cooldown is for.
*/
guildId?: string;
/**
* The name of the command that the cooldown is for.
*/
commandName?: string;
/**
* The type of the command that the cooldown is for.
*/
commandType?: CommandType;
}

Expand Down Expand Up @@ -49,6 +67,9 @@ export class Cooldown implements CooldownData {
this.commandType = data.commandType;
}

/**
* Check if the cooldown has ended.
*/
public isEnded(): boolean {
return this.endsAt.getTime() <= Date.now();
}
Expand Down
22 changes: 22 additions & 0 deletions packages/core/src/classes/structures/MessageCommandOptionValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,29 @@ import { RecipleClient } from './RecipleClient.js';
import { Message } from 'discord.js';

export interface MessageCommandOptionValueData<T extends any = any> {
/**
* The name of the option.
*/
name: string;
/**
* The builder that is used to create the option.
*/
option: MessageCommandOptionBuilder<T>;
/**
* The raw value of the option.
*/
value: string|null;
/**
* Whether the option is missing.
*/
missing: boolean;
/**
* Whether the option is invalid.
*/
invalid: boolean;
/**
* The error that occurred while parsing the option.
*/
error?: string|Error;
}

Expand Down Expand Up @@ -39,6 +57,10 @@ export class MessageCommandOptionValue<T extends any = any> implements MessageCo
this.error = typeof options.error === 'string' ? new Error(options.error) : options.error;
}

/**
* Resolves the raw value of the option.
* @param required Whether the option is required.
*/
public async resolveValue(required?: boolean): Promise<T|null>;
public async resolveValue(required?: true): Promise<T>;
public async resolveValue(required: boolean = false): Promise<T|null> {
Expand Down
25 changes: 25 additions & 0 deletions packages/core/src/classes/structures/RecipleModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,37 @@ import { Utils } from './Utils.js';
import semver from 'semver';

export interface RecipleModuleData {
/**
* The id of your module.
* The id only accepts lowercase letters and cannot contain spaces or special characters.
*/
id?: string;
/**
* The name of your module. This is used to display when logging the module into the console.
*/
name?: string;
/**
* The supported reciple client versions of the module.
*/
versions?: string|string[];
/**
* The commands that the module will use.
*/
commands?: AnyCommandResolvable[];
/**
* The function that is executed when the module is resolved. (Bot's Pre-login)
* @param data The data that is passed to the module.
*/
onStart(data: RecipleModuleStartData): boolean|string|Error|Promise<boolean|string|Error>;
/**
* The function that is executed when the module is loaded. (Bot's Post-login)
* @param data The data that is passed to the module.
*/
onLoad?(data: RecipleModuleLoadData): void|string|Error|Promise<void|string|Error>;
/**
* The function that is executed when the module is unloaded. (Bot's Pre-logout)
* @param data The data that is passed to the module.
*/
onUnload?(data: RecipleModuleUnloadData): void|string|Error|Promise<void|string|Error>;
}

Expand Down

0 comments on commit a51c467

Please sign in to comment.