Skip to content

Commit 3c4736c

Browse files
authored
fix: improve format checker logs (#31)
- do not use "name" field with Pino (it is special, for the application name) - log user's name and tag and message content - do not log when failed to send private message because of privacy settings
1 parent 8d0ed7d commit 3c4736c

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/framework/Cron.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class Cron extends Base {
5555
const logger = bot.logger.child({
5656
id: randomUUID(),
5757
type: 'Cron',
58-
name: this.name,
58+
cronName: this.name,
5959
});
6060
try {
6161
logger.debug('execute cron handler');

src/framework/FormatChecker.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,20 @@ export class FormatChecker extends Base {
4747
const logger = this.bot.logger.child({
4848
id: randomUUID(),
4949
type: 'FormatChecker',
50-
name: this.name,
50+
checkerName: this.name,
5151
});
5252

5353
if (this.checker instanceof RegExp) {
5454
if (this.checker.test(message.cleanContent)) return;
5555
} else if (this.checker(message, logger)) return;
5656

57-
logger.debug('bad format detected');
58-
5957
const { cleanContent, author } = message;
6058

59+
logger.info(
60+
{ userId: author.id, userTag: author.tag, cleanContent },
61+
'Detected bad message format',
62+
);
63+
6164
await message.delete();
6265
const plural = this.examples !== undefined && this.examples.length > 1;
6366
const pluralSuffix = plural ? 's' : '';
@@ -78,11 +81,14 @@ export class FormatChecker extends Base {
7881
try {
7982
await author.send(`Bonjour,\n${warningContent}`);
8083
} catch (err) {
81-
logger.error(
82-
err,
83-
'failed to send private message to user %s',
84-
author.tag,
85-
);
84+
if (err.code !== 50007 /* Cannot send messages to this user */) {
85+
logger.error(
86+
err,
87+
'failed to send private message to user %s (id: %s)',
88+
author.tag,
89+
author.id,
90+
);
91+
}
8692
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
8793
const channel = findTextChannelByName(message.guild!.channels, 'logs');
8894
if (channel === undefined)

0 commit comments

Comments
 (0)