koishi-plugin-xxpk-1 0.0.2 → 0.0.4

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 +12 -19
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -34,31 +34,24 @@ var Config = import_koishi.Schema.object({
34
34
  });
35
35
  function apply(ctx, config) {
36
36
  const logger = ctx.logger("poke-reply");
37
- ctx.on("notice/poke", async (raw) => {
38
- const s = raw;
39
- if (s.targetId !== s.selfId) return;
40
- logger.info(`[poke-reply] 收到戳一戳 | 用户:${s.userId}`);
37
+ ctx.on("notice.notify", (payload) => {
38
+ if (payload.sub_type !== "poke") return;
39
+ const { user_id, target_id, self_id, group_id } = payload;
40
+ if (target_id !== self_id) return;
41
41
  const reply = config.replies[Math.floor(Math.random() * config.replies.length)];
42
42
  if (config.pokeBack && Math.random() < config.pokeProb) {
43
+ const bot = ctx.bots[self_id];
44
+ if (!bot) return;
43
45
  try {
44
- if (s.guildId) {
45
- await s.bot.sendAction("group_poke", {
46
- group_id: s.guildId,
47
- user_id: s.userId
48
- });
49
- } else {
50
- await s.bot.sendAction("friend_poke", {
51
- user_id: s.userId
52
- });
53
- }
54
- logger.info(`[poke-reply] 成功戳回 ${s.userId}`);
46
+ const pokeMsg = "[CQ:poke,type=126,id=2003]";
47
+ group_id ? bot.sendMessage(group_id, pokeMsg) : bot.sendPrivateMessage(user_id, pokeMsg);
48
+ logger.info(`戳回用户:${user_id}`);
55
49
  } catch (e) {
56
- logger.error("[poke-reply] 戳回失败", e);
57
- await s.send(reply);
50
+ logger.error("戳回失败", e);
58
51
  }
59
- } else {
60
- await s.send(reply);
61
52
  }
53
+ if (group_id) ctx.bots[self_id]?.sendMessage(group_id, reply);
54
+ else ctx.bots[self_id]?.sendPrivateMessage(user_id, reply);
62
55
  });
63
56
  }
64
57
  __name(apply, "apply");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-xxpk-1",
3
3
  "description": "[开发中]",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [