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
dcaaeb5c
Commit
dcaaeb5c
authored
Jul 25, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bump to Koishi 4.8
parent
5bbd0b89
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1537 additions
and
503 deletions
+1537
-503
dev/index.ts
dev/index.ts
+5
-5
package-lock.json
package-lock.json
+1479
-450
package.json
package.json
+8
-7
src/index.ts
src/index.ts
+34
-38
tests/sample.spec.ts
tests/sample.spec.ts
+3
-3
webpack.config.js
webpack.config.js
+8
-0
No files found.
dev/index.ts
View file @
dcaaeb5c
import
{
App
}
from
'
koishi
'
;
import
{
Context
}
from
'
koishi
'
;
import
TargetPlugin
from
'
../src
'
;
import
ConsolePlugin
from
'
@koishijs/plugin-console
'
;
import
SandboxPlugin
from
'
@koishijs/plugin-sandbox
'
;
import
*
as
DatabasePlugin
from
'
@koishijs/plugin-database-memory
'
;
import
CachePlugin
from
'
@koishijs/plugin-cache-lru
'
;
import
DatabasePlugin
from
'
@koishijs/plugin-database-memory
'
;
import
AragamiPlugin
from
'
koishi-plugin-cache-aragami
'
;
import
ExtrasInDev
from
'
./extras
'
;
const
app
=
new
App
({
const
app
=
new
Context
({
port
:
14514
,
host
:
'
localhost
'
,
prefix
:
'
.
'
,
...
...
@@ -19,7 +19,7 @@ app.plugin(ConsolePlugin, {
});
// Some services
app
.
plugin
(
Cache
Plugin
);
app
.
plugin
(
Aragami
Plugin
);
app
.
plugin
(
DatabasePlugin
);
// Some extras
...
...
package-lock.json
View file @
dcaaeb5c
This source diff could not be displayed because it is too large. You can
view the blob
instead.
package.json
View file @
dcaaeb5c
...
...
@@ -24,7 +24,7 @@
"ygo"
,
"yugioh"
,
"ygopro"
,
"required:cache"
"required:cache
-aragami
"
],
"bugs"
:
{
"url"
:
"
https://code.mycard.moe/3rdeye/koishi-plugin-ygotournament/issues
"
...
...
@@ -38,19 +38,19 @@
"
@aws-sdk/types
"
:
"
3.38.0
"
,
"
@aws-sdk/util-format-url
"
:
"
3.38.0
"
,
"
class-transformer
"
:
"
^0.4.0
"
,
"
koishi-thirdeye
"
:
"
^1
0.3.2
"
,
"
koishi-thirdeye
"
:
"
^1
1.0.6
"
,
"
moment
"
:
"
^2.29.1
"
,
"
schemastery-gen
"
:
"
^3.1.14
"
},
"devDependencies"
:
{
"
@koishijs/plugin-cache-lru
"
:
"
^1.0.0-rc.0
"
,
"
@koishijs/plugin-console
"
:
"
^3.3.2
"
,
"
@koishijs/plugin-database-memory
"
:
"
^1.3.0
"
,
"
@koishijs/plugin-sandbox
"
:
"
^1.1.3
"
,
"
@koishijs/plugin-console
"
:
"
^4.1.1
"
,
"
@koishijs/plugin-database-memory
"
:
"
^1.4.1
"
,
"
@koishijs/plugin-sandbox
"
:
"
^2.0.1
"
,
"
@types/jest
"
:
"
^27.4.0
"
,
"
@types/node
"
:
"
^16.11.6
"
,
"
@typescript-eslint/eslint-plugin
"
:
"
^4.33.0
"
,
"
@typescript-eslint/parser
"
:
"
^4.33.0
"
,
"
esbuild-loader
"
:
"
^2.19.0
"
,
"
eslint
"
:
"
^7.32.0
"
,
"
eslint-config-prettier
"
:
"
^8.3.0
"
,
"
eslint-plugin-prettier
"
:
"
^3.4.1
"
,
...
...
@@ -66,7 +66,8 @@
"
ws
"
:
"
^8.3.0
"
},
"peerDependencies"
:
{
"koishi"
:
"^4.7.5"
"koishi"
:
"^4.8.2"
,
"koishi-plugin-cache-aragami"
:
"^1.0.4"
},
"jest"
:
{
"moduleFileExtensions"
:
[
...
...
src/index.ts
View file @
dcaaeb5c
// import 'source-map-support/register';
export
*
from
'
./config
'
;
import
{
YGOTournamentPluginConfig
}
from
'
./config
'
;
import
{
classToPlain
,
plainToClass
}
from
'
class-transformer
'
;
import
{
plainToClass
}
from
'
class-transformer
'
;
import
{
MatchWrapper
,
TournamentWrapper
}
from
'
./def/challonge
'
;
import
{
S3Client
}
from
'
@aws-sdk/client-s3
'
;
import
{
getSignedUrl
}
from
'
./presign
'
;
import
{
SRVProRoomInfo
}
from
'
./def/srvpro
'
;
import
moment
from
'
moment
'
;
import
{
DefinePlugin
,
Inject
,
selectContext
,
StarterPlugin
}
from
'
koishi-thirdeye
'
;
import
{
Cache
}
from
'
koishi
'
;
import
{
DefinePlugin
,
Inject
,
selectContext
,
StarterPlugin
,
}
from
'
koishi-thirdeye
'
;
import
AragamiPlugin
,
{
CacheKey
}
from
'
koishi-plugin-cache-aragami
'
;
export
interface
FromAndToTimeUnix
{
class
LateDeclarationTime
{
fromTime
:
number
;
toTime
:
number
;
@
CacheKey
()
key
()
{
return
'
current
'
;
}
}
declare
module
'
koishi
'
{
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace
Cache
{
interface
Tables
{
challongeData
:
any
;
lateDeclarationTime
:
FromAndToTimeUnix
;
}
}
class
ChallongeData
extends
TournamentWrapper
{
@
CacheKey
()
challongeId
:
string
;
}
@
DefinePlugin
()
...
...
@@ -30,32 +34,28 @@ export default class YGOTournamentPlugin extends StarterPlugin(
YGOTournamentPluginConfig
,
)
{
@
Inject
(
true
)
private
cache
:
Cache
;
private
aragami
:
AragamiPlugin
;
private
s3
:
S3Client
;
private
async
getChallongeCache
()
{
const
data
=
this
.
cache
.
get
(
'
challongeData
'
,
return
this
.
aragami
.
get
(
ChallongeData
,
this
.
config
.
tournament
.
challongeTournamentId
,
);
if
(
data
)
{
return
plainToClass
(
TournamentWrapper
,
data
);
}
}
private
async
deleteChallongeCache
()
{
return
this
.
cache
.
del
(
'
challongeData
'
,
return
this
.
aragami
.
get
(
ChallongeData
,
this
.
config
.
tournament
.
challongeTournamentId
,
);
}
private
async
setChallongeCache
(
data
:
TournamentWrapper
)
{
return
this
.
cache
.
set
(
'
challongeData
'
,
this
.
config
.
tournament
.
challongeTournamentId
,
classToPlain
(
data
),
);
return
this
.
aragami
.
set
(
ChallongeData
,
{
...
data
,
challongeId
:
this
.
config
.
tournament
.
challongeTournamentId
,
});
}
private
async
fetchChallongeData
()
{
...
...
@@ -63,7 +63,7 @@ export default class YGOTournamentPlugin extends StarterPlugin(
if
(
cached
)
{
return
cached
;
}
const
plain
=
await
this
.
ctx
.
http
.
get
(
const
data
=
await
this
.
ctx
.
http
.
get
(
`
${
this
.
config
.
tournament
.
getChallongeUrl
()}
.json`
,
{
params
:
{
...
...
@@ -73,9 +73,7 @@ export default class YGOTournamentPlugin extends StarterPlugin(
},
},
);
const
data
=
plainToClass
(
TournamentWrapper
,
plain
);
await
this
.
setChallongeCache
(
data
);
return
data
;
return
this
.
setChallongeCache
(
data
);
}
private
async
onUserQuit
(
userId
:
string
)
{
...
...
@@ -158,7 +156,7 @@ export default class YGOTournamentPlugin extends StarterPlugin(
}
private
async
onUserDeclareLate
(
userId
:
string
)
{
const
timeUnix
=
await
this
.
cache
.
get
(
'
lateDeclarationTime
'
,
'
current
'
);
const
timeUnix
=
await
this
.
aragami
.
get
(
LateDeclarationTime
,
'
current
'
);
// this.ctx.logger('test').warn(JSON.stringify(timeUnix));
if
(
!
timeUnix
||
...
...
@@ -306,7 +304,6 @@ export default class YGOTournamentPlugin extends StarterPlugin(
if
(
!
this
.
config
.
isTournamentEnabled
())
{
return
;
}
this
.
cache
.
table
(
'
lateDeclarationTime
'
,
{
maxAge
:
3600
*
1000
});
this
.
ctx
.
command
(
'
tournament/currentmatch
'
,
'
获取当前对局
'
)
.
shortcut
(
'
获取当前对局
'
)
...
...
@@ -373,14 +370,13 @@ export default class YGOTournamentPlugin extends StarterPlugin(
.
action
(
async
({
session
,
options
})
=>
{
const
fromTime
=
moment
().
add
(
options
.
delay
,
'
minutes
'
);
const
toTime
=
fromTime
.
clone
().
add
(
options
.
duration
,
'
minutes
'
);
await
this
.
cache
.
set
(
'
lateDeclarationTime
'
,
'
current
'
,
await
this
.
aragami
.
set
(
LateDeclarationTime
,
{
fromTime
:
fromTime
.
unix
(),
toTime
:
toTime
.
unix
(),
},
(
options
.
delay
+
options
.
duration
)
*
60000
,
{
ttl
:
(
options
.
delay
+
options
.
duration
)
*
60000
}
,
);
return
`设置成功。将允许在
${
fromTime
.
format
(
'
HH:mm:ss
'
,
...
...
@@ -390,14 +386,14 @@ export default class YGOTournamentPlugin extends StarterPlugin(
.
subcommand
(
'
.disablelate
'
,
'
关闭迟到杀
'
)
.
usage
(
'
不再允许选手进行迟到杀操作。
'
)
.
action
(
async
()
=>
{
await
this
.
cache
.
del
(
'
lateDeclarationTime
'
,
'
current
'
);
await
this
.
aragami
.
del
(
LateDeclarationTime
,
'
current
'
);
return
'
设置成功。选手不再允许进行迟到杀操作。
'
;
});
judgeCommand
.
subcommand
(
'
.refresh
'
,
'
清理 Challonge 缓存
'
)
.
action
(
async
()
=>
{
await
this
.
cache
.
del
(
'
challongeData
'
,
await
this
.
aragami
.
del
(
ChallongeData
,
this
.
config
.
tournament
.
challongeTournamentId
,
);
return
'
清理缓存成功。
'
;
...
...
tests/sample.spec.ts
View file @
dcaaeb5c
import
{
App
}
from
'
koishi
'
;
import
{
Context
}
from
'
koishi
'
;
import
TargetPlugin
from
'
../src
'
;
describe
(
'
Test of plugin.
'
,
()
=>
{
let
app
:
App
;
let
app
:
Context
;
beforeEach
(
async
()
=>
{
app
=
new
App
();
app
=
new
Context
();
// app.plugin(TargetPlugin);
await
app
.
start
();
});
...
...
webpack.config.js
View file @
dcaaeb5c
const
path
=
require
(
'
path
'
);
const
packgeInfo
=
require
(
'
./package.json
'
);
const
{
ESBuildMinifyPlugin
}
=
require
(
'
esbuild-loader
'
);
function
externalsFromDep
()
{
return
Object
.
fromEntries
(
...
...
@@ -43,4 +44,11 @@ module.exports = {
koishi
:
'
koishi
'
,
...(
packAll
?
{}
:
externalsFromDep
()),
},
optimization
:
{
minimizer
:
[
new
ESBuildMinifyPlugin
({
keepNames
:
true
,
}),
],
},
};
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