koishi-plugin-maple-dice-v2 0.0.5 → 0.0.6
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 +22 -6
- package/package.json +1 -1
- package/lib/index.d.ts +0 -24
package/lib/index.js
CHANGED
|
@@ -34,14 +34,30 @@ var DiceRoller = class {
|
|
|
34
34
|
__name(this, "DiceRoller");
|
|
35
35
|
}
|
|
36
36
|
static parseDice(expression) {
|
|
37
|
-
if (!expression) {
|
|
37
|
+
if (!expression || expression.trim() === "") {
|
|
38
38
|
expression = "1d100";
|
|
39
39
|
}
|
|
40
40
|
expression = expression.replace(/\s+/g, "").toLowerCase();
|
|
41
41
|
const diceRegex = /^(\d+)?d(\d+)(?:([+\-*/])(\d+))?$/;
|
|
42
|
-
|
|
42
|
+
let match = expression.match(diceRegex);
|
|
43
43
|
if (!match) {
|
|
44
|
-
|
|
44
|
+
if (/^\d+d$/.test(expression)) {
|
|
45
|
+
expression = expression + "100";
|
|
46
|
+
match = expression.match(diceRegex);
|
|
47
|
+
} else if (/^d\d+$/.test(expression)) {
|
|
48
|
+
expression = "1" + expression;
|
|
49
|
+
match = expression.match(diceRegex);
|
|
50
|
+
} else if (/^\d+$/.test(expression)) {
|
|
51
|
+
expression = expression + "d100";
|
|
52
|
+
match = expression.match(diceRegex);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!match) {
|
|
56
|
+
expression = "1d100";
|
|
57
|
+
match = expression.match(diceRegex);
|
|
58
|
+
if (!match) {
|
|
59
|
+
throw new Error("无效的掷骰表达式。正确格式: r xdy[+-*/]z");
|
|
60
|
+
}
|
|
45
61
|
}
|
|
46
62
|
const count = match[1] ? parseInt(match[1]) : 1;
|
|
47
63
|
const sides = parseInt(match[2]);
|
|
@@ -53,6 +69,9 @@ var DiceRoller = class {
|
|
|
53
69
|
if (count > 100) {
|
|
54
70
|
throw new Error("一次最多只能掷 100 个骰子");
|
|
55
71
|
}
|
|
72
|
+
if (operator === "/" && modifier === 0) {
|
|
73
|
+
throw new Error("除数不能为0");
|
|
74
|
+
}
|
|
56
75
|
const rolls = [];
|
|
57
76
|
for (let i = 0; i < count; i++) {
|
|
58
77
|
rolls.push(Math.floor(Math.random() * sides) + 1);
|
|
@@ -70,9 +89,6 @@ var DiceRoller = class {
|
|
|
70
89
|
total = diceTotal * modifier;
|
|
71
90
|
break;
|
|
72
91
|
case "/":
|
|
73
|
-
if (modifier === 0) {
|
|
74
|
-
throw new Error("除数不能为0");
|
|
75
|
-
}
|
|
76
92
|
total = Math.floor(diceTotal / modifier);
|
|
77
93
|
break;
|
|
78
94
|
default:
|
package/package.json
CHANGED
package/lib/index.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Context, Schema } from 'koishi';
|
|
2
|
-
export declare const name = "maple-dice-v2";
|
|
3
|
-
export declare const using: readonly ["database"];
|
|
4
|
-
declare module 'koishi' {
|
|
5
|
-
interface Tables {
|
|
6
|
-
'maple-dice-responses': DiceResponse;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
interface DiceResponse {
|
|
10
|
-
id: number;
|
|
11
|
-
level: string;
|
|
12
|
-
content: string;
|
|
13
|
-
author: string;
|
|
14
|
-
group: string;
|
|
15
|
-
created: Date;
|
|
16
|
-
}
|
|
17
|
-
export interface Config {
|
|
18
|
-
defaultSkill: number;
|
|
19
|
-
replyMode: 'global' | 'group' | 'personal';
|
|
20
|
-
commandPrefixes: string[];
|
|
21
|
-
}
|
|
22
|
-
export declare const Config: Schema<Config>;
|
|
23
|
-
export declare function apply(ctx: Context, config: Config): void;
|
|
24
|
-
export {};
|