Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
koishi-plugin-ygotournament
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-ygotournament
Commits
504dff53
Commit
504dff53
authored
Nov 27, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add currentmatch
parent
1cfb1453
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
3 deletions
+58
-3
src/def/challonge.ts
src/def/challonge.ts
+17
-3
src/plugin.ts
src/plugin.ts
+41
-0
No files found.
src/def/challonge.ts
View file @
504dff53
...
...
@@ -177,9 +177,23 @@ export class TournamentWrapper {
);
}
getCurrentMatchFromId
(
id
:
number
)
{
return
this
.
tournament
.
matches
.
find
(
(
m
)
=>
m
.
match
.
state
!==
'
complete
'
&&
m
.
hasPlayer
(
id
),
getParticipantFromParticipantId
(
id
:
number
)
{
return
this
.
tournament
.
participants
.
find
((
p
)
=>
p
.
participant
.
id
===
id
);
}
getCurrentMatchFromId
(
id
:
number
,
fetchLastCompleted
=
false
)
{
const
allRelatedMatches
=
this
.
tournament
.
matches
.
filter
((
m
)
=>
m
.
hasPlayer
(
id
),
);
const
currentMatch
=
allRelatedMatches
.
find
(
(
m
)
=>
m
.
match
.
state
!==
'
complete
'
,
);
if
(
currentMatch
)
{
return
currentMatch
;
}
if
(
!
fetchLastCompleted
)
{
return
;
}
return
allRelatedMatches
[
allRelatedMatches
.
length
-
1
];
}
}
src/plugin.ts
View file @
504dff53
...
...
@@ -130,6 +130,29 @@ export class YGOTournamentPlugin {
}
}
private
async
onUserGetCurrentMatch
(
userId
:
string
)
{
const
tournament
=
await
this
.
fetchChallongeData
();
const
participant
=
tournament
.
getParticipantFromId
(
userId
);
if
(
!
participant
)
{
return
'
未找到您的参赛信息。
'
;
}
const
currentMatch
=
tournament
.
getCurrentMatchFromId
(
participant
.
participant
.
id
,
true
,
);
if
(
!
currentMatch
)
{
return
'
您没有正在进行的比赛。
'
;
}
const
currentMatchInfo
=
currentMatch
.
match
;
const
player1Name
=
tournament
.
getParticipantFromParticipantId
(
currentMatchInfo
.
player1_id
,
).
participant
.
name
;
const
player2Name
=
tournament
.
getParticipantFromParticipantId
(
currentMatchInfo
.
player2_id
,
).
participant
.
name
;
return
`您当前的对局信息:\n
${
player1Name
}
\t
${
currentMatchInfo
.
scores_csv
}
\t
${
player2Name
}
`
;
}
private
async
onUserDeclareLate
(
userId
:
string
)
{
const
timeUnix
=
await
this
.
ctx
.
cache
.
get
(
'
lateDeclarationTime
'
,
'
current
'
);
// this.ctx.logger('test').warn(JSON.stringify(timeUnix));
...
...
@@ -257,6 +280,24 @@ export class YGOTournamentPlugin {
this
.
ctx
.
on
(
'
service/cache
'
,
()
=>
{
this
.
ctx
.
cache
.
table
(
'
lateDeclarationTime
'
,
{
maxAge
:
3600
*
1000
});
});
this
.
ctx
.
command
(
'
tournament/currentmatch
'
,
'
获取当前对局
'
)
.
shortcut
(
'
获取当前对局
'
)
.
usage
(
'
获取自己的当前对局和比分。
'
)
.
action
(
async
({
session
})
=>
{
try
{
return
await
this
.
onUserGetCurrentMatch
(
session
.
userId
);
}
catch
(
e
)
{
this
.
ctx
.
logger
(
'
challonge
'
)
.
error
(
`Failed to fetch current match of
${
session
.
userId
}
:
${
e
.
toString
()}
`
,
);
return
'
获取比赛出现了一些问题,请与技术人员联系。
'
;
}
});
this
.
ctx
.
command
(
'
tournament/late
'
,
'
迟到杀
'
)
.
shortcut
(
'
迟到杀
'
)
...
...
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