mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 14:11:50 +00:00
Improve error resilience with auto-reactions
This commit is contained in:
parent
249fff259b
commit
9aeae4f89e
1 changed files with 40 additions and 7 deletions
|
@ -128,14 +128,25 @@ export class AutoReactionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
try {
|
try {
|
||||||
realMsg = await this.bot.getMessage(msg.channel_id, msg.id);
|
realMsg = await this.bot.getMessage(msg.channel_id, msg.id);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof DiscordRESTError && e.code === 10008) {
|
if (e instanceof DiscordRESTError) {
|
||||||
// Unknown message, post warning in logs
|
|
||||||
logger.warn(
|
logger.warn(
|
||||||
`Could not apply auto-reactions to ${msg.channel_id}/${msg.id} in guild ${this.guild.name} (${this.guildId}) (error code 10008)`,
|
`Could not load auto-reaction message ${msg.channel_id}/${msg.id} in guild ${this.guild.name} (${this.guildId}) (error code ${e.code})`,
|
||||||
);
|
);
|
||||||
this.logs.log(LogType.BOT_ALERT, {
|
|
||||||
body: `Could not apply auto-reactions in <#${msg.channel_id}> for message \`${msg.id}\`. Make sure the bot has **Read Message History** permissions on the channel.`,
|
if (e.code === 50001) {
|
||||||
});
|
// Missing access
|
||||||
|
this.logs.log(LogType.BOT_ALERT, {
|
||||||
|
body: `Could not load auto-reaction message \`${msg.id}\` in <#${msg.channel_id}>. Make sure the bot has **Read Message History** permissions on the channel.`,
|
||||||
|
});
|
||||||
|
} else if (e.code === 10008) {
|
||||||
|
this.logs.log(LogType.BOT_ALERT, {
|
||||||
|
body: `Could not load auto-reaction message \`${msg.id}\` in <#${msg.channel_id}>. Make sure nothing is deleting the message immediately.`,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.logs.log(LogType.BOT_ALERT, {
|
||||||
|
body: `Could not load auto-reaction message \`${msg.id}\` in <#${msg.channel_id}>. Error code ${e.code}.`,
|
||||||
|
});
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -143,7 +154,29 @@ export class AutoReactionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const reaction of autoReaction.reactions) {
|
for (const reaction of autoReaction.reactions) {
|
||||||
realMsg.addReaction(reaction);
|
try {
|
||||||
|
await realMsg.addReaction(reaction);
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof DiscordRESTError) {
|
||||||
|
logger.warn(
|
||||||
|
`Could not apply auto-reaction to ${msg.channel_id}/${msg.id} in guild ${this.guild.name} (${this.guildId}) (error code ${e.code})`,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (e.code === 10008) {
|
||||||
|
this.logs.log(LogType.BOT_ALERT, {
|
||||||
|
body: `Could not apply auto-reactions in <#${msg.channel_id}> for message \`${msg.id}\`. Make sure nothing is deleting the message before the reactions are applied.`,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.logs.log(LogType.BOT_ALERT, {
|
||||||
|
body: `Could not apply auto-reactions in <#${msg.channel_id}> for message \`${msg.id}\`. Error code ${e.code}.`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue