Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
YuzuDice
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
nanahira
YuzuDice
Commits
ded6b8db
Commit
ded6b8db
authored
May 03, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support better param
parent
da4a2e92
Pipeline
#3115
passed with stages
in 10 minutes and 25 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
4 deletions
+28
-4
src/app.service.ts
src/app.service.ts
+25
-2
src/bot/bot.controller.ts
src/bot/bot.controller.ts
+3
-2
No files found.
src/app.service.ts
View file @
ded6b8db
...
@@ -26,10 +26,12 @@ export interface CommonResult {
...
@@ -26,10 +26,12 @@ export interface CommonResult {
reason
?:
string
;
reason
?:
string
;
result
?:
number
;
result
?:
number
;
}
}
export
interface
DiceParam
{
export
interface
RollResult
extends
CommonResult
{
count
:
number
;
count
:
number
;
size
:
number
;
size
:
number
;
}
export
interface
RollResult
extends
CommonResult
,
DiceParam
{
formula
?:
string
;
formula
?:
string
;
results
?:
number
[];
results
?:
number
[];
}
}
...
@@ -196,6 +198,27 @@ export class AppService {
...
@@ -196,6 +198,27 @@ export class AppService {
return
{
user
,
group
,
profile
,
banReason
:
null
};
return
{
user
,
group
,
profile
,
banReason
:
null
};
}
}
parseDiceParam
(
param
:
string
):
DiceParam
{
if
(
!
param
)
{
return
null
;
}
let
match
=
param
.
match
(
/^d
?(\d
+
)
$/
);
if
(
match
)
{
return
{
size
:
parseInt
(
match
[
1
]),
count
:
1
,
};
}
match
=
param
.
match
(
/^
(\d
+
)
d
(\d
+
)
$/
);
if
(
match
)
{
return
{
size
:
parseInt
(
match
[
2
]),
count
:
parseInt
(
match
[
1
]),
};
}
return
null
;
}
async
rollDice
(
async
rollDice
(
rollResult
:
RollResult
,
rollResult
:
RollResult
,
userData
:
KoishiSessionLike
,
userData
:
KoishiSessionLike
,
...
...
src/bot/bot.controller.ts
View file @
ded6b8db
...
@@ -87,14 +87,14 @@ export class BotController {
...
@@ -87,14 +87,14 @@ export class BotController {
await
this
.
appService
.
banForKicked
(
session
.
groupId
,
session
.
operatorId
);
await
this
.
appService
.
banForKicked
(
session
.
groupId
,
session
.
operatorId
);
});
});
globalCtx
globalCtx
.
command
(
'
rolldice
'
,
'
投掷骰子
'
)
.
command
(
'
rolldice
[param:string]
'
,
'
投掷骰子
'
)
.
option
(
'
count
'
,
'
-c <count:posint> 骰子数量
'
,
{
fallback
:
1
})
.
option
(
'
count
'
,
'
-c <count:posint> 骰子数量
'
,
{
fallback
:
1
})
.
option
(
'
size
'
,
'
-s <count:posint> 骰子面数
'
,
{
fallback
:
6
})
.
option
(
'
size
'
,
'
-s <count:posint> 骰子面数
'
,
{
fallback
:
6
})
.
option
(
'
reason
'
,
'
-r <reason:text> 骰子说明
'
)
.
option
(
'
reason
'
,
'
-r <reason:text> 骰子说明
'
)
.
alias
(
'
rd
'
,
'
roll
'
,
'
r
'
)
.
alias
(
'
rd
'
,
'
roll
'
,
'
r
'
)
.
usage
(
'
也支持 .rd<size> 和 .r<count>d<size> [reason] 这样的传统语法。
'
)
.
usage
(
'
也支持 .rd<size> 和 .r<count>d<size> [reason] 这样的传统语法。
'
)
.
example
(
'
.rolldice -c 2 -s 6 -r "行动判定"
'
)
.
example
(
'
.rolldice -c 2 -s 6 -r "行动判定"
'
)
.
action
(
async
(
argv
,
args
)
=>
{
.
action
(
async
(
argv
,
param
)
=>
{
const
session
=
argv
.
session
;
const
session
=
argv
.
session
;
const
rollResult
=
{
const
rollResult
=
{
name
:
session
.
username
,
name
:
session
.
username
,
...
@@ -102,6 +102,7 @@ export class BotController {
...
@@ -102,6 +102,7 @@ export class BotController {
size
:
6
,
size
:
6
,
reason
:
null
,
reason
:
null
,
...
argv
.
options
,
...
argv
.
options
,
...
this
.
appService
.
parseDiceParam
(
param
),
};
};
return
await
this
.
appService
.
rollDice
(
rollResult
,
session
);
return
await
this
.
appService
.
rollDice
(
rollResult
,
session
);
});
});
...
...
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