97 lines
3.3 KiB
TypeScript
97 lines
3.3 KiB
TypeScript
import mongoose from 'mongoose'
|
|
import * as dotenv from 'dotenv'
|
|
|
|
const envFile = process.env.NODE_ENV && process.env.NODE_ENV === 'production' ? `.env.production` : '.env.development'
|
|
dotenv.config({ path: envFile })
|
|
console.log(process.env.DB_MAIN)
|
|
import { ActivityChest } from 'models/ActivityChest'
|
|
import { VoucherRecord } from 'models/VoucherRecord'
|
|
import { NFTHolderRecord } from 'models/NFTHodlerRecord'
|
|
import { TicketRecord } from 'models/TicketRecord'
|
|
const db = mongoose.connection
|
|
|
|
;(async () => {
|
|
try {
|
|
await mongoose.connect(process.env.DB_MAIN)
|
|
let chests = await ActivityChest.find({})
|
|
// 过滤掉箱子码开出来的箱子
|
|
console.log('箱子总数: ', chests.length)
|
|
let voucherChestSet = new Set()
|
|
let voucherRecords = await VoucherRecord.find({ status: 9 })
|
|
for (let record of voucherRecords) {
|
|
if (record.chests.length > 0) {
|
|
voucherChestSet.add(record.chests[0])
|
|
}
|
|
}
|
|
let chestsLeft = []
|
|
for (let chest of chests) {
|
|
if (!voucherChestSet.has(chest.id)) {
|
|
chestsLeft.push(chest)
|
|
}
|
|
}
|
|
console.log('过滤掉箱子码开出来的箱子: ', voucherChestSet.size, '剩余: ', chestsLeft.length)
|
|
// 过滤掉正常合作伙伴nft holeder的箱子
|
|
let nftHolderRecords = await NFTHolderRecord.find({})
|
|
let nftHolderChestSet = new Set()
|
|
for (let record of nftHolderRecords) {
|
|
if (record.rewards.length > 0) {
|
|
nftHolderChestSet.add(record.rewards[0])
|
|
}
|
|
}
|
|
let chestsLeft2 = []
|
|
for (let chest of chestsLeft) {
|
|
if (!nftHolderChestSet.has(chest.id)) {
|
|
chestsLeft2.push(chest)
|
|
}
|
|
}
|
|
console.log('过滤掉正常NFT holder记录的箱子: ', nftHolderChestSet.size, '剩余: ', chestsLeft2.length)
|
|
// 根据探索记录时间和箱子生成时间过滤正常的箱子
|
|
let ticketRecords = await TicketRecord.find({ score: { $lt: 0 } })
|
|
let exploreChestSet = new Set()
|
|
for (let ticketRecord of ticketRecords) {
|
|
// query chest createAt between ticketRecord.createAt and ticketRecord.createAt - 1 second
|
|
let total = Math.abs(ticketRecord.score)
|
|
let chestArr = []
|
|
for (let chest of chestsLeft2) {
|
|
if (
|
|
chest.user === ticketRecord.user &&
|
|
// @ts-ignore
|
|
chest.createdAt < ticketRecord.createdAt &&
|
|
// @ts-ignore
|
|
chest.createdAt > ticketRecord.createdAt - 1000
|
|
) {
|
|
chestArr.push(chest)
|
|
}
|
|
}
|
|
// 有限保留已开过和品质高的箱子
|
|
chestArr.sort((a, b) => {
|
|
return b.status - a.status
|
|
})
|
|
let count = 0
|
|
for (let chest of chestArr) {
|
|
if (count >= total) {
|
|
break
|
|
}
|
|
exploreChestSet.add(chest.id)
|
|
count++
|
|
}
|
|
}
|
|
let chestsLeft3 = []
|
|
for (let chest of chestsLeft2) {
|
|
if (!exploreChestSet.has(chest.id)) {
|
|
chestsLeft3.push(chest)
|
|
}
|
|
}
|
|
console.log(chestsLeft3.length)
|
|
console.log('过滤掉探索获得的箱子: ', exploreChestSet.size, '剩余: ', chestsLeft3.length)
|
|
let file = require('fs')
|
|
let ids = chestsLeft3.map(chest => chest.id)
|
|
file.writeFileSync('initdatas/chest_id.txt', ids.join('\n'))
|
|
|
|
console.log('Finished repair box data in the database')
|
|
} catch (e) {
|
|
console.log(e)
|
|
}
|
|
process.exit(0)
|
|
})()
|