Skip to content

Commit

Permalink
proper mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoobes committed May 21, 2024
1 parent 7f4004e commit 814fc4f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/core/id.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ApplicationCommandType, ComponentType, Interaction, InteractionType } from 'discord.js';
import { CommandType, EventType } from './structures/enums';

const parseParams = (event: { customId: string }, id: string) => {
const parseParams = (event: { customId: string }, id: string, append: string) => {
const hasSlash = event.customId.indexOf('/')
if(hasSlash === -1) {
return { id };
}
const baseid = event.customId.substring(0, hasSlash);
const params = event.customId.substring(hasSlash+1);
return { id: baseid, params }
return { id: baseid+append, params }
}
/**
* Construct unique ID for a given interaction object.
Expand All @@ -18,17 +18,18 @@ const parseParams = (event: { customId: string }, id: string) => {
export function reconstruct<T extends Interaction>(event: T) {
switch (event.type) {
case InteractionType.MessageComponent: {
let id = `${event.customId}_C${event.componentType}`;
const data = parseParams(event, id)
let id = event.customId;
const data = parseParams(event, id, `_C${event.componentType}`)
console.log(data)
return [data];
}
case InteractionType.ApplicationCommand:
case InteractionType.ApplicationCommandAutocomplete:
return [{ id: `${event.commandName}_A${event.commandType}` }, { id: `${event.commandName}_B` }];
//Modal interactions are classified as components for sern
case InteractionType.ModalSubmit: {
let id = `${event.customId}_M`;
const data = parseParams(event, id);
let id = `${event.customId}`;
const data = parseParams(event, id, '_M');
return [data];
}
}
Expand Down

0 comments on commit 814fc4f

Please sign in to comment.