Skip to content

Commit

Permalink
Don't log user info in command logs every time
Browse files Browse the repository at this point in the history
The user info is logged in the first seen of interaction, and the rest
log message should use the interaction id to keep track of every step,
so no need to log user info every time now.
  • Loading branch information
s25g5d4 committed Apr 10, 2022
1 parent 794eb19 commit 4fb0db7
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 32 deletions.
7 changes: 3 additions & 4 deletions src/commands/user/arrange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
UserProfile,
UserProfileRecord,
} from "src/models/user-profile";
import { logUser } from "src/utils/log-user";
import { polePosition } from "src/models/pole-position";
import { profileRatio } from "src/models/profile-ratio";
import { logUser } from "src/utils/log-user";
import { InteractiveCommand } from "../interactive-command";
import { CatchExecuteError } from "../catch-execute-error";
import {
Expand Down Expand Up @@ -114,12 +114,11 @@ export class ArrangePlayers extends InteractiveCommand {
const options = await this.parseOptions();

let { players } = options;
const { guild, user } = this.interaction;
const { guild } = this.interaction;
this.l.debug(
{
options: { players: players.map((p) => p.id) },
options: { players: logUser(players) },
mention: this.mention,
user: logUser(user),
},
"arrange players options"
);
Expand Down
8 changes: 2 additions & 6 deletions src/commands/user/profile/activate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { isNil } from "lodash";
import { Logger } from "pino";
import { formatUserProfile } from "src/models/user-profile";
import { UserProfileStore } from "src/store/user-profiles";
import { logUser } from "src/utils/log-user";
import { InteractiveCommand } from "../../interactive-command";
import { CatchExecuteError } from "../../catch-execute-error";
import {
Expand Down Expand Up @@ -57,10 +56,7 @@ export class ActivateProfile extends InteractiveCommand {

const { index } = options;
const { user, guild } = this.interaction;
this.l.debug(
{ options: { index }, user: logUser(user) },
"activate profile options"
);
this.l.debug({ options: { index } }, "activate profile options");

const record = await this.getUserProfileRecord(guild.id, user);
const i = index - 1;
Expand All @@ -72,7 +68,7 @@ export class ActivateProfile extends InteractiveCommand {
const newRecord: typeof record = { ...record, active: i };
await this.profileStore.set(guild.id, user.id, newRecord);

this.l.info({ user: logUser(user) }, "profile activated");
this.l.info("profile activated");
await this.interaction.reply(
[
`已更新使用中編組編號。使用中編組:`,
Expand Down
9 changes: 3 additions & 6 deletions src/commands/user/profile/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,15 @@ export class ListProfile extends InteractiveCommand {
const options = await this.parseOptions();

const { user: targetUser } = options;
const { user, guild } = this.interaction;
const { guild } = this.interaction;
this.l.debug(
{ options: { user: logUser(targetUser) }, user: logUser(user) },
{ options: { user: logUser(targetUser) } },
"list profile options"
);

const record = await this.getUserProfileRecord(guild.id, targetUser);

this.l.info(
{ user: logUser(user), targetUser: logUser(targetUser) },
"profile listed"
);
this.l.info("profile listed");
const userString = `${targetUser.username} (${targetUser})`;
await this.interaction.reply({
content: [
Expand Down
8 changes: 2 additions & 6 deletions src/commands/user/profile/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
isEmptyRecord,
} from "src/models/user-profile";
import { UserProfileStore } from "src/store/user-profiles";
import { logUser } from "src/utils/log-user";
import { InteractiveCommand } from "../../interactive-command";
import { CatchExecuteError } from "../../catch-execute-error";
import {
Expand Down Expand Up @@ -60,10 +59,7 @@ export class RemoveProfile extends InteractiveCommand {

const { index } = options;
const { user, guild } = this.interaction;
this.l.debug(
{ options: { index }, user: logUser(user) },
"remove profile options"
);
this.l.debug({ options: { index } }, "remove profile options");

const record = await this.getUserProfileRecord(guild.id, user);
const i = index - 1;
Expand All @@ -86,7 +82,7 @@ ${formatUserProfileRecord(newRecord)}
\`\`\`
`.trim();

this.l.info({ user: logUser(user) }, "profile removed");
this.l.info("profile removed");
await this.interaction.reply(reply);
}
}
5 changes: 2 additions & 3 deletions src/commands/user/profile/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
UserProfileType,
} from "src/models/user-profile";
import { UserProfileStore } from "src/store/user-profiles";
import { logUser } from "src/utils/log-user";
import { InteractiveCommand } from "../../interactive-command";
import { CatchExecuteError } from "../../catch-execute-error";
import {
Expand Down Expand Up @@ -120,7 +119,7 @@ export class UpdateProfile extends InteractiveCommand {
const { type, power, cards, index } = options;
const { user, guild } = this.interaction;
this.l.debug(
{ options: { type, power, cards, index }, user: logUser(user) },
{ options: { type, power, cards, index } },
"update profile options"
);

Expand All @@ -139,7 +138,7 @@ export class UpdateProfile extends InteractiveCommand {
record = { ...record, profiles: newProfiles };
await this.profileStore.set(guild.id, user.id, record);

this.l.info({ user: logUser(user) }, "profile updated");
this.l.info("profile updated");
await this.interaction.reply(
[
"已更新。你的編組資料:",
Expand Down
9 changes: 2 additions & 7 deletions src/commands/user/ratio-tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { CommandInteraction } from "discord.js";
import { Logger } from "pino";
import { parseCards } from "src/models/parse-cards";
import { profileRatio } from "src/models/profile-ratio";
import { logUser } from "src/utils/log-user";
import { CatchExecuteError } from "../catch-execute-error";
import { InteractiveCommand } from "../interactive-command";
import { InvalidOptionCardsError } from "./ratio-tw-errors";
Expand Down Expand Up @@ -38,13 +37,9 @@ export class RatioTW extends InteractiveCommand {

const options = await this.parseOptions();
const { ratio } = options;
const { user } = this.interaction;
this.l.debug(
{ options: { ratio }, user: logUser(user) },
"ratio-tw options"
);
this.l.debug({ options: { ratio } }, "ratio-tw options");

this.l.info({ user: logUser(user) }, "ratio-tw calculated");
this.l.info("ratio-tw calculated");
await this.interaction.reply(`此組卡片倍率為 ${ratio.toFixed(2)}。`);
}
}

0 comments on commit 4fb0db7

Please sign in to comment.