mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-25 03:49:11 +00:00
chore: refactor asyncResponse to take a preflight response
This commit is contained in:
parent
26bc74bcbc
commit
76a03c2d2c
3 changed files with 21 additions and 8 deletions
|
@ -1,5 +1,8 @@
|
||||||
import { selectRole } from '@roleypoly/interactions/utils/api';
|
import { selectRole } from '@roleypoly/interactions/utils/api';
|
||||||
import { asyncResponse } from '@roleypoly/interactions/utils/interactions';
|
import {
|
||||||
|
asyncPreflightEphemeral,
|
||||||
|
asyncResponse,
|
||||||
|
} from '@roleypoly/interactions/utils/interactions';
|
||||||
import { invalid, mustBeInGuild } from '@roleypoly/interactions/utils/responses';
|
import { invalid, mustBeInGuild } from '@roleypoly/interactions/utils/responses';
|
||||||
import {
|
import {
|
||||||
InteractionCallbackType,
|
InteractionCallbackType,
|
||||||
|
@ -78,5 +81,6 @@ export const pickRole = (mode: 'add' | 'remove') =>
|
||||||
flags: InteractionFlags.EPHEMERAL,
|
flags: InteractionFlags.EPHEMERAL,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
|
asyncPreflightEphemeral
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import { getPickableRoles } from '@roleypoly/interactions/utils/api';
|
import { getPickableRoles } from '@roleypoly/interactions/utils/api';
|
||||||
import { uiPublicURI } from '@roleypoly/interactions/utils/config';
|
import { uiPublicURI } from '@roleypoly/interactions/utils/config';
|
||||||
import { asyncResponse } from '@roleypoly/interactions/utils/interactions';
|
import {
|
||||||
|
asyncPreflightEphemeral,
|
||||||
|
asyncResponse,
|
||||||
|
} from '@roleypoly/interactions/utils/interactions';
|
||||||
import { mustBeInGuild } from '@roleypoly/interactions/utils/responses';
|
import { mustBeInGuild } from '@roleypoly/interactions/utils/responses';
|
||||||
import {
|
import {
|
||||||
CategoryType,
|
CategoryType,
|
||||||
|
@ -55,5 +58,6 @@ export const pickableRoles = asyncResponse(
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
|
asyncPreflightEphemeral
|
||||||
);
|
);
|
||||||
|
|
|
@ -41,7 +41,10 @@ export type CommandHandler = (
|
||||||
) => Promise<InteractionResponse>;
|
) => Promise<InteractionResponse>;
|
||||||
|
|
||||||
export const asyncResponse =
|
export const asyncResponse =
|
||||||
(handler: CommandHandler): CommandHandler =>
|
(
|
||||||
|
handler: CommandHandler,
|
||||||
|
preflight?: () => InteractionResponse['data']
|
||||||
|
): CommandHandler =>
|
||||||
async (
|
async (
|
||||||
command: InteractionRequestCommand,
|
command: InteractionRequestCommand,
|
||||||
requestInfo: RequestInfo
|
requestInfo: RequestInfo
|
||||||
|
@ -55,12 +58,14 @@ export const asyncResponse =
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: InteractionCallbackType.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE,
|
type: InteractionCallbackType.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE,
|
||||||
data: {
|
data: preflight ? preflight() : undefined,
|
||||||
flags: InteractionFlags.EPHEMERAL,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const asyncPreflightEphemeral = () => ({
|
||||||
|
flags: InteractionFlags.EPHEMERAL,
|
||||||
|
});
|
||||||
|
|
||||||
const updateOriginalMessage = async (
|
const updateOriginalMessage = async (
|
||||||
appID: string,
|
appID: string,
|
||||||
token: string,
|
token: string,
|
||||||
|
|
Loading…
Add table
Reference in a new issue