Commit 1cc42437 authored by nanahira's avatar nanahira

fix cache inject

parent 5f4e8d25
......@@ -7,7 +7,8 @@ import { S3Client } from '@aws-sdk/client-s3';
import { getSignedUrl } from './presign';
import { SRVProRoomInfo } from './def/srvpro';
import moment from 'moment';
import { DefinePlugin, StarterPlugin } from 'koishi-thirdeye';
import { DefinePlugin, Inject, StarterPlugin } from 'koishi-thirdeye';
import { Cache } from 'koishi';
export interface FromAndToTimeUnix {
fromTime: number;
......@@ -28,9 +29,12 @@ declare module 'koishi' {
export default class YGOTournamentPlugin extends StarterPlugin(
YGOTournamentPluginConfig,
) {
@Inject(true)
private cache: Cache;
private s3: S3Client;
private async getChallongeCache() {
const data = this.ctx.cache.get(
const data = this.cache.get(
'challongeData',
this.config.tournament.challongeTournamentId,
);
......@@ -40,14 +44,14 @@ export default class YGOTournamentPlugin extends StarterPlugin(
}
private async deleteChallongeCache() {
return this.ctx.cache.del(
return this.cache.del(
'challongeData',
this.config.tournament.challongeTournamentId,
);
}
private async setChallongeCache(data: TournamentWrapper) {
return this.ctx.cache.set(
return this.cache.set(
'challongeData',
this.config.tournament.challongeTournamentId,
classToPlain(data),
......@@ -154,7 +158,7 @@ export default class YGOTournamentPlugin extends StarterPlugin(
}
private async onUserDeclareLate(userId: string) {
const timeUnix = await this.ctx.cache.get('lateDeclarationTime', 'current');
const timeUnix = await this.cache.get('lateDeclarationTime', 'current');
// this.ctx.logger('test').warn(JSON.stringify(timeUnix));
if (
!timeUnix ||
......@@ -302,7 +306,7 @@ export default class YGOTournamentPlugin extends StarterPlugin(
if (!this.config.isTournamentEnabled()) {
return;
}
this.ctx.cache.table('lateDeclarationTime', { maxAge: 3600 * 1000 });
this.cache.table('lateDeclarationTime', { maxAge: 3600 * 1000 });
this.ctx
.command('tournament/currentmatch', '获取当前对局')
.shortcut('获取当前对局')
......@@ -370,7 +374,7 @@ 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.ctx.cache.set(
await this.cache.set(
'lateDeclarationTime',
'current',
{
......@@ -387,13 +391,13 @@ export default class YGOTournamentPlugin extends StarterPlugin(
.subcommand('.disablelate', '关闭迟到杀')
.usage('不再允许选手进行迟到杀操作。')
.action(async () => {
await this.ctx.cache.del('lateDeclarationTime', 'current');
await this.cache.del('lateDeclarationTime', 'current');
return '设置成功。选手不再允许进行迟到杀操作。';
});
judgeCommand
.subcommand('.refresh', '清理 Challonge 缓存')
.action(async () => {
await this.ctx.cache.del(
await this.cache.del(
'challongeData',
this.config.tournament.challongeTournamentId,
);
......
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