Add hoarding
This commit is contained in:
@@ -29,6 +29,7 @@ import { APP_INTERCEPTOR } from '@nestjs/core';
|
||||
import { JunkDrawerModule } from './junk-drawer/junk-drawer.module';
|
||||
import { EmailModule } from './email/email.module';
|
||||
import { ContactModule } from './contact/contact.module';
|
||||
import { HoardingModule } from './hoarding/hoarding.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -104,6 +105,7 @@ import { ContactModule } from './contact/contact.module';
|
||||
JunkDrawerModule,
|
||||
EmailModule,
|
||||
ContactModule,
|
||||
HoardingModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [
|
||||
|
@@ -17,7 +17,7 @@ export default () => ({
|
||||
channel: process.env.IRC_CHANNEL ?? '#usdev',
|
||||
password: process.env.IRC_PASSWORD ?? '',
|
||||
nick:
|
||||
process.env.IRC_NICK ?? process.env.NODE_ENV === 'production'
|
||||
(process.env.IRC_NICK ?? process.env.NODE_ENV === 'production')
|
||||
? 'us-bot'
|
||||
: 'us-dev',
|
||||
},
|
||||
@@ -35,6 +35,9 @@ export default () => ({
|
||||
process.env.FILE_DEFAULT_TTL ?? (30 * 24 * 60 * 60).toString(),
|
||||
),
|
||||
},
|
||||
s3: {
|
||||
bucketName: process.env.S3_BUCKET ?? 'api.us.dev',
|
||||
},
|
||||
focoLive: {
|
||||
airtable: {
|
||||
apiKey: process.env.FOCO_LIVE_AIRTABLE_APIKEY ?? '',
|
||||
|
8
src/hoarding/hoarding.module.ts
Normal file
8
src/hoarding/hoarding.module.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { HoardingService } from './hoarding.service';
|
||||
import { MinioService } from 'src/minio/minio.service';
|
||||
|
||||
@Module({
|
||||
providers: [HoardingService, MinioService],
|
||||
})
|
||||
export class HoardingModule {}
|
38
src/hoarding/hoarding.service.ts
Normal file
38
src/hoarding/hoarding.service.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { Cron } from '@nestjs/schedule';
|
||||
import axios from 'axios';
|
||||
import { MinioService } from 'src/minio/minio.service';
|
||||
|
||||
@Injectable()
|
||||
export class HoardingService {
|
||||
private readonly logger: Logger = new Logger(HoardingService.name);
|
||||
constructor(public readonly minioService: MinioService) {
|
||||
this.hoardChessStats();
|
||||
}
|
||||
|
||||
@Cron('0 0 1 * * *')
|
||||
async hoardChessStats() {
|
||||
await this.hoardUserChessStats('letmutchessplayer');
|
||||
await this.hoardUserChessStats('archyotype');
|
||||
}
|
||||
|
||||
async hoardUserChessStats(user: string) {
|
||||
this.logger.log(`Hoarding chess.com stats for ${user}`);
|
||||
const chessState = (id: string) =>
|
||||
`https://api.chess.com/pub/player/${id}/stats`;
|
||||
const stats = await axios.get(chessState(user));
|
||||
|
||||
const time = new Date().getTime();
|
||||
await this.minioService.uploadBuffer(
|
||||
this.minioService.defaultBucketName,
|
||||
`hoarding/chess.com-stats/${user}/${time}-${user}.json`,
|
||||
Buffer.from(
|
||||
JSON.stringify({
|
||||
time,
|
||||
data: stats.data,
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user