koishi-plugin-starfx-bot 0.9.0 → 0.10.0
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 +57 -15
- package/lib/utils.d.ts +1 -0
- package/package.json +1 -1
- package/readme.md +14 -12
package/lib/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
33
33
|
// src/locales/zh-CN.yml
|
|
34
34
|
var require_zh_CN = __commonJS({
|
|
35
35
|
"src/locales/zh-CN.yml"(exports2, module2) {
|
|
36
|
-
module2.exports = { commands: { roll: { messages: { noParam: "
|
|
36
|
+
module2.exports = { commands: { roll: { messages: { noParam: "你问啥?", invalid: "你要不看看你说的是啥", "too-many": "太、太多了啦!", noodles: "扔出了{num}个{noodles}面的骰子,点数如下:{points}", possibility: "{param}是{possibility}%", choose: "当然是{option}啦!" } } }, middleware: { messages: { atNotReply: "艾特我又不说话", atNotReplyOther: "艾特他又不说话", notBot: "我才不是机器人!", loveMessage: "我喜欢你", iLoveU: "我也喜欢你" } } };
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
|
|
@@ -368,6 +368,59 @@ function detectControl(controlJson, guildId, funName) {
|
|
|
368
368
|
return rule.whitelist ? inList : !inList;
|
|
369
369
|
}
|
|
370
370
|
__name(detectControl, "detectControl");
|
|
371
|
+
function handleRoll(session) {
|
|
372
|
+
const elements = session.elements;
|
|
373
|
+
let parts = [];
|
|
374
|
+
for (const element of elements) {
|
|
375
|
+
if (element?.type === "text") {
|
|
376
|
+
parts.push(...element.attrs.content.split(/(?:\s+)+/).filter(Boolean));
|
|
377
|
+
} else {
|
|
378
|
+
parts.push(element);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
const commandLength = parts[0].length;
|
|
382
|
+
console.log(parts);
|
|
383
|
+
parts.shift();
|
|
384
|
+
if (!parts) return session.text(".noParam");
|
|
385
|
+
const last = session.elements[session.elements.length - 1];
|
|
386
|
+
if (last?.type === "text" && last?.attrs?.content?.endsWith("的概率") && last?.attrs?.content?.length > 3) {
|
|
387
|
+
return session.text(".possibility", {
|
|
388
|
+
param: parts,
|
|
389
|
+
possibility: Math.floor(Math.random() * 1e4 + 1) / 100
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
const items = parts.join(" ").split("r");
|
|
393
|
+
if (items.length === 2) {
|
|
394
|
+
const [num, noodles] = items.map(Number);
|
|
395
|
+
return getPoints(session, num, noodles);
|
|
396
|
+
}
|
|
397
|
+
const newParts = [];
|
|
398
|
+
parts.forEach((element) => {
|
|
399
|
+
if (typeof element === "string") {
|
|
400
|
+
newParts.push(...element.split(/(?:、|还是|,|,)+/).filter(Boolean));
|
|
401
|
+
} else {
|
|
402
|
+
newParts.push(element);
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
if (newParts.length > 1) {
|
|
406
|
+
return session.text(".choose", {
|
|
407
|
+
option: import_koishi.Random.pick(newParts)
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
return session.text(".noParam");
|
|
411
|
+
}
|
|
412
|
+
__name(handleRoll, "handleRoll");
|
|
413
|
+
function getPoints(session, num, noodles) {
|
|
414
|
+
if (isNaN(num) || isNaN(noodles)) return session.text(".invalid");
|
|
415
|
+
if (num > 20 || noodles > 1e8) return session.text(".too-many");
|
|
416
|
+
const points = Array(num).fill(0).map(() => Math.floor(Math.random() * noodles + 1));
|
|
417
|
+
return session.text(".noodles", {
|
|
418
|
+
num,
|
|
419
|
+
noodles,
|
|
420
|
+
points: points.join(", ")
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
__name(getPoints, "getPoints");
|
|
371
424
|
|
|
372
425
|
// src/index.ts
|
|
373
426
|
var name = "starfx-bot";
|
|
@@ -386,7 +439,7 @@ var Config2 = import_koishi2.Schema.intersect([
|
|
|
386
439
|
//saveArchive: Schema.boolean().default(false).description('开启入典功能').hidden(),
|
|
387
440
|
}).description("语录记录功能"),
|
|
388
441
|
import_koishi2.Schema.object({
|
|
389
|
-
roll: import_koishi2.Schema.boolean().default(
|
|
442
|
+
roll: import_koishi2.Schema.boolean().default(true).description("开启roll随机数功能")
|
|
390
443
|
}).description("指令小功能"),
|
|
391
444
|
import_koishi2.Schema.object({
|
|
392
445
|
atNotSay: import_koishi2.Schema.boolean().default(true).description("开启‘艾特我又不说话’功能"),
|
|
@@ -427,20 +480,9 @@ function apply(ctx, cfg) {
|
|
|
427
480
|
});
|
|
428
481
|
}
|
|
429
482
|
if (cfg.roll) {
|
|
430
|
-
ctx.command("roll
|
|
483
|
+
ctx.command("roll").action(async ({ session }) => {
|
|
431
484
|
if (detectControl(controlJson, session.guildId, "roll")) {
|
|
432
|
-
|
|
433
|
-
if (param.endsWith("的概率")) {
|
|
434
|
-
}
|
|
435
|
-
const parts = param.split(/(?:\s+|还是)+/).filter(Boolean);
|
|
436
|
-
if (parts.length > 1) {
|
|
437
|
-
} else {
|
|
438
|
-
const items = param.split("r");
|
|
439
|
-
if (items.length === 2) {
|
|
440
|
-
const num = parseInt(items[0]);
|
|
441
|
-
const noodles = parseInt(items[1]);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
485
|
+
return handleRoll(session);
|
|
444
486
|
}
|
|
445
487
|
});
|
|
446
488
|
}
|
package/lib/utils.d.ts
CHANGED
|
@@ -128,4 +128,5 @@ export declare function drawBanGDream(avatar: string, inputOptions?: {
|
|
|
128
128
|
}): Promise<string>;
|
|
129
129
|
export declare function parseJsonControl(text: string): FeatureControl | null;
|
|
130
130
|
export declare function detectControl(controlJson: FeatureControl, guildId: string, funName: string): boolean;
|
|
131
|
+
export declare function handleRoll(session: Session): string;
|
|
131
132
|
export {};
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -49,6 +49,7 @@ StarFreedomX机器人的小功能,自用
|
|
|
49
49
|
| `replyBot` | “我才不是机器人!”系列功能 |
|
|
50
50
|
| `iLoveYou` | “我也喜欢你”系列功能 |
|
|
51
51
|
| `bdbd` | BanG Dream! 边框功能(对应 `bangdreamBorder`) |
|
|
52
|
+
| `roll` | 随机数功能 |
|
|
52
53
|
|
|
53
54
|
---
|
|
54
55
|
|
|
@@ -68,15 +69,16 @@ StarFreedomX机器人的小功能,自用
|
|
|
68
69
|
```
|
|
69
70
|
|
|
70
71
|
## 更新日志
|
|
71
|
-
| 版本
|
|
72
|
-
|
|
73
|
-
| `0.0.1`
|
|
74
|
-
| `0.1.0`
|
|
75
|
-
| `0.2.0`
|
|
76
|
-
| `0.3.0`
|
|
77
|
-
| `0.4.0`
|
|
78
|
-
| `0.5.0`
|
|
79
|
-
| `0.6.0`
|
|
80
|
-
| `0.7.0`
|
|
81
|
-
| `0.8.0`
|
|
82
|
-
| `0.9.0`
|
|
72
|
+
| 版本 | 更新日志 |
|
|
73
|
+
|----------|-------------------------------|
|
|
74
|
+
| `0.0.1` | 加入封印功能 |
|
|
75
|
+
| `0.1.0` | 加入"卖掉了"功能 |
|
|
76
|
+
| `0.2.0` | 加入"艾特我又不说话"回复功能 |
|
|
77
|
+
| `0.3.0` | 加入"我喜欢你"和"我才不是机器人!"回复功能 |
|
|
78
|
+
| `0.4.0` | 更改处理库为sharp |
|
|
79
|
+
| `0.5.0` | 加入BanG Dream!边框功能 |
|
|
80
|
+
| `0.6.0` | 加入群语录功能,修复一处bangdream绘制的bug |
|
|
81
|
+
| `0.7.0` | 加入复读功能 |
|
|
82
|
+
| `0.8.0` | 将各个工具函数封装在utils.ts中,更改语录的触发方式 |
|
|
83
|
+
| `0.9.0` | 添加白名单/黑名单模式,对每个功能做过滤 |
|
|
84
|
+
| `0.10.0` | 添加随机数功能 |
|