update api roll to use resolve instead of old respondWith
This commit is contained in:
parent
5e14b4207e
commit
dff1e97186
|
@ -94,14 +94,17 @@ export const apiRoll = async (query: Map<string, string>, apiUserid: bigint): Pr
|
||||||
apiWarn: hideWarn ? '' : apiWarning,
|
apiWarn: hideWarn ? '' : apiWarning,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse the roll and get the return text
|
return new Promise<Response>((resolve) => {
|
||||||
await queueRoll({
|
queueRoll({
|
||||||
apiRoll: true,
|
apiRoll: true,
|
||||||
api: { channelId: BigInt(query.get('channel') || '0'), userId: BigInt(query.get('user') || '') },
|
api: { resolve, channelId: BigInt(query.get('channel') || '0'), userId: BigInt(query.get('user') || '') },
|
||||||
rollCmd,
|
rollCmd,
|
||||||
modifiers,
|
modifiers,
|
||||||
originalCommand,
|
originalCommand,
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Parse the roll and get the return text
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Handle any errors we missed
|
// Handle any errors we missed
|
||||||
log(LT.ERROR, `Unhandled Error: ${JSON.stringify(err)}`);
|
log(LT.ERROR, `Unhandled Error: ${JSON.stringify(err)}`);
|
||||||
|
|
|
@ -34,6 +34,7 @@ interface QueuedRoll {
|
||||||
export interface ApiQueuedRoll extends QueuedRoll {
|
export interface ApiQueuedRoll extends QueuedRoll {
|
||||||
apiRoll: true;
|
apiRoll: true;
|
||||||
api: {
|
api: {
|
||||||
|
resolve: (value: Response | PromiseLike<Response>) => void;
|
||||||
channelId: bigint;
|
channelId: bigint;
|
||||||
userId: bigint;
|
userId: bigint;
|
||||||
};
|
};
|
||||||
|
|
|
@ -35,7 +35,7 @@ const handleRollWorker = async (rq: ApiQueuedRoll | DDQueuedRoll) => {
|
||||||
rollWorker.terminate();
|
rollWorker.terminate();
|
||||||
currentWorkers--;
|
currentWorkers--;
|
||||||
if (rq.apiRoll) {
|
if (rq.apiRoll) {
|
||||||
rq.api.requestEvent.respondWith(stdResp.RequestTimeout('Roll took too long to process, try breaking roll down into simpler parts'));
|
rq.api.resolve(stdResp.RequestTimeout('Roll took too long to process, try breaking roll down into simpler parts'));
|
||||||
} else {
|
} else {
|
||||||
rq.dd.m
|
rq.dd.m
|
||||||
.edit({
|
.edit({
|
||||||
|
@ -77,7 +77,7 @@ const handleRollWorker = async (rq: ApiQueuedRoll | DDQueuedRoll) => {
|
||||||
// If there was an error, report it to the user in hopes that they can determine what they did wrong
|
// If there was an error, report it to the user in hopes that they can determine what they did wrong
|
||||||
if (returnmsg.error) {
|
if (returnmsg.error) {
|
||||||
if (rq.apiRoll) {
|
if (rq.apiRoll) {
|
||||||
rq.api.requestEvent.respondWith(stdResp.InternalServerError(returnmsg.errorMsg));
|
rq.api.resolve(stdResp.InternalServerError(returnmsg.errorMsg));
|
||||||
} else {
|
} else {
|
||||||
rq.dd.m.edit({ embeds: [pubEmbedDetails.embed] });
|
rq.dd.m.edit({ embeds: [pubEmbedDetails.embed] });
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ const handleRollWorker = async (rq: ApiQueuedRoll | DDQueuedRoll) => {
|
||||||
.catch((e) => utils.commonLoggers.dbError('rollQueue.ts:82', 'insert into', e));
|
.catch((e) => utils.commonLoggers.dbError('rollQueue.ts:82', 'insert into', e));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let n: DiscordenoMessage | void;
|
let n: DiscordenoMessage | void = undefined;
|
||||||
// Determine if we are to send a GM roll or a normal roll
|
// Determine if we are to send a GM roll or a normal roll
|
||||||
if (rq.modifiers.gmRoll) {
|
if (rq.modifiers.gmRoll) {
|
||||||
if (rq.apiRoll) {
|
if (rq.apiRoll) {
|
||||||
|
@ -98,7 +98,7 @@ const handleRollWorker = async (rq: ApiQueuedRoll | DDQueuedRoll) => {
|
||||||
embeds: [pubEmbedDetails.embed],
|
embeds: [pubEmbedDetails.embed],
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
apiErroredOut = true;
|
apiErroredOut = true;
|
||||||
rq.api.requestEvent.respondWith(stdResp.InternalServerError('Message failed to send - location 0.'));
|
rq.api.resolve(stdResp.InternalServerError('Message failed to send - location 0.'));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Send the public embed to correct channel
|
// Send the public embed to correct channel
|
||||||
|
@ -121,7 +121,7 @@ const handleRollWorker = async (rq: ApiQueuedRoll | DDQueuedRoll) => {
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
if (n && rq.apiRoll) {
|
if (n && rq.apiRoll) {
|
||||||
n.reply(generateDMFailed(gm));
|
n.reply(generateDMFailed(gm));
|
||||||
} else {
|
} else if (!rq.apiRoll) {
|
||||||
rq.dd.message.reply(generateDMFailed(gm));
|
rq.dd.message.reply(generateDMFailed(gm));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -130,7 +130,7 @@ const handleRollWorker = async (rq: ApiQueuedRoll | DDQueuedRoll) => {
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
if (rq.apiRoll && n) {
|
if (rq.apiRoll && n) {
|
||||||
n.reply(generateDMFailed(gm));
|
n.reply(generateDMFailed(gm));
|
||||||
} else {
|
} else if (!rq.apiRoll) {
|
||||||
rq.dd.message.reply(generateDMFailed(gm));
|
rq.dd.message.reply(generateDMFailed(gm));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -144,7 +144,7 @@ const handleRollWorker = async (rq: ApiQueuedRoll | DDQueuedRoll) => {
|
||||||
embeds: rq.modifiers.count ? [pubEmbedDetails.embed, countEmbed] : [pubEmbedDetails.embed],
|
embeds: rq.modifiers.count ? [pubEmbedDetails.embed, countEmbed] : [pubEmbedDetails.embed],
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
apiErroredOut = true;
|
apiErroredOut = true;
|
||||||
rq.api.requestEvent.respondWith(stdResp.InternalServerError('Message failed to send - location 1.'));
|
rq.api.resolve(stdResp.InternalServerError('Message failed to send - location 1.'));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
n = await rq.dd.m.edit({
|
n = await rq.dd.m.edit({
|
||||||
|
@ -165,7 +165,7 @@ const handleRollWorker = async (rq: ApiQueuedRoll | DDQueuedRoll) => {
|
||||||
.execute(queries.insertRollLogCmd(1, 0), [rq.originalCommand, returnmsg.errorCode, n ? n.id : null])
|
.execute(queries.insertRollLogCmd(1, 0), [rq.originalCommand, returnmsg.errorCode, n ? n.id : null])
|
||||||
.catch((e) => utils.commonLoggers.dbError('rollQueue.ts:155', 'insert into', e));
|
.catch((e) => utils.commonLoggers.dbError('rollQueue.ts:155', 'insert into', e));
|
||||||
|
|
||||||
rq.api.requestEvent.respondWith(
|
rq.api.resolve(
|
||||||
stdResp.OK(
|
stdResp.OK(
|
||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
rq.modifiers.count
|
rq.modifiers.count
|
||||||
|
@ -184,7 +184,7 @@ const handleRollWorker = async (rq: ApiQueuedRoll | DDQueuedRoll) => {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(LT.ERROR, `Unddandled Error: ${JSON.stringify(e)}`);
|
log(LT.ERROR, `Unddandled Error: ${JSON.stringify(e)}`);
|
||||||
if (rq.apiRoll && !apiErroredOut) {
|
if (rq.apiRoll && !apiErroredOut) {
|
||||||
rq.api.requestEvent.respondWith(stdResp.InternalServerError(JSON.stringify(e)));
|
rq.api.resolve(stdResp.InternalServerError(JSON.stringify(e)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue