Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
Koishi Plugin Dicex
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 Dicex
Commits
09456eec
Commit
09456eec
authored
Aug 18, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve shortcut grammer and .st
parent
12ae7d4f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
40 deletions
+53
-40
src/modules/compat.ts
src/modules/compat.ts
+10
-14
src/modules/db.ts
src/modules/db.ts
+42
-23
src/modules/roll.ts
src/modules/roll.ts
+1
-3
No files found.
src/modules/compat.ts
View file @
09456eec
...
...
@@ -2,30 +2,26 @@ import { DiceModule } from '../utility/utility';
import
{
BaseModule
}
from
'
../utility/base-module
'
;
import
{
UseMiddleware
}
from
'
koishi-thirdeye
'
;
import
{
Next
,
Session
}
from
'
koishi
'
;
import
{
rcRegexp
,
rollRegexp
}
from
'
../utility/constant
'
;
@
DiceModule
()
export
class
CompatModule
extends
BaseModule
{
private
checkCommands
=
[
'
st
'
,
'
rc
'
,
'
ra
'
,
'
r
'
]
as
const
;
@
UseMiddleware
()
onRollCompat
(
session
:
Session
,
next
:
Next
)
{
if
(
!
session
.
parsed
)
{
return
next
();
}
const
{
content
,
prefix
}
=
session
.
parsed
;
if
(
!
prefix
||
content
[
0
]
!==
'
r
'
)
return
next
();
const
expr
=
content
.
slice
(
1
);
if
(
rollRegexp
.
test
(
expr
))
{
return
session
.
execute
({
name
:
'
roll
'
,
args
:
[
expr
]
});
if
(
!
prefix
)
{
return
next
();
}
if
(
rcRegexp
.
test
(
expr
))
{
const
matching
=
expr
.
match
(
rcRegexp
);
return
session
.
execute
({
name
:
'
rc
'
,
args
:
[
matching
[
1
],
...(
matching
[
2
]
?
[
parseInt
(
matching
[
2
].
trim
())]
:
[]),
],
});
const
matchingCommand
=
this
.
checkCommands
.
find
((
pattern
)
=>
content
.
startsWith
(
pattern
),
);
if
(
matchingCommand
)
{
const
rest
=
content
.
slice
(
matchingCommand
.
length
);
return
session
.
execute
(
`
${
matchingCommand
}
${
rest
}
`
,
next
);
}
return
next
();
}
...
...
src/modules/db.ts
View file @
09456eec
...
...
@@ -90,33 +90,52 @@ export class DbModule extends BaseModule implements LifecycleEvents {
return
isGlobal
?
'
频道
'
:
'
用户
'
;
}
@
UseCommand
(
'
dice/st <
skill:string> <value:integer
>
'
)
@
UseCommand
(
'
dice/st <
exprs:text
>
'
)
@
CommandDescription
({
zh
:
'
设置能力数值
'
,
en
:
'
Set skill value
'
})
@
CommandExample
(
'
st 潜行 50
'
)
async
onSetSkill
(
@
PutSession
()
session
:
Session
,
@
PutArg
(
0
)
skillName
:
string
,
@
PutArg
(
1
)
value
:
number
,
)
{
if
(
!
skillName
)
{
return
'
请输入技能名称。
'
;
async
onSetSkill
(@
PutSession
()
session
:
Session
,
@
PutArg
(
0
)
expr
:
string
)
{
const
sessionInfo
=
{
userId
:
session
.
userId
,
channelId
:
session
.
channelId
||
'
priv
'
,
};
const
exprChain
=
expr
.
split
(
/
\s
/
);
const
datas
:
Partial
<
DiceSkill
>
[]
=
[];
for
(
let
i
=
0
;
i
<
exprChain
.
length
;
i
++
)
{
let
skillName
:
string
,
value
:
number
;
const
fullMatch
=
exprChain
[
i
].
match
(
/^
(\D
+
)(\d{1,3})
$/
);
if
(
fullMatch
)
{
skillName
=
fullMatch
[
1
];
value
=
parseInt
(
fullMatch
[
2
],
10
);
}
else
{
const
nextValue
=
exprChain
[
i
+
1
];
if
(
nextValue
.
match
(
/^
\d{1,3}
$/
))
{
skillName
=
exprChain
[
i
];
value
=
parseInt
(
nextValue
,
10
);
i
++
;
}
else
{
return
'
语法错误。
'
;
}
}
if
(
value
==
null
||
value
<
0
||
value
>
100
)
{
return
'
数值必须在 0 到 100 之间。
'
;
}
datas
.
push
({
...
sessionInfo
,
skillName
:
fullMatch
[
1
],
value
:
parseInt
(
fullMatch
[
2
]),
});
}
if
(
value
==
null
||
value
<
0
||
value
>
100
)
{
return
'
数值必须在 0 到 100 之间。
'
;
if
(
!
datas
.
length
)
{
return
;
}
await
this
.
database
.
upsert
(
'
diceSkill
'
,
[
{
userId
:
session
.
userId
,
channelId
:
session
.
channelId
||
'
priv
'
,
skillName
,
value
,
},
],
[
'
userId
'
,
'
channelId
'
,
'
skillName
'
],
);
return
`已设置
${
skillName
}
的能力数值为
${
value
}
。`
;
await
this
.
database
.
upsert
(
'
diceSkill
'
,
datas
,
[
'
userId
'
,
'
channelId
'
,
'
skillName
'
,
]);
return
`已设置能力数值:
${
datas
.
map
(({
skillName
,
value
})
=>
`
${
skillName
}
=
${
value
}
`
)
.
join
(
'
'
)}
`
;
}
async
getSkillValue
(
session
:
Session
,
skillName
:
string
)
{
...
...
src/modules/roll.ts
View file @
09456eec
...
...
@@ -21,11 +21,9 @@ import { BaseModule } from '../utility/base-module';
@
DiceModule
()
export
class
RollModule
extends
BaseModule
{
private
getDefaultFaces
(
user
:
User
,
channel
:
Channel
)
{}
@
UseCommand
(
'
dice/roll [expr:string]
'
,
'
掷骰
'
)
@
CommandDescription
({
en
:
'
Roll dice
'
})
@
CommandAlias
(
'
r
d
'
)
@
CommandAlias
(
'
r
'
)
@
CommandShortcut
(
'
掷骰
'
,
{
fuzzy
:
true
})
@
CommandExample
(
'
roll 2d6+d10
'
)
onRoll
(
...
...
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