Commit 1cc42437 authored by nanahira's avatar nanahira

fix cache inject

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