Skip to content

Commit

Permalink
feat: add ActionRowWrapper#editComponent()
Browse files Browse the repository at this point in the history
I'm not sure why I didn't add this before
  • Loading branch information
Amgelo563 committed Jan 20, 2024
1 parent dec24e5 commit 39f7bf0
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion packages/framework/src/discord/ActionRowWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ import type {
MessageActionRowComponentData,
ModalActionRowComponentBuilder,
} from 'discord.js';
import { ActionRowBuilder, ComponentType } from 'discord.js';
import {
ActionRowBuilder,
ButtonStyle,
ComponentType,
isJSONEncodable,
} from 'discord.js';

type ComponentEditCallback<ComponentData extends ActionRowComponentData> = (
component: ComponentData,
Expand Down Expand Up @@ -69,6 +74,38 @@ export class ActionRowWrapper<ComponentData extends ActionRowComponentData> {
return this;
}

public editComponent(
customId: string,
callback: ComponentEditCallback<ComponentData>,
): this {
return this.editWhere(
(component) => {
if (isJSONEncodable(component)) {
const json = component.toJSON();
if (
json.type === ComponentType.Button
&& json.style === ButtonStyle.Link
) {
return false;
}

return json.custom_id === customId;
} else {
if (
component.type === ComponentType.Button
&& component.style === ButtonStyle.Link
) {
return false;
}

return component.customId === customId;
}
},
callback,
false,
);
}

public editWhere(
where: (component: ComponentData) => boolean,
callback: ComponentEditCallback<ComponentData>,
Expand Down

0 comments on commit 39f7bf0

Please sign in to comment.