master
Matthew 2021-12-09 21:23:42 -05:00
parent da81eeb11e
commit 58231affc9
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
4 changed files with 24 additions and 4 deletions

View File

@ -88,13 +88,14 @@ export default class Apply extends Command {
func: async (client: Client, ...data: any[]) => { func: async (client: Client, ...data: any[]) => {
const dmember = await client.guilds.get(client.config.guildID).getRESTMember(data[0]); 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 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) { if (!member) {
const addMember = new this.client.db.Member({ const addMember = new this.client.db.Member({
userID: dmember.id, userID: dmember.id,
}); });
await addMember.save(); 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); await CloudServicesUtil.upgradeT2(dmember.id, this.client.config.internalKey);
}, },

View File

@ -14,9 +14,8 @@ export default function checkLock(client: Client): NodeJS.Timeout {
members.forEach(async (member) => { members.forEach(async (member) => {
if (member.misc?.t3TemporaryExpiration?.processed === false) { if (member.misc?.t3TemporaryExpiration?.processed === false) {
if (new Date() > member.misc?.t3TemporaryExpiration?.date) { if (new Date() > member.misc?.t3TemporaryExpiration?.date) {
await member.updateOne({ 'misc.t3TemporaryExpiration.processed': true }); await CloudServicesUtil.setTier(member.id, member.misc.t3TemporaryExpiration.previousTier, client.config.internalKey);
await member.updateOne({ 'misc.t3TemporaryExpiration.processed': true, 'misc.t3TemporaryExpiration.previousTier': null });
await CloudServicesUtil.downgradeT2(member.id, client.config.internalKey);
} }
} }
}); });

View File

@ -13,6 +13,7 @@ export interface MemberInterface extends Document {
t3TemporaryExpiration?: { t3TemporaryExpiration?: {
date: Date, date: Date,
processed: boolean processed: boolean
previousTier: 1 | 2 | 3
} }
} }
x509?: string, x509?: string,
@ -32,6 +33,7 @@ const Member: Schema = new Schema({
t3TemporaryExpiration: { t3TemporaryExpiration: {
date: Date, date: Date,
processed: Boolean, processed: Boolean,
previousTier: 1,
}, },
}, },
x509: String, x509: String,

View File

@ -37,6 +37,24 @@ export default class CloudServicesUtil {
return response.status; 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) { 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; const response = (await axios.get<CSDAccountStatusBasic>(`https://api.cloud.libraryofcode.org/wh/score?id=${userID}&authorization=${authorization}`)).data;
if (!response.found) return null; if (!response.found) return null;