Commit dcaaeb5c authored by nanahira's avatar nanahira

bump to Koishi 4.8

parent 5bbd0b89
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-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": "^10.3.2",
"koishi-thirdeye": "^11.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": [
......
// 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 '清理缓存成功。';
......
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