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.
- package/lib/index.js +12 -19
- 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
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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("
|
|
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");
|