3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

fix: only retry reminders in case of HTTP errors

Doesn't make a lot of sense to keep trying to e.g. post a reminder in
a deleted channel or a channel we have no perms to post in.
This commit is contained in:
Dragory 2022-05-12 21:38:01 +03:00
parent 7faa211d49
commit 10c107d5d9
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -1,10 +1,10 @@
import { GuildPluginData } from "knub";
import { RemindersPluginType } from "../types";
import { Reminder } from "../../../data/entities/Reminder";
import { Snowflake, TextChannel } from "discord.js";
import { DiscordAPIError, HTTPError, Snowflake, TextChannel } from "discord.js";
import moment from "moment-timezone";
import { disableLinkPreviews } from "knub/dist/helpers";
import { DBDateFormat, SECONDS } from "../../../utils";
import { DBDateFormat, isDiscordHTTPError, SECONDS } from "../../../utils";
import humanizeDuration from "humanize-duration";
export async function postReminder(pluginData: GuildPluginData<RemindersPluginType>, reminder: Reminder) {
@ -31,10 +31,13 @@ export async function postReminder(pluginData: GuildPluginData<RemindersPluginTy
});
}
} catch (err) {
// If we were unable to post the reminder, we'll try again later
// tslint:disable-next-line:no-console
console.warn(`Error when posting reminder for ${reminder.user_id} in guild ${reminder.guild_id}: ${String(err)}`);
return;
if (err instanceof HTTPError && err.code >= 500) {
// If we get a server error, try again later
return;
}
}
}