Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
koishi-plugin-tabulate
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-tabulate
Commits
3e15baa8
Commit
3e15baa8
authored
Jul 25, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bump to Koishi 4.8
parent
7d10ffe8
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1646 additions
and
558 deletions
+1646
-558
dev/index.ts
dev/index.ts
+5
-5
package-lock.json
package-lock.json
+1592
-515
package.json
package.json
+8
-7
src/index.ts
src/index.ts
+30
-28
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 @
3e15baa8
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 @
3e15baa8
This source diff could not be displayed because it is too large. You can
view the blob
instead.
package.json
View file @
3e15baa8
...
...
@@ -24,7 +24,7 @@
"ygo"
,
"yugioh"
,
"ygopro"
,
"required:cache"
"required:cache
-aragami
"
],
"bugs"
:
{
"url"
:
"
https://code.mycard.moe/3rdeye/koishi-plugin-tabulate/issues
"
...
...
@@ -32,22 +32,22 @@
"homepage"
:
"
https://code.mycard.moe/3rdeye/koishi-plugin-tabulate
"
,
"dependencies"
:
{
"
class-transformer
"
:
"
^0.5.1
"
,
"
koishi-thirdeye
"
:
"
^1
0.3.2
"
,
"
koishi-thirdeye
"
:
"
^1
1.0.6
"
,
"
league-tabulator
"
:
"
^1.0.0
"
,
"
lodash
"
:
"
^4.17.21
"
,
"
moment
"
:
"
^2.29.1
"
,
"
reflect-metadata
"
:
"
^0.1.13
"
},
"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/lodash
"
:
"
^4.14.176
"
,
"
@types/node
"
:
"
^16.11.7
"
,
"
@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
"
,
...
...
@@ -63,7 +63,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 @
3e15baa8
// import 'source-map-support/register';
import
{
Context
,
Cache
,
Session
}
from
'
koishi
'
;
import
{
Context
,
Session
}
from
'
koishi
'
;
import
{
TabulatePluginConfig
,
TabulatePluginConfigLike
}
from
'
./config
'
;
import
{
DefinePlugin
,
InjectConfig
,
Inject
,
OnApply
,
UseCommand
,
CommandUsage
,
CommandExample
,
...
...
@@ -15,53 +14,56 @@ import {
CommandDescription
,
}
from
'
koishi-thirdeye
'
;
import
{
Game
,
ReportScoreResult
}
from
'
league-tabulator
'
;
import
{
classToPlain
,
plainToClass
}
from
'
class-transformer
'
;
import
{
plainToInstance
,
Transform
}
from
'
class-transformer
'
;
import
_
from
'
lodash
'
;
export
*
from
'
./config
'
;
import
AragamiPlugin
,
{
CacheKey
}
from
'
koishi-plugin-cache-aragami
'
;
declare
module
'
koishi
'
{
namespace
Cache
{
interface
Tables
{
tabulateMatches
:
Record
<
string
,
Partial
<
Game
>>
;
}
}
class
TabulateMatches
{
@
CacheKey
()
location
:
string
;
@
Transform
((
params
)
=>
_
.
mapValues
(
params
.
value
,
(
v
)
=>
plainToInstance
(
Game
,
v
)),
)
games
:
Record
<
string
,
Game
>
;
}
@
DefinePlugin
({
name
:
'
tabulate
'
,
schema
:
TabulatePluginConfig
})
export
default
class
TabulatePlugin
implements
OnApply
{
export
default
class
TabulatePlugin
{
constructor
(
private
ctx
:
Context
,
config
:
TabulatePluginConfigLike
)
{}
async
getGames
(
key
:
string
)
{
const
dataFromCache
=
(
await
this
.
cache
.
get
(
'
tabulateMatches
'
,
key
))
||
{};
return
_
.
mapValues
(
dataFromCache
,
(
d
)
=>
plainToClass
(
Game
,
d
));
let
data
=
await
this
.
aragami
.
get
(
TabulateMatches
,
key
);
if
(
data
)
{
return
data
;
}
data
=
new
TabulateMatches
();
data
.
games
=
{};
data
.
location
=
key
;
return
data
;
}
async
saveGame
(
game
:
Game
)
{
const
dataFromCache
=
(
await
this
.
cache
.
get
(
'
tabulateMatches
'
,
game
.
location
))
||
{};
dataFromCache
[
game
.
getKey
()]
=
classToPlain
(
game
);
return
this
.
cache
.
set
(
'
tabulateMatches
'
,
game
.
location
,
dataFromCache
);
const
matches
=
await
this
.
getGames
(
game
.
location
);
matches
.
games
[
game
.
getKey
()]
=
game
;
return
this
.
aragami
.
set
(
matches
,
{
ttl
:
this
.
config
.
saveTime
});
}
async
deleteGame
(
game
:
Game
)
{
const
dataFromCache
=
(
await
this
.
cache
.
get
(
'
tabulateMatches
'
,
game
.
location
))
||
{};
if
(
!
dataFromCache
[
game
.
getKey
()])
{
const
matches
=
await
this
.
getGames
(
game
.
location
);
if
(
!
matches
.
games
[
game
.
getKey
()])
{
return
;
}
delete
dataFromCache
[
game
.
getKey
()];
return
this
.
cache
.
set
(
'
tabulateMatches
'
,
game
.
location
,
dataFromCache
);
delete
matches
.
games
[
game
.
getKey
()];
return
this
.
aragami
.
set
(
matches
,
{
ttl
:
this
.
config
.
saveTime
}
);
}
@
InjectConfig
()
private
config
:
TabulatePluginConfig
;
@
Inject
(
'
cache
'
,
true
)
private
cache
:
Cache
;
onApply
()
{
this
.
cache
.
table
(
'
tabulateMatches
'
,
{
maxAge
:
this
.
config
.
saveTime
});
}
@
Inject
(
true
)
private
aragami
:
AragamiPlugin
;
@
UseCommand
(
'
tabulate
'
,
'
排表
'
)
@
CommandDescription
({
en
:
'
Tabulate
'
})
...
...
@@ -175,7 +177,7 @@ export default class TabulatePlugin implements OnApply {
]),
);
const
gamesMap
=
await
this
.
getGames
(
exactLocation
);
const
game
=
Object
.
values
(
gamesMap
).
find
((
game
)
=>
const
game
=
Object
.
values
(
gamesMap
.
games
).
find
((
game
)
=>
game
.
includesPendingPlayer
(
possibleNames
),
);
if
(
!
game
)
{
...
...
tests/sample.spec.ts
View file @
3e15baa8
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 @
3e15baa8
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