mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 04:25:01 +00:00
fix: fix error handling in InternalPoster.sendMessage direct sends
This commit is contained in:
parent
4179bc4ee1
commit
fe63ec9d77
3 changed files with 21 additions and 13 deletions
|
@ -29,10 +29,14 @@ export class Queue<TQueueFunction extends AnyFn = AnyFn> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public add(fn: TQueueFunction): Promise<any> {
|
public add(fn: TQueueFunction): Promise<any> {
|
||||||
const promise = new Promise<any>((resolve) => {
|
const promise = new Promise<any>((resolve, reject) => {
|
||||||
this.queue.push(async () => {
|
this.queue.push(async () => {
|
||||||
const result = await fn();
|
try {
|
||||||
resolve(result);
|
const result = await fn();
|
||||||
|
resolve(result);
|
||||||
|
} catch (err) {
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!this.running) this.next();
|
if (!this.running) this.next();
|
||||||
|
|
|
@ -24,7 +24,7 @@ export async function postToCaseLogChannel(
|
||||||
// This doesn't use `!isText() || isThread()` because TypeScript had some issues inferring types from it
|
// This doesn't use `!isText() || isThread()` because TypeScript had some issues inferring types from it
|
||||||
if (!caseLogChannel || !(caseLogChannel instanceof TextChannel || caseLogChannel instanceof NewsChannel)) return null;
|
if (!caseLogChannel || !(caseLogChannel instanceof TextChannel || caseLogChannel instanceof NewsChannel)) return null;
|
||||||
|
|
||||||
let result;
|
let result: InternalPosterMessageResult | null = null;
|
||||||
try {
|
try {
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
content.files = file;
|
content.files = file;
|
||||||
|
|
|
@ -10,6 +10,16 @@ export type InternalPosterMessageResult = {
|
||||||
channelId: string;
|
channelId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function sendDirectly(
|
||||||
|
channel: TextChannel | NewsChannel,
|
||||||
|
content: MessageOptions,
|
||||||
|
): Promise<InternalPosterMessageResult | null> {
|
||||||
|
return channel.send(content).then((message) => ({
|
||||||
|
id: message.id,
|
||||||
|
channelId: message.channelId,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a message using a webhook or direct API requests, preferring webhooks when possible.
|
* Sends a message using a webhook or direct API requests, preferring webhooks when possible.
|
||||||
*/
|
*/
|
||||||
|
@ -17,7 +27,7 @@ export async function sendMessage(
|
||||||
pluginData: GuildPluginData<InternalPosterPluginType>,
|
pluginData: GuildPluginData<InternalPosterPluginType>,
|
||||||
channel: TextChannel | NewsChannel,
|
channel: TextChannel | NewsChannel,
|
||||||
content: MessageOptions,
|
content: MessageOptions,
|
||||||
): Promise<InternalPosterMessageResult> {
|
): Promise<InternalPosterMessageResult | null> {
|
||||||
return pluginData.state.queue.add(async () => {
|
return pluginData.state.queue.add(async () => {
|
||||||
if (!pluginData.state.webhookClientCache.has(channel.id)) {
|
if (!pluginData.state.webhookClientCache.has(channel.id)) {
|
||||||
const webhookInfo = await getOrCreateWebhookForChannel(pluginData, channel);
|
const webhookInfo = await getOrCreateWebhookForChannel(pluginData, channel);
|
||||||
|
@ -53,19 +63,13 @@ export async function sendMessage(
|
||||||
pluginData.state.webhookClientCache.delete(channel.id);
|
pluginData.state.webhookClientCache.delete(channel.id);
|
||||||
|
|
||||||
// Fallback to regular message for this log message
|
// Fallback to regular message for this log message
|
||||||
return channel.send(content).then((message) => ({
|
return sendDirectly(channel, content);
|
||||||
id: message.id,
|
|
||||||
channelId: message.channelId,
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return channel.send(content).then((message) => ({
|
return sendDirectly(channel, content);
|
||||||
id: message.id,
|
|
||||||
channelId: message.channelId,
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue