3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-18 07:35:02 +00:00

Add a generic bot alert log type. Use this in several places.

This commit is contained in:
Dragory 2019-05-04 19:18:16 +03:00
parent 718029e9a5
commit c7fc789c1e
8 changed files with 110 additions and 27 deletions

View file

@ -152,16 +152,26 @@ export class PostPlugin extends ZeppelinPlugin<IPostPluginConfig> {
for (const post of duePosts) {
const channel = this.guild.channels.get(post.channel_id);
if (channel instanceof TextChannel) {
const [username, discriminator] = post.author_name.split("#");
const author: Partial<User> = this.bot.users.get(post.author_id) || {
id: post.author_id,
username,
discriminator,
};
try {
const postedMessage = await this.postMessage(channel, post.content, post.attachments, post.enable_mentions);
const [username, discriminator] = post.author_name.split("#");
this.logs.log(LogType.POSTED_SCHEDULED_MESSAGE, {
author: ({ id: post.author_id, username, discriminator } as any) as Partial<User>,
author: stripObjectToScalars(author),
channel: stripObjectToScalars(channel),
messageId: postedMessage.id,
});
} catch (e) {
this.logs.log(LogType.BOT_ALERT, {
body: `Failed to post scheduled message by {userMention(author)} to {channelMention(channel)}`,
channel: stripObjectToScalars(channel),
author: stripObjectToScalars(author),
});
logger.warn(
`Failed to post scheduled message to #${channel.name} (${channel.id}) on ${this.guild.name} (${
this.guildId