koishi-plugin-bcjh-logs 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/index.js +11 -5
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -31,11 +31,11 @@ var Config = import_koishi.Schema.object({});
31
31
  function apply(ctx) {
32
32
  const logger = ctx.logger("bcjh-logs");
33
33
  ctx.middleware(async (session, next) => {
34
+ const isPrivate = !session.guildId;
34
35
  let atSelf = false;
35
- const botId = session.bot?.selfId;
36
- const mentioned = session.mentioned;
37
- if (typeof mentioned === "boolean") {
38
- atSelf = mentioned;
36
+ const botId = session.bot.selfId;
37
+ if (typeof session.mentioned === "boolean") {
38
+ atSelf = session.mentioned;
39
39
  } else {
40
40
  const elements = session.elements || [];
41
41
  for (const el of elements) {
@@ -49,13 +49,19 @@ function apply(ctx) {
49
49
  let content = stripped?.content || session.content || "";
50
50
  content = content.replace(/\n/g, "\\n + ");
51
51
  const userId = session.userId || "-";
52
+ const username = session.username || "-";
52
53
  const channelId = session.channelId || "-";
53
54
  const guildId = session.guildId || "-";
54
55
  const platform = session.platform || "-";
55
56
  const green = "\x1B[32m";
56
57
  const yellow = "\x1B[33m";
57
58
  const reset = "\x1B[0m";
58
- const logMessage = `{atSelf:${yellow}${atSelf}${reset},content:‘${green}${content}${reset}’,用户:${yellow}${userId}${reset},频道:${yellow}${channelId}${reset},群组:${yellow}${guildId}${reset},平台:${yellow}${platform}${reset}}`;
59
+ let logMessage;
60
+ if (isPrivate) {
61
+ logMessage = `{atSelf:${yellow}${atSelf}${reset},content:‘${green}${content}${reset}’,用户:${yellow}${userId}${reset},频道:${yellow}${channelId}${reset},群组:${yellow}${guildId}${reset},平台:${yellow}${platform}${reset}}`;
62
+ } else {
63
+ logMessage = `{atSelf:${yellow}${atSelf}${reset},content:‘${green}${content}${reset}’,昵称:${yellow}${username}${reset},用户:${yellow}${userId}${reset},频道:${yellow}${channelId}${reset},群组:${yellow}${guildId}${reset},平台:${yellow}${platform}${reset}}`;
64
+ }
59
65
  logger.info(logMessage);
60
66
  return next();
61
67
  }, true);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-bcjh-logs",
3
3
  "description": "bcjh自用",
4
- "version": "0.0.7",
4
+ "version": "0.0.9",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -15,6 +15,6 @@
15
15
  "plugin"
16
16
  ],
17
17
  "peerDependencies": {
18
- "koishi": "4.18.11"
18
+ "koishi": "^4.18.11"
19
19
  }
20
20
  }