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
f935d3fa
Commit
f935d3fa
authored
Aug 17, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add .st
parent
70dbb8a2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
20 deletions
+100
-20
src/index.ts
src/index.ts
+2
-6
src/modules/db.ts
src/modules/db.ts
+77
-2
src/modules/rc.ts
src/modules/rc.ts
+21
-12
No files found.
src/index.ts
View file @
f935d3fa
...
...
@@ -3,6 +3,7 @@ import { DicePluginConfig } from './config';
import
{
CommandDescription
,
DefinePlugin
,
Isolate
,
LifecycleEvents
,
UseCommand
,
}
from
'
koishi-thirdeye
'
;
...
...
@@ -14,12 +15,7 @@ import { CompatModule } from './modules/compat';
export
*
from
'
./config
'
;
declare
module
'
koishi
'
{
interface
Context
{
diceDb
:
DbModule
;
}
}
@
Isolate
(
'
diceDb
'
)
@
DefinePlugin
({
name
:
'
dicex
'
,
schema
:
DicePluginConfig
})
export
default
class
DicePlugin
extends
BaseModule
implements
LifecycleEvents
{
@
UseCommand
(
'
dice
'
,
{
empty
:
true
})
...
...
src/modules/db.ts
View file @
f935d3fa
...
...
@@ -3,16 +3,29 @@ import {
CommandDescription
,
CommandExample
,
CommandUsage
,
DefineModel
,
Inject
,
InjectLogger
,
LifecycleEvents
,
MixinModel
,
ModelField
,
Primary
,
Provide
,
PutArg
,
PutOption
,
PutSession
,
UseCommand
,
UseModel
,
}
from
'
koishi-thirdeye
'
;
import
{
Channel
,
Database
,
DatabaseService
,
Logger
,
User
}
from
'
koishi
'
;
import
{
Channel
,
Database
,
DatabaseService
,
Logger
,
Session
,
Tables
,
User
,
}
from
'
koishi
'
;
import
{
RcRuleList
}
from
'
../utility/rc-rules
'
;
import
{
DiceModule
,
...
...
@@ -33,15 +46,35 @@ declare module 'koishi' {
interface
User
{
diceProfile
:
DiceProfile
;
}
interface
Tables
{
diceSkill
:
DiceSkill
;
}
}
@
DefineModel
(
'
diceSkill
'
)
export
class
DiceSkill
{
@
Primary
()
@
ModelField
(
'
string(64)
'
)
userId
:
string
;
@
Primary
()
@
ModelField
(
'
string(64)
'
)
channelId
:
string
;
@
Primary
()
@
ModelField
(
'
string(32)
'
)
skillName
:
string
;
@
ModelField
(
'
unsigned(1)
'
)
value
:
number
;
}
@
Provide
(
'
diceDb
'
)
@
MixinModel
(
'
user
'
,
{
diceProfile
:
DiceProfile
})
@
MixinModel
(
'
channel
'
,
{
diceProfile
:
DiceProfile
})
@
UseModel
(
DiceSkill
)
@
DiceModule
()
export
class
DbModule
extends
BaseModule
implements
LifecycleEvents
{
@
Inject
(
true
)
private
database
:
Database
;
private
database
:
Database
<
Tables
>
;
@
Inject
(
true
)
private
model
:
DatabaseService
;
...
...
@@ -57,6 +90,48 @@ export class DbModule extends BaseModule implements LifecycleEvents {
return
isGlobal
?
'
频道
'
:
'
用户
'
;
}
@
UseCommand
(
'
dice/st <skill:string> <value:integer>
'
)
@
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
'
请输入技能名称。
'
;
}
if
(
value
==
null
||
value
<
0
||
value
>
100
)
{
return
'
数值必须在 0 到 100 之间。
'
;
}
await
this
.
database
.
upsert
(
'
diceSkill
'
,
[
{
userId
:
session
.
userId
,
channelId
:
session
.
channelId
||
'
priv
'
,
skillName
,
value
,
},
],
[
'
userId
'
,
'
channelId
'
,
'
skillName
'
],
);
return
`已设置
${
skillName
}
的能力数值为
${
value
}
。`
;
}
async
getSkillValue
(
session
:
Session
,
skillName
:
string
)
{
const
[
skill
]
=
await
this
.
database
.
get
(
'
diceSkill
'
,
{
userId
:
session
.
userId
,
channelId
:
session
.
channelId
||
'
priv
'
,
skillName
,
},
[
'
value
'
],
);
return
skill
?.
value
;
}
@
UseCommand
(
'
dice/rcmode
'
)
@
CommandDescription
({
zh
:
'
设置检点规则
'
,
en
:
'
Set RC rule
'
})
@
CommandUsage
(
...
...
src/modules/rc.ts
View file @
f935d3fa
...
...
@@ -3,13 +3,14 @@ import {
CommandDescription
,
CommandExample
,
CommandShortcut
,
CommandUsage
,
Inject
,
PutArg
,
PutChannel
,
PutUser
,
PutSession
,
PutUserName
,
UseCommand
,
}
from
'
koishi-thirdeye
'
;
import
{
Channel
,
Random
,
User
}
from
'
koishi
'
;
import
{
Channel
,
Random
,
Session
,
User
}
from
'
koishi
'
;
import
{
DiceModule
,
getRcMode
,
...
...
@@ -18,6 +19,7 @@ import {
}
from
'
../utility/utility
'
;
import
{
BaseModule
}
from
'
../utility/base-module
'
;
import
{
RcResult
,
RcRuleList
}
from
'
../utility/rc-rules
'
;
import
{
DbModule
}
from
'
./db
'
;
@
DiceModule
()
export
class
RcModule
extends
BaseModule
{
...
...
@@ -26,19 +28,28 @@ export class RcModule extends BaseModule {
return
RcRuleList
[
index
];
}
@
UseCommand
(
'
dice/rc <rate:integer> [reason:string]
'
)
@
Inject
()
diceDb
:
DbModule
;
@
UseCommand
(
'
dice/rc <reason:string> [rate:integer]
'
)
@
CommandDescription
({
zh
:
'
检定
'
,
en
:
'
Roll check
'
})
@
CommandAlias
(
'
ra
'
)
@
CommandShortcut
(
'
检定
'
,
{
fuzzy
:
true
})
@
CommandExample
(
'
rc 20 潜行
'
)
onRc
(
@
CommandUsage
(
'
可以用 st 设置数值。
'
)
@
CommandExample
(
'
rc 潜行 20
'
)
@
CommandExample
(
'
rc 潜行
'
)
async
onRc
(
@
PutSession
()
session
:
Session
,
@
PutUserName
(
true
)
username
:
string
,
@
PutArg
(
0
)
r
ate
:
number
,
@
PutArg
(
1
)
r
eason
:
string
,
@
PutArg
(
0
)
r
eason
:
string
,
@
PutArg
(
1
)
r
ate
:
number
,
@
PutUserProfile
()
user
:
User
,
@
PutChannelProfile
()
channel
:
Channel
,
)
{
if
(
!
rate
||
rate
<
0
||
rate
>
100
)
{
if
(
rate
==
null
&&
this
.
diceDb
)
{
rate
=
await
this
.
diceDb
.
getSkillValue
(
session
,
reason
);
}
if
(
rate
==
null
||
rate
<
0
||
rate
>
100
)
{
return
'
成功率必须在 0 到 100 之间。
'
;
}
const
rule
=
this
.
getRcRule
(
user
,
channel
);
...
...
@@ -52,8 +63,6 @@ export class RcModule extends BaseModule {
:
result
===
RcResult
.
Success
?
'
成功
'
:
'
大成功!
'
;
return
`
${
username
}${
reason
?
`要
${
reason
}
,开始`
:
''
}
进行检定:D100=
${
value
}
/
${
rate
}
${
resultText
}
`
;
return
`
${
username
}
要
${
reason
}
,开始进行检定:D100=
${
value
}
/
${
rate
}
${
resultText
}
`
;
}
}
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