From 58231affc95075ac10222aeed83c56a462285f6a Mon Sep 17 00:00:00 2001 From: Matthew R Date: Thu, 9 Dec 2021 21:23:42 -0500 Subject: [PATCH] fixes --- src/commands/apply.ts | 3 ++- src/intervals/autoRelease.ts | 5 ++--- src/models/Member.ts | 2 ++ src/util/CloudServices.ts | 18 ++++++++++++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/commands/apply.ts b/src/commands/apply.ts index 17081cb..3f48655 100644 --- a/src/commands/apply.ts +++ b/src/commands/apply.ts @@ -88,13 +88,14 @@ export default class Apply extends Command { func: async (client: Client, ...data: any[]) => { const dmember = await client.guilds.get(client.config.guildID).getRESTMember(data[0]); const member = await this.client.db.Member.findOne({ userID: dmember.id }).lean().exec(); + const csAccount = await CloudServicesUtil.fetchAccountStatus(member.id, this.client.config.internalKey); if (!member) { const addMember = new this.client.db.Member({ userID: dmember.id, }); await addMember.save(); } - await this.client.db.Member.updateOne({ userID: dmember.id }, { $set: { misc: { t3TemporaryExpiration: { processed: false, date: new Date(Date.now() + 129600000) } } } }); + await this.client.db.Member.updateOne({ userID: dmember.id }, { $set: { misc: { t3TemporaryExpiration: { processed: false, date: new Date(Date.now() + 129600000), previousTier: csAccount.tier } } } }); await CloudServicesUtil.upgradeT2(dmember.id, this.client.config.internalKey); }, diff --git a/src/intervals/autoRelease.ts b/src/intervals/autoRelease.ts index 21bf63d..fc4bd94 100644 --- a/src/intervals/autoRelease.ts +++ b/src/intervals/autoRelease.ts @@ -14,9 +14,8 @@ export default function checkLock(client: Client): NodeJS.Timeout { members.forEach(async (member) => { if (member.misc?.t3TemporaryExpiration?.processed === false) { if (new Date() > member.misc?.t3TemporaryExpiration?.date) { - await member.updateOne({ 'misc.t3TemporaryExpiration.processed': true }); - - await CloudServicesUtil.downgradeT2(member.id, client.config.internalKey); + await CloudServicesUtil.setTier(member.id, member.misc.t3TemporaryExpiration.previousTier, client.config.internalKey); + await member.updateOne({ 'misc.t3TemporaryExpiration.processed': true, 'misc.t3TemporaryExpiration.previousTier': null }); } } }); diff --git a/src/models/Member.ts b/src/models/Member.ts index 62abd3e..36f277d 100644 --- a/src/models/Member.ts +++ b/src/models/Member.ts @@ -13,6 +13,7 @@ export interface MemberInterface extends Document { t3TemporaryExpiration?: { date: Date, processed: boolean + previousTier: 1 | 2 | 3 } } x509?: string, @@ -32,6 +33,7 @@ const Member: Schema = new Schema({ t3TemporaryExpiration: { date: Date, processed: Boolean, + previousTier: 1, }, }, x509: String, diff --git a/src/util/CloudServices.ts b/src/util/CloudServices.ts index f4d20f2..82c0844 100644 --- a/src/util/CloudServices.ts +++ b/src/util/CloudServices.ts @@ -37,6 +37,24 @@ export default class CloudServicesUtil { return response.status; } + static async setTier(userID: string, tier: 1 | 2 | 3, authorization: string) { + let responseStatus: number; + switch (tier) { + case 1: + responseStatus = (await axios.get(`https://api.cloud.libraryofcode.org/wh/t2-rm?userID=${userID}&auth=${authorization}`)).status; + break; + case 2: + responseStatus = (await axios.get(`https://api.cloud.libraryofcode.org/wh/t2?userID=${userID}&auth=${authorization}`)).status; + break; + case 3: + responseStatus = (await axios.get(`https://api.cloud.libraryofcode.org/wh/t3?userID=${userID}&auth=${authorization}`)).status; + break; + default: + throw new RangeError('Invalid Tier.'); + } + return responseStatus; + } + static async fetchAccountStatus(userID: string, authorization: string) { const response = (await axios.get(`https://api.cloud.libraryofcode.org/wh/score?id=${userID}&authorization=${authorization}`)).data; if (!response.found) return null;