Commit 3e15baa8 authored by nanahira's avatar nanahira

bump to Koishi 4.8

parent 7d10ffe8
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(CachePlugin);
app.plugin(AragamiPlugin);
app.plugin(DatabasePlugin);
// Some extras
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -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": "^10.3.2",
"koishi-thirdeye": "^11.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": [
......
// 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) {
......
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();
});
......
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,
}),
],
},
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment