kotori-plugin-requester 1.1.1 → 1.1.2

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.
package/lib/index.d.ts CHANGED
@@ -1,21 +1,22 @@
1
- import { Context, Tsu } from 'kotori-bot';
1
+ import { type Context, Tsu } from 'kotori-bot';
2
2
  export declare const lang: string[];
3
3
  export declare const config: import("kotori-bot").ObjectParser<{
4
- print: import("kotori-bot").BooleanParser;
5
- filterCmd: import("kotori-bot").BooleanParser;
6
- onHttpRequest: import("kotori-bot").UnionParser<[import("kotori-bot").BooleanParser, import("kotori-bot").CustomParser<("get" | "options" | "delete" | "head" | "post" | "put" | "patch" | "ws")[]>]>;
7
- onRegexp: import("kotori-bot").BooleanParser;
8
- onCommand: import("kotori-bot").BooleanParser;
9
- onBotGroupIncrease: import("kotori-bot").BooleanParser;
10
- onBotGroupDecrease: import("kotori-bot").BooleanParser;
11
- onBotGroupAdmin: import("kotori-bot").BooleanParser;
12
- onBotGroupBan: import("kotori-bot").BooleanParser;
13
- onGroupRecall: import("kotori-bot").BooleanParser;
14
- onPrivateRecall: import("kotori-bot").BooleanParser;
15
- onGroupRequest: import("kotori-bot").BooleanParser;
16
- onPrivateRequest: import("kotori-bot").BooleanParser;
17
- onGroupMsg: import("kotori-bot").BooleanParser;
18
- onPrivateMsg: import("kotori-bot").BooleanParser;
4
+ print: import("kotori-bot").Parser<boolean>;
5
+ notify: import("kotori-bot").Parser<boolean>;
6
+ filterCmd: import("kotori-bot").Parser<boolean>;
7
+ onHttpRequest: import("kotori-bot").Parser<boolean | ("get" | "options" | "delete" | "head" | "post" | "put" | "patch" | "ws")[]>;
8
+ onRegexp: import("kotori-bot").Parser<boolean>;
9
+ onCommand: import("kotori-bot").Parser<boolean>;
10
+ onBotGroupIncrease: import("kotori-bot").Parser<boolean>;
11
+ onBotGroupDecrease: import("kotori-bot").Parser<boolean>;
12
+ onBotGroupAdmin: import("kotori-bot").Parser<boolean>;
13
+ onBotGroupBan: import("kotori-bot").Parser<boolean>;
14
+ onGroupRecall: import("kotori-bot").Parser<boolean>;
15
+ onPrivateRecall: import("kotori-bot").Parser<boolean>;
16
+ onGroupRequest: import("kotori-bot").Parser<boolean>;
17
+ onPrivateRequest: import("kotori-bot").Parser<boolean>;
18
+ onGroupMsg: import("kotori-bot").Parser<boolean>;
19
+ onPrivateMsg: import("kotori-bot").Parser<boolean>;
19
20
  }>;
20
21
  export declare const inject: string[];
21
22
  export declare function main(ctx: Context, cfg: Tsu.infer<typeof config>): void;
package/lib/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
 
2
2
  /**
3
3
  * @Package kotori-plugin-requester
4
- * @Version 1.1.0
5
- * @Author Himeno <biyuehuya@gmail.com>
4
+ * @Version 1.1.2
5
+ * @Author Himeno <me@hotaru.icu>
6
6
  * @Copyright 2024 Hotaru. All rights reserved.
7
7
  * @License GPL-3.0
8
8
  * @Link https://github.com/kotorijs/kotori
9
- * @Date 2024/6/7 21:36:15
9
+ * @Date 2024/8/8 20:54:13
10
10
  */
11
11
 
12
12
  "use strict";
@@ -38,26 +38,27 @@ module.exports = __toCommonJS(src_exports);
38
38
  var import_kotori_bot = require("kotori-bot");
39
39
  const lang = [__dirname, "../locales"];
