Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
J
Jdaw
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
MyCard
Jdaw
Commits
d37c1be2
Commit
d37c1be2
authored
Jan 16, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
arena system
parent
542ddefd
Pipeline
#19592
passed with stages
in 8 minutes and 18 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
4 deletions
+54
-4
Dockerfile
Dockerfile
+1
-0
src/app.module.ts
src/app.module.ts
+5
-0
src/arena-score/arena-score.service.ts
src/arena-score/arena-score.service.ts
+35
-1
src/mycard-account/mycard-account.service.ts
src/mycard-account/mycard-account.service.ts
+7
-3
views/arena-score.mustache
views/arena-score.mustache
+3
-0
views/bind-account.mustache
views/bind-account.mustache
+3
-0
No files found.
Dockerfile
View file @
d37c1be2
...
@@ -20,6 +20,7 @@ RUN npm ci && npm cache clean --force
...
@@ -20,6 +20,7 @@ RUN npm ci && npm cache clean --force
COPY
--from=builder /app/dist ./dist
COPY
--from=builder /app/dist ./dist
COPY
--chown=mycard:mycard ./config.example.yaml ./config.yaml
COPY
--chown=mycard:mycard ./config.example.yaml ./config.yaml
COPY
--chown=mycard:mycard ./views ./views
ENV
NODE_PG_FORCE_NATIVE=true
ENV
NODE_PG_FORCE_NATIVE=true
EXPOSE
3000
EXPOSE
3000
...
...
src/app.module.ts
View file @
d37c1be2
...
@@ -103,6 +103,11 @@ import { ArenaScoreService } from './arena-score/arena-score.service';
...
@@ -103,6 +103,11 @@ import { ArenaScoreService } from './arena-score/arena-score.service';
type
:
'
parent
'
,
type
:
'
parent
'
,
name
:
'
用户服务
'
,
name
:
'
用户服务
'
,
children
:
[
children
:
[
{
type
:
'
click
'
,
name
:
'
MyCard 战绩
'
,
command
:
'
arena-score
'
,
},
{
{
type
:
'
click
'
,
type
:
'
click
'
,
name
:
'
服务器列表
'
,
name
:
'
服务器列表
'
,
...
...
src/arena-score/arena-score.service.ts
View file @
d37c1be2
import
{
Injectable
}
from
'
@nestjs/common
'
;
import
{
Injectable
}
from
'
@nestjs/common
'
;
import
{
PutUserId
,
UseCommand
}
from
'
koishi-nestjs
'
;
import
{
TemplateService
}
from
'
../template/template.service
'
;
import
{
HttpService
}
from
'
@nestjs/axios
'
;
import
{
MycardAuthService
}
from
'
nestjs-mycard
'
;
import
{
MycardAccountService
}
from
'
../mycard-account/mycard-account.service
'
;
import
{
lastValueFrom
}
from
'
rxjs
'
;
@
Injectable
()
@
Injectable
()
export
class
ArenaScoreService
{}
export
class
ArenaScoreService
{
constructor
(
private
template
:
TemplateService
,
private
http
:
HttpService
,
private
mycard
:
MycardAuthService
,
private
mycardAccount
:
MycardAccountService
,
)
{}
@
UseCommand
(
'
arena-score
'
,
'
查询 MyCard 匹配战绩
'
)
async
arenaScoreCommand
(@
PutUserId
()
id
:
string
)
{
const
user
=
await
this
.
mycardAccount
.
findOrCreateUser
(
id
);
if
(
!
user
.
mycardId
)
{
return
(
'
您还未绑定 MyCard 帐号。
'
+
(
await
this
.
mycardAccount
.
bind
(
id
,
true
))
);
}
const
mycardUser
=
await
this
.
mycard
.
getUser
(
user
.
mycardId
);
const
result
=
await
lastValueFrom
(
this
.
http
.
get
(
'
https://sapi.moecube.com:444/ygopro/arena/user
'
,
{
params
:
{
username
:
mycardUser
.
username
,
},
}),
);
return
this
.
template
.
render
(
'
arena-score
'
,
{
...
result
.
data
,
name
:
mycardUser
.
username
,
});
}
}
src/mycard-account/mycard-account.service.ts
View file @
d37c1be2
...
@@ -9,8 +9,9 @@ import cryptoRandomString from 'crypto-random-string';
...
@@ -9,8 +9,9 @@ import cryptoRandomString from 'crypto-random-string';
import
{
MycardAuthService
,
MycardUser
}
from
'
nestjs-mycard
'
;
import
{
MycardAuthService
,
MycardUser
}
from
'
nestjs-mycard
'
;
import
{
ConfigService
}
from
'
@nestjs/config
'
;
import
{
ConfigService
}
from
'
@nestjs/config
'
;
import
{
BindQueryDto
}
from
'
./dto/bind-query.dto
'
;
import
{
BindQueryDto
}
from
'
./dto/bind-query.dto
'
;
import
{
TemplateService
}
from
'
../template/template.service
'
;
@
CacheTTL
(
1800
)
@
CacheTTL
(
1800
*
1000
)
class
BindSession
{
class
BindSession
{
@
CacheKey
()
@
CacheKey
()
sessionId
:
string
;
sessionId
:
string
;
...
@@ -42,6 +43,7 @@ export class MycardAccountService extends CrudService(User) {
...
@@ -42,6 +43,7 @@ export class MycardAccountService extends CrudService(User) {
@
InjectAragami
()
private
aragami
:
Aragami
,
@
InjectAragami
()
private
aragami
:
Aragami
,
private
mycard
:
MycardAuthService
,
private
mycard
:
MycardAuthService
,
private
config
:
ConfigService
,
private
config
:
ConfigService
,
private
template
:
TemplateService
,
)
{
)
{
super
(
repo
);
super
(
repo
);
}
}
...
@@ -67,19 +69,21 @@ export class MycardAccountService extends CrudService(User) {
...
@@ -67,19 +69,21 @@ export class MycardAccountService extends CrudService(User) {
}
}
@
UseCommand
(
'
bind
'
,
'
绑定 MyCard 帐号
'
)
@
UseCommand
(
'
bind
'
,
'
绑定 MyCard 帐号
'
)
async
bind
(@
PutUserId
()
id
:
string
)
{
async
bind
(@
PutUserId
()
id
:
string
,
needHint
=
false
)
{
const
session
=
BindSession
.
create
(
id
);
const
session
=
BindSession
.
create
(
id
);
console
.
log
(
session
.
sessionId
);
await
this
.
aragami
.
set
(
session
);
await
this
.
aragami
.
set
(
session
);
const
url
=
loginUrl
(
const
url
=
loginUrl
(
`
${
this
.
rootUrl
}
/api/mycard-account/bind?session=
${
session
.
sessionId
}
`
,
`
${
this
.
rootUrl
}
/api/mycard-account/bind?session=
${
session
.
sessionId
}
`
,
);
);
return
`请点击下面的链接完成 MyCard 帐号绑定:\n
${
url
}
`
;
return
this
.
template
.
render
(
'
bind-account
'
,
{
url
,
needHint
})
;
}
}
async
bindCallback
(
async
bindCallback
(
dto
:
BindQueryDto
,
dto
:
BindQueryDto
,
):
Promise
<
{
error
?:
string
;
user
?:
MycardUser
}
>
{
):
Promise
<
{
error
?:
string
;
user
?:
MycardUser
}
>
{
const
session
=
await
this
.
aragami
.
get
(
BindSession
,
dto
.
session
);
const
session
=
await
this
.
aragami
.
get
(
BindSession
,
dto
.
session
);
console
.
log
(
dto
.
session
,
session
);
if
(
!
session
)
{
if
(
!
session
)
{
return
{
error
:
'
会话不存在。
'
};
return
{
error
:
'
会话不存在。
'
};
}
}
...
...
views/arena-score.mustache
0 → 100644
View file @
d37c1be2
{{
name
}}
,您的的 DP 是
{{
pt
}}
,排名第
{{
arena_rank
}}
。您的 EXP 是
{{
exp
}}
,排名第
{{
exp_rank
}}
。
您的竞技匹配总场数是
{{
athletic_all
}}
,胜场数是
{{
athletic_win
}}
,胜率是
{{
athletic_wl_ratio
}}
%。
您的娱乐匹配总场数是
{{
entertain_all
}}
,胜场数是
{{
entertain_win
}}
,胜率是
{{
entertain_wl_ratio
}}
%。
\ No newline at end of file
views/bind-account.mustache
0 → 100644
View file @
d37c1be2
请点击下面的链接完成 MyCard 帐号绑定。
{{
url
}}
{{#
needHint
}}
日后可以通过指令 bind 绑定或换绑 MyCard 帐号,通过指令 unbind 解绑 MyCard 帐号。
{{/
needHint
}}
\ No newline at end of file
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