fully prepare execution for interactions
This commit is contained in:
parent
28dce0b29f
commit
56a0e686b0
1 changed files with 40 additions and 16 deletions
|
@ -54,6 +54,32 @@ async function getUserLimit(user: string | {id: string}, requestTimestamp: Date)
|
|||
return {limit: userLimits.limit, remaining: userLimits.limit - usedLimit};
|
||||
}
|
||||
|
||||
/**
|
||||
* Replies to a request
|
||||
* @param request the request to reply to
|
||||
* @param message the message
|
||||
* @param replyOptions additional options if the request is a message
|
||||
* @param interactionOptions additional options if the request is an interaction
|
||||
* @returns Promise of the done action
|
||||
*/
|
||||
function requestReply(
|
||||
request: request,
|
||||
message: DiscordApi.MessageReplyOptions & DiscordApi.InteractionReplyOptions,
|
||||
// TODO: add support for these below
|
||||
replyOptions: DiscordApi.MessageReplyOptions = {},
|
||||
interactionOptions: DiscordApi.InteractionReplyOptions = {},
|
||||
) {
|
||||
if (request instanceof DiscordApi.Message) {
|
||||
return request.reply(Object.assign(message, replyOptions));
|
||||
}
|
||||
else {
|
||||
if (!request.deferred)
|
||||
return request.reply(Object.assign(message, interactionOptions));
|
||||
else
|
||||
return request.editReply(Object.assign(message, interactionOptions));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and queues up the request and runs it if there is nothing in queue.
|
||||
* @param request the message to check and queue
|
||||
|
@ -151,14 +177,10 @@ async function executeFromQueue(channel: string) {
|
|||
const answerContent = answer.data.choices[0].message?.content;
|
||||
|
||||
if (answerContent != undefined || answerContent != "") {
|
||||
const response = message.reply({
|
||||
content: answerContent,
|
||||
allowedMentions: {
|
||||
repliedUser: false,
|
||||
}
|
||||
});
|
||||
|
||||
Moderation.checkMessage(await response);
|
||||
const response = requestReply(message, {content: answerContent}, {allowedMentions: { repliedUser: false }});
|
||||
|
||||
response.then(rval => Moderation.checkMessage(rval));
|
||||
}
|
||||
else {
|
||||
if (message instanceof DiscordApi.Message) message.react("😶");
|
||||
|
@ -167,15 +189,17 @@ async function executeFromQueue(channel: string) {
|
|||
console.error(`Error ocurred while handling chat completion request (${(e as object).constructor.name}):`);
|
||||
console.error(e);
|
||||
|
||||
message.reply({
|
||||
requestReply(
|
||||
message,
|
||||
{
|
||||
embeds: [{
|
||||
color: 0xff0000,
|
||||
description: "Something bad happened! :frowning:"
|
||||
}],
|
||||
allowedMentions: {
|
||||
repliedUser: false,
|
||||
}
|
||||
});
|
||||
},
|
||||
{allowedMentions: { repliedUser: false } },
|
||||
{ ephemeral: true },
|
||||
);
|
||||
}
|
||||
|
||||
channelQueue.shift();
|
||||
|
|
Loading…
Reference in a new issue