40
40
  const config = import_kotori_bot.Tsu.Object({
41
- print: import_kotori_bot.Tsu.Boolean().default(true),
42
- filterCmd: import_kotori_bot.Tsu.Boolean().default(true),
43
- onHttpRequest: import_kotori_bot.Tsu.Union([
41
+ print: import_kotori_bot.Tsu.Boolean().default(true).describe("Whether to print the log"),
42
+ notify: import_kotori_bot.Tsu.Boolean().default(true).describe("Whether to send message to master"),
43
+ filterCmd: import_kotori_bot.Tsu.Boolean().default(true).describe("Filter message about command"),
44
+ onHttpRequest: import_kotori_bot.Tsu.Union(
44
45
  import_kotori_bot.Tsu.Boolean(),
45
46
  import_kotori_bot.Tsu.Custom(
46
- (input) => Array.isArray(input) && input.filter((el) => !["get", "post", "put", "delete", "patch", "head", "options", "ws"].includes(String(el))).length === 0
47
+ (input) => Array.isArray(input) && input.every((el) => ["get", "post", "put", "delete", "patch", "head", "options", "ws"].includes(String(el)))
47
48
  )
48
- ]).default(["get", "post", "put", "delete", "patch"]),
49
- onRegexp: import_kotori_bot.Tsu.Boolean().default(true),
50
- onCommand: import_kotori_bot.Tsu.Boolean().default(true),
51
- onBotGroupIncrease: import_kotori_bot.Tsu.Boolean().default(true),
52
- onBotGroupDecrease: import_kotori_bot.Tsu.Boolean().default(true),
53
- onBotGroupAdmin: import_kotori_bot.Tsu.Boolean().default(true),
54
- onBotGroupBan: import_kotori_bot.Tsu.Boolean().default(true),
55
- onGroupRecall: import_kotori_bot.Tsu.Boolean().default(true),
56
- onPrivateRecall: import_kotori_bot.Tsu.Boolean().default(true),
57
- onGroupRequest: import_kotori_bot.Tsu.Boolean().default(true),
58
- onPrivateRequest: import_kotori_bot.Tsu.Boolean().default(true),
59
- onGroupMsg: import_kotori_bot.Tsu.Boolean().default(true),
60
- onPrivateMsg: import_kotori_bot.Tsu.Boolean().default(true)
49
+ ).default(["get", "post", "put", "delete", "patch"]).describe("Whether to listen to http request (only print)"),
50
+ onRegexp: import_kotori_bot.Tsu.Boolean().default(true).describe("Whether to listen to regexp (only print)"),
51
+ onCommand: import_kotori_bot.Tsu.Boolean().default(true).describe("Whether to listen to command (only print)"),
52
+ onBotGroupIncrease: import_kotori_bot.Tsu.Boolean().default(true).describe("Whether to listen to bot group increase"),
53
+ onBotGroupDecrease: import_kotori_bot.Tsu.Boolean().default(true).describe("Whether to listen to bot group decrease"),
54
+ onBotGroupAdmin: import_kotori_bot.Tsu.Boolean().default(true).describe("Whether to listen to bot group admin"),
55
+ onBotGroupBan: import_kotori_bot.Tsu.Boolean().default(true).describe("Whether to listen to bot group ban"),
56
+ onGroupRecall: import_kotori_bot.Tsu.Boolean().default(true).describe("Whether to listen to group recall"),
57
+ onPrivateRecall: import_kotori_bot.Tsu.Boolean().default(true).describe("Whether to listen to private recall"),
58
+ onGroupRequest: import_kotori_bot.Tsu.Boolean().default(true).describe("Whether to listen to group request"),
59
+ onPrivateRequest: import_kotori_bot.Tsu.Boolean().default(true).describe("Whether to listen to private request"),
60
+ onGroupMsg: import_kotori_bot.Tsu.Boolean().default(true).describe("Whether to listen to group message"),
61
+ onPrivateMsg: import_kotori_bot.Tsu.Boolean().default(true).describe("Whether to listen to private message")
61
62
  });
62
63
  const inject = ["cache"];
63
64
  function main(ctx, cfg) {
@@ -72,14 +73,14 @@ function main(ctx, cfg) {
72
73
  session.api.adapter.config.master
73
74
  );
74
75
  log(
75
- session.api.adapter.identity,
76
- isString ? session.i18n.locale(msg.replace(".msg.", ".log.")) : session.format(msg[0].replace(".msg.", ".log."), msg[1])
76
+ `${session.api.adapter.platform}/${session.api.adapter.identity}`,
77
+ isString ? session.i18n.locale(msg.replace(".msg.", ".log.")) : session.format(msg[0].replace(".msg.", ".log."), msg[1]).toString()
77
78
  );
78
79
  };
79
80
  if (cfg.onBotGroupIncrease) {
80
81
  ctx.on("on_group_increase", (session) => {
81
82
  if (session.userId !== session.api.adapter.selfId) return;
82
- send(session)([`requester.msg.increase`, [session.groupId]]);
83
+ send(session)(["requester.msg.increase", [session.groupId]]);
83
84
  });
84
85
  }
