Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
koishi-plugin-draw
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
3rdeye
koishi-plugin-draw
Commits
9f65f6be
Commit
9f65f6be
authored
Aug 19, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
migrate to onedice
parent
f53fbd99
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
23 deletions
+17
-23
package-lock.json
package-lock.json
+12
-1
package.json
package.json
+2
-1
src/index.ts
src/index.ts
+3
-21
No files found.
package-lock.json
View file @
9f65f6be
...
...
@@ -12,7 +12,8 @@
"koishi-thirdeye"
:
"^11.0.9"
,
"leven"
:
"^3.1.0"
,
"load-json-file"
:
"^6.2.0"
,
"lodash"
:
"^4.17.21"
"lodash"
:
"^4.17.21"
,
"onedice"
:
"^1.0.2"
},
"devDependencies"
:
{
"@koishijs/plugin-console"
:
"^4.1.1"
,
...
...
@@ -6045,6 +6046,11 @@
"wrappy"
:
"1"
}
},
"node_modules/onedice"
:
{
"version"
:
"1.0.2"
,
"resolved"
:
"https://registry.npmjs.org/onedice/-/onedice-1.0.2.tgz"
,
"integrity"
:
"sha512-B7sN77wWL7WP+4a5ngPYhrJC4E6q8yHs2FQS6hz/vPmTgBXZvJjJMJguV8DAaLtSLjbhwXG4wdIoyNI64ieziQ=="
},
"node_modules/onetime"
:
{
"version"
:
"5.1.2"
,
"resolved"
:
"https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz"
,
...
...
@@ -12761,6 +12767,11 @@
"wrappy"
:
"1"
}
},
"onedice"
:
{
"version"
:
"1.0.2"
,
"resolved"
:
"https://registry.npmjs.org/onedice/-/onedice-1.0.2.tgz"
,
"integrity"
:
"sha512-B7sN77wWL7WP+4a5ngPYhrJC4E6q8yHs2FQS6hz/vPmTgBXZvJjJMJguV8DAaLtSLjbhwXG4wdIoyNI64ieziQ=="
},
"onetime"
:
{
"version"
:
"5.1.2"
,
"resolved"
:
"https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz"
,
...
...
package.json
View file @
9f65f6be
...
...
@@ -47,7 +47,8 @@
"
koishi-thirdeye
"
:
"
^11.0.9
"
,
"
leven
"
:
"
^3.1.0
"
,
"
load-json-file
"
:
"
^6.2.0
"
,
"
lodash
"
:
"
^4.17.21
"
"
lodash
"
:
"
^4.17.21
"
,
"
onedice
"
:
"
^1.0.2
"
},
"peerDependencies"
:
{
"koishi"
:
"^4.8.4"
...
...
src/index.ts
View file @
9f65f6be
...
...
@@ -21,6 +21,7 @@ import _ from 'lodash';
import
*
as
localeZh
from
'
./locales/zh
'
;
import
*
as
localeEn
from
'
./locales/en
'
;
import
leven
from
'
leven
'
;
import
{
OneDice
}
from
'
onedice
'
;
export
*
from
'
./config
'
;
type
Decks
=
Record
<
string
,
string
[]
>
;
...
...
@@ -70,28 +71,9 @@ export default class DrawPlugin
return
{
deckCount
,
deckFileCount
};
}
parseDicePattern
(
pattern
:
string
)
{
if
(
pattern
.
match
(
/^
\d
+$/
))
{
return
parseInt
(
pattern
);
}
const
match
=
pattern
.
match
(
/^
(\d
*
)
d
(\d
+
)
$/
);
if
(
!
match
)
{
return
0
;
}
const
[,
_count
,
_sides
]
=
match
;
const
count
=
_count
?
parseInt
(
_count
)
:
1
;
const
sides
=
parseInt
(
_sides
);
return
_
.
sum
(
_
.
range
(
count
).
map
(()
=>
Random
.
int
(
1
,
sides
+
1
)));
}
parseDice
(
dice
:
string
)
{
const
patterns
=
dice
.
split
(
'
+
'
);
return
_
.
sumBy
(
patterns
,
(
pattern
)
=>
this
.
parseDicePattern
(
pattern
));
}
parseEntry
(
name
:
string
,
entry
:
string
,
depth
=
1
):
string
{
let
result
=
entry
.
replace
(
/
\[
[
d
\d\+]
+
\]
/g
,
(
dicePattern
)
=>
this
.
parseDic
e
(
dicePattern
.
slice
(
1
,
-
1
)).
toString
(),
let
result
=
entry
.
replace
(
/
\[
([^\]]
+
)
\]
/g
,
(
dicePattern
)
=>
new
OneDice
().
calculat
e
(
dicePattern
.
slice
(
1
,
-
1
)).
toString
(),
);
if
(
depth
>
this
.
config
.
maxDepth
)
{
this
.
logger
.
warn
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment