koishi-plugin-starfx-bot 0.9.0 → 0.10.1

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
@@ -19,6 +19,7 @@ export interface Config {
19
19
  openRepeat: boolean;
20
20
  minRepeatTimes: number;
21
21
  repeatPossibility: number;
22
+ saveArchive: boolean;
22
23
  featureControl: string;
23
24
  }
24
25
  export declare const Config: Schema<Schemastery.ObjectS<{
@@ -27,6 +28,7 @@ export declare const Config: Schema<Schemastery.ObjectS<{
27
28
  bangdreamBorder: Schema<boolean, boolean>;
28
29
  }> | Schemastery.ObjectS<{
29
30
  record: Schema<boolean, boolean>;
31
+ saveArchive: Schema<boolean, boolean>;
30
32
  }> | Schemastery.ObjectS<{
31
33
  roll: Schema<boolean, boolean>;
32
34
  }> | Schemastery.ObjectS<{
@@ -48,6 +50,7 @@ export declare const Config: Schema<Schemastery.ObjectS<{
48
50
  bangdreamBorder: boolean;
49
51
  } & import("cosmokit").Dict & {
50
52
  record: boolean;
53
+ saveArchive: boolean;
51
54
  } & {
52
55
  roll: boolean;
53
56
  } & {
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: "请输入要随机的对象" } } }, middleware: { messages: { atNotReply: "艾特我又不说话", atNotReplyOther: "艾特他又不说话", notBot: "我才不是机器人!", loveMessage: "我喜欢你", iLoveU: "我也喜欢你" } } };
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 (!Number.isInteger(num) || !Number.isInteger(noodles) || num < 0 || noodles > 0) 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";
@@ -382,11 +435,11 @@ var Config2 = import_koishi2.Schema.intersect([
382
435
  bangdreamBorder: import_koishi2.Schema.boolean().default(true).description("开启BanG Dream!边框功能")
383
436
  }).description("绘图功能"),
384
437
  import_koishi2.Schema.object({
385
- record: import_koishi2.Schema.boolean().default(true).description("开启群语录功能")
386
- //saveArchive: Schema.boolean().default(false).description('开启入典功能').hidden(),
438
+ record: import_koishi2.Schema.boolean().default(true).description("开启群语录功能"),
439
+ saveArchive: import_koishi2.Schema.boolean().default(false).description("开启入典功能").hidden()
387
440
  }).description("语录记录功能"),
388
441
  import_koishi2.Schema.object({
389
- roll: import_koishi2.Schema.boolean().default(false).description("开启roll随机数功能").hidden()
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 <param:text>").action(async ({ session }, param) => {
483
+ ctx.command("roll").action(async ({ session }) => {
431
484
  if (detectControl(controlJson, session.guildId, "roll")) {
432
- if (!param) return session.text(".noParam");
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
  }
@@ -485,6 +527,11 @@ function apply(ctx, cfg) {
485
527
  }
486
528
  });
487
529
  }
530
+ if (cfg.saveArchive) {
531
+ ctx.command("入典").action(async ({ session }) => {
532
+ if (!session.quote) return "请引用合并转发聊天记录进行入典";
533
+ });
534
+ }
488
535
  ctx.middleware(async (session, next) => {
489
536
  const elements = session.elements;
490
537
  if (cfg.openRepeat && detectControl(controlJson, session.guildId, "repeat")) {
package/lib/utils.d.ts CHANGED
@@ -128,4 +128,6 @@ 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;
132
+ export declare function saveArchive(quoteElements: h[], gid: string, session: Session): void;
131
133
  export {};
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "contributors": [
5
5
  "StarFreedomX <starfreedomx@outlook.com>"
6
6
  ],
7
- "version": "0.9.0",
7
+ "version": "0.10.1",
8
8
  "main": "lib/index.js",
9
9
  "typings": "lib/index.d.ts",
10
10
  "files": [
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,17 @@ 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` | 更改处理库为sharp |
78
- | `0.5.0` | 加入BanG Dream!边框功能 |
79
- | `0.6.0` | 加入群语录功能,修复一处bangdream绘制的bug |
80
- | `0.7.0` | 加入复读功能 |
81
- | `0.8.0` | 将各个工具函数封装在utils.ts中,更改语录的触发方式 |
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` | 添加随机数功能 |
85
+ | `0.10.1` | 修复随机数骰子功能输入负数报错的bug |