73 lines
2.0 KiB
TypeScript
73 lines
2.0 KiB
TypeScript
import "dotenv/config"
|
|
|
|
import fs from 'fs/promises'
|
|
import { exec as execCb } from 'child_process'
|
|
import { promisify } from 'util'
|
|
|
|
import pino from 'pino'
|
|
|
|
import * as Minio from 'minio'
|
|
import Vision from '@google-cloud/vision'
|
|
import { PrismaClient } from '@prisma/client'
|
|
import { MeiliSearch } from 'meilisearch'
|
|
|
|
import discordScraper from './src/scraper'
|
|
import attachmentService from "./src/attachments"
|
|
import memeService from "./src/memes"
|
|
|
|
// @ts-ignore - ts don't know wtf it talking about
|
|
BigInt.prototype.toJSON = function bigIntStringify() {
|
|
return this.toString();
|
|
};
|
|
|
|
const exec = promisify(execCb)
|
|
|
|
async function main() {
|
|
const log = pino({ base: {} });
|
|
const VISION_CREDENTIALS = JSON.parse(process.env.VISION_CREDENTIALS)
|
|
|
|
const vision = new Vision.ImageAnnotatorClient({ credentials: VISION_CREDENTIALS })
|
|
const prisma = new PrismaClient()
|
|
const minio = new Minio.Client({
|
|
endPoint: process.env.STORAGE_ENDPOINT,
|
|
accessKey: process.env.STORAGE_ACCESS_KEY,
|
|
secretKey: process.env.STORAGE_SECRET_KEY,
|
|
useSSL: false,
|
|
port: 9000,
|
|
})
|
|
|
|
const meili = new MeiliSearch({
|
|
host: process.env.MEILI_URL,
|
|
apiKey: process.env.MEILI_MASTER_KEY,
|
|
})
|
|
|
|
const memes = await memeService(log, prisma, meili)
|
|
const attachments = await attachmentService(log, minio, prisma, memes)
|
|
const scraper = await discordScraper(process.env.DISCORD_AUTH, vision, minio, prisma, log, attachments)
|
|
|
|
const CHANNEL_IDS = [
|
|
// 367936426962190336n, // TPM shitposts
|
|
// 367936467592413194n, // tpm screenshots
|
|
// 1028511952277864501n, // tpm sludge
|
|
// 725835129326665768n, // machinegirl memes
|
|
1095060717117374687n, // aella memes
|
|
]
|
|
|
|
async function migrateDb() {
|
|
const output = await exec('prisma migrate deploy')
|
|
log.info(output)
|
|
}
|
|
|
|
await migrateDb()
|
|
|
|
log.info('ready')
|
|
|
|
await Promise.all(CHANNEL_IDS.map(id => scraper.processChannel(id)))
|
|
}
|
|
|
|
main()
|
|
.then(() => true)
|
|
.catch(e => console.error(e))
|
|
|
|
|