85
86
  if (cfg.onBotGroupDecrease) {
@@ -95,7 +96,7 @@ function main(ctx, cfg) {
95
96
  if (cfg.onBotGroupAdmin) {
96
97
  ctx.on("on_group_admin", (session) => {
97
98
  if (session.userId !== session.api.adapter.selfId) return;
98
- send(session)([`requester.msg.admin.${session.userId ? "set" : "unset"}`, [session.groupId]]);
99
+ send(session)([`requester.msg.admin.${session.operation}`, [session.groupId]]);
99
100
  });
100
101
  }
101
102
  if (cfg.onBotGroupBan) {
@@ -108,19 +109,19 @@ function main(ctx, cfg) {
108
109
  });
109
110
  }
110
111
  if (cfg.onPrivateRecall || cfg.onGroupRecall) {
111
- ctx.on("on_recall", (session) => {
112
+ ctx.on("on_message_delete", (session) => {
112
113
  if (session.userId === session.api.adapter.selfId || session.operatorId === session.api.adapter.selfId) return;
113
114
  if (cfg.onPrivateRecall && session.type === import_kotori_bot.MessageScope.PRIVATE) {
114
115
  const message = ctx.cache.get(`${session.api.adapter.identity}${session.messageId}`);
115
116
  if (!message) return;
116
- send(session)([`requester.msg.recall.private`, [session.userId, message]]);
117
+ send(session)(["requester.msg.recall.private", [session.userId, message]]);
117
118
  } else if (cfg.onGroupRecall && session.type === import_kotori_bot.MessageScope.GROUP) {
118
119
  const message = ctx.cache.get(`${session.api.adapter.identity}${session.messageId}`);
119
120
  if (!message) return;
120
121
  const equaled = session.operatorId === session.userId;
121
122
  send(session)([
122
123
  `requester.msg.recall.group.${equaled ? "self" : "other"}`,
123
- [session.userId, ...equaled ? [message, session.groupId] : [session.operatorId, message, session.groupId]]
124
+ [session.userId, ...equaled ? [session.groupId, message] : [session.operatorId, session.groupId, message]]
124
125
  ]);
125
126
  }
126
127
  });
@@ -128,9 +129,9 @@ function main(ctx, cfg) {
128
129
  if (cfg.onPrivateRequest || cfg.onGroupRequest) {
129
130
  ctx.on("on_request", (session) => {
130
131
  if (cfg.onPrivateRequest && session.type === import_kotori_bot.MessageScope.PRIVATE) {
131
- send(session)([`requester.msg.request.private`, [session.userId]]);
132
+ send(session)(["requester.msg.request.private", [session.userId]]);
132
133
  } else if (cfg.onGroupMsg && session.type === import_kotori_bot.MessageScope.GROUP) {
133
- send(session)([`requester.msg.request.group`, [session.userId, session.groupId]]);
134
+ send(session)(["requester.msg.request.group", [session.userId, session.groupId]]);
134
135
  }
135
136
  });
136
137
  }
@@ -139,11 +140,12 @@ function main(ctx, cfg) {
139
140
  if (session.userId === session.api.adapter.selfId) return;
140
141
  if (session.type === import_kotori_bot.MessageScope.GROUP && cfg.onGroupRecall) {
141
142
  ctx.cache.set(`${session.api.adapter.identity}${session.messageId}`, session.message);
142
- } else if (cfg.onPrivateRecall) {
143
+ } else if (session.type === import_kotori_bot.MessageScope.PRIVATE && cfg.onPrivateRecall) {
143
144
  ctx.cache.set(`${session.api.adapter.identity}${session.messageId}`, session.message);
144
145
  }
145
- if (cfg.onPrivateMsg && String(session.userId) !== String(session.api.adapter.config.master)) {
146
- send(session)([`requester.msg.msg.private`, [session.userId, session.message]]);
146
+ if (session.userId !== session.api.adapter.config.master) return;
147
+ if (cfg.onPrivateMsg && session.type === import_kotori_bot.MessageScope.PRIVATE) {
148
+ send(session)(["requester.msg.msg.private", [session.userId, session.message]]);
147
149
  }
148
150
  });
149
151
  }
@@ -151,7 +153,7 @@ function main(ctx, cfg) {
151
153
  ctx.on(
152
154
  "command",
153
155
  ({ session, raw }) => log(
154
- session.api.adapter.identity,
156
+ `${session.api.adapter.platform}/${session.api.adapter.identity}`,
155
157
  session.format(`requester.log.command.${session.type === import_kotori_bot.MessageScope.GROUP ? "group" : "private"}`, [
156
158
  session.userId,
157
159
  raw,
@@ -164,7 +166,7 @@ function main(ctx, cfg) {
164
166
  ctx.on(
165
167
  "regexp",
166
168
  ({ session, raw }) => log(
167
- session.api.adapter.identity,
169
+ `${session.api.adapter.platform}/${session.api.adapter.identity}`,
168
170
  session.format(`requester.log.regexp.${session.type === import_kotori_bot.MessageScope.GROUP ? "group" : "private"}`, [
169
171
  session.userId,
170
172
  raw,
@@ -176,7 +178,7 @@ function main(ctx, cfg) {
176
178
  if (cfg.onHttpRequest) {
177
179
  const originHttp = ctx.root.http;
178
180
  const http = ctx.root.http;
179
- (cfg.onHttpRequest === true ? ["get", "post", "put", "delete", "patch", "head", "options", "ws"] : cfg.onHttpRequest).forEach((method) => {
181
+ for (const method of cfg.onHttpRequest === true ? ["get", "post", "put", "delete", "patch", "head", "options", "ws"] : cfg.onHttpRequest) {
180
182
  if (method === "ws") {
181
183
  http.ws = new Proxy(http.ws, {
182
184
  apply(target, thisArg, argArray) {
@@ -192,7 +194,7 @@ function main(ctx, cfg) {
192
194
  return Reflect.apply(target, thisArg, argArray);
193
195
  }
194
196
  });
195
- });
197
+ }
196
198
  }
197
199
  }
198
200
  // Annotate the CommonJS export names for ESM import in node:
@@ -4,7 +4,7 @@
4
4
  "requester.log.decrease.kick": "The BOT was kicked out of the group <bold>{1}</bold> by the administrator <bold>{0}</bold>",
5
5
  "requester.log.admin.set": "The BOT was set as the admin of the group <bold>{0}</bold>",
6
6
  "requester.log.admin.unset": "The BOT was removed from the admin position in the group <bold>{0}</bold>",
7
- "requester.log.ban.ban": "The BOT was muted by the administrator <bold>{0}</bold> for <bold>{1}</bold> minutes in the group <bold>{2}</bold>",
7
+ "requester.log.ban.ban": "The BOT was muted by the administrator <bold>{0}</bold> for <bold>{2}</bold> minutes in the group <bold>{1}</bold>",
8
8
  "requester.log.ban.lift_ban": "The mute on the BOT was lifted by the administrator <green>{0}</green> in the group <bold>{1}</bold>",
9
9
  "requester.log.recall.group.other": "User <bold>{0}</bold> had a message retracted by the administrator <bold>{1}</bold> in the group <bold>{2}</bold>: <green>{3}</green>",
10
10
  "requester.log.recall.group.self": "User <bold>{0}</bold> retracted a message in the group <bold>{1}</bold>: <green>{2}</green>",
@@ -4,7 +4,7 @@
4
4
  "requester.msg.decrease.kick": "BOT 被管理员 {0} 踢出了群 {1}",
5
5
  "requester.msg.admin.set": "BOT 被设置为群 {0} 的管理员",
6
6
  "requester.msg.admin.unset": "BOT 被取消了群 {0} 的管理员",
7
- "requester.msg.ban.ban": "BOT 被管理员 {0} 禁言了 {1} 分钟在群 {2}",
7
+ "requester.msg.ban.ban": "BOT 被管理员 {0} 禁言了 {2} 分钟在群 {1}",
8
8
  "requester.msg.ban.lift_ban": "BOT 被管理员 {0} 取消了禁言在群 {1}",
9
9
  "requester.msg.recall.group.other": "用户 {0} 被管理员 {1} 在群 {2} 撤回了消息:{3}",
10
10
  "requester.msg.recall.group.self": "用户 {0} 在群 {1} 撤回了消息:{2}",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kotori-plugin-requester",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Listen delete message and request event call to master",
5
5
  "main": "lib/index.js",
6
6
  "keywords": [
@@ -15,9 +15,9 @@
15
15
  "LICENSE",
16
16
  "README.md"
17
17
  ],
18
- "author": "Himeno <biyuehuya@gmail.com>",
18
+ "author": "Himeno <me@hotaru.icu>",
19
19
  "peerDependencies": {
20
- "kotori-bot": "^1.5.4"
20
+ "kotori-bot": "^1.6.0-rc.1"
21
21
  },
22
22
  "kotori": {
23
23
  "meta": {