fixes
parent
da81eeb11e
commit
58231affc9
|
@ -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);
|
||||
},
|
||||
|
|
|
@ -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 });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<CSDAccountStatusBasic>(`https://api.cloud.libraryofcode.org/wh/score?id=${userID}&authorization=${authorization}`)).data;
|
||||
if (!response.found) return null;
|
||||
|
|
Loading…
Reference in New Issue