1
0
Fork 0

add t2 apply

refactor/models
Matthew 2020-10-06 22:53:48 -04:00
parent fa4df85a67
commit aea3604681
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
3 changed files with 75 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import type { AxiosError } from 'axios'; import type { AxiosError } from 'axios';
import axios from 'axios'; import axios from 'axios';
import { response } from 'express';
export interface SoftReport { export interface SoftReport {
status: 'SUCCESS' | 'UNAUTHORIZED' | 'PERMISSION_DENIED' | 'CLIENT_ERROR' | 'SERVER_ERROR'; status: 'SUCCESS' | 'UNAUTHORIZED' | 'PERMISSION_DENIED' | 'CLIENT_ERROR' | 'SERVER_ERROR';
@ -18,6 +19,24 @@ export interface HardReport extends SoftReport {
} }
export default class Report { export default class Report {
public static async tier2(userID: string, auth: string) {
try {
const { data } = await axios({
method: 'get',
url: `https://eds.libraryofcode.org/cs/t2?userID=${userID}&auth=${auth}`,
});
return {
status: 'SUCCESS',
decision: data.decision,
};
} catch (err) {
const error = <AxiosError>err;
if (error.response?.status === 404 || error.response.status === 400 || error.response.status === 401) return { status: 'CLIENT_ERROR', decision: 'PRE-DECLINED' };
return { status: 'SERVER_ERROR', decision: 'PRE-DECLINED' };
}
}
public static async getPIN(userID: string, auth: string): Promise<{ status: 'SUCCESS' | 'UNAUTHORIZED' | 'PERMISSION_DENIED' | 'CLIENT_ERROR' | 'SERVER_ERROR'; pin?: number[] }> { public static async getPIN(userID: string, auth: string): Promise<{ status: 'SUCCESS' | 'UNAUTHORIZED' | 'PERMISSION_DENIED' | 'CLIENT_ERROR' | 'SERVER_ERROR'; pin?: number[] }> {
try { try {
const { data } = await axios({ const { data } = await axios({

55
src/commands/applyt2.ts Normal file
View File

@ -0,0 +1,55 @@
import { Message } from 'eris';
import { Client, Command, Report, RichEmbed } from '../class';
export default class ApplyT2 extends Command {
constructor(client: Client) {
super(client);
this.name = 'apply-t2';
this.description = 'Applies for Tier 2.';
this.enabled = true;
this.guildOnly = true;
this.aliases = ['t2'];
this.usage = `${this.client.config.prefix}apply-t2`;
}
public async run(message: Message, args: string[]) { // eslint-disable-line
try {
if (!args.length) return this.client.commands.get('help').run(message, [this.name]);
const account = await this.client.db.Account.findOne({ userID: message.author.id });
if (!account) return this.error(message.channel, 'I can\'t find a CS Account for you.');
if (account.tier > 1) return this.error(message.channel, 'You cannot apply for Tier 2 if you already have Tier 2 or higher.');
const loading = await this.loading(message.channel, 'Please wait a moment, processing application...');
const decision = await Report.tier2(account.userID, this.client.config.internalKey);
if (decision.status !== 'SUCCESS') {
await loading.delete();
this.success(message.channel, `__**Decision**__\n\n**Status:** ${decision.decision}\n**Processed by:** EDS (A*01)`);
if (decision.decision === 'APPROVED') {
const tier = await this.client.db.Tier.findOne({ id: 2 });
if (account.ramLimitNotification !== -1) {
await account.updateOne({ $set: { tier: 2, ramLimitNotification: tier.resourceLimits.ram - 20 } });
} else {
await account.updateOne({ $set: { tier: 2 } });
}
const embed = new RichEmbed();
embed.setTitle('Cloud Account | Tier Change');
embed.setColor('#0099ff');
embed.addField('User', `${account.username} | <@${account.userID}>`, true);
embed.addField('Technician', 'SYSTEM', true);
embed.addField('Old Tier -> New Tier', `${account.tier} -> ${args[1]}`, true);
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setTimestamp();
await this.client.util.sendMessageToUserTerminal(account.username, 'A technician has changed your tier to 2').catch(() => { });
this.client.createMessage('580950455581147146', { embed }); return this.client.getDMChannel(account.userID).then((channel) => channel.createMessage({ embed })).catch();
}
return null;
}
await loading.delete();
return this.success(message.channel, `__**Decision**__\n\n**Status:** ${decision.decision}\n**Processed by:** EDS (A*01)\n\n\n*Pre-Declines will not result in a hard pull, and they may be due to a server issue or insufficient information. You may want to contact a Staff member for further information.`);
} catch (error) {
return this.client.util.handleError(error, message, this);
}
}
}

View File

@ -1,5 +1,6 @@
export { default as addreferral } from './addreferral'; export { default as addreferral } from './addreferral';
export { default as announce } from './announce'; export { default as announce } from './announce';
export { default as applyt2 } from './applyt2';
export { default as authreferral } from './authreferral'; export { default as authreferral } from './authreferral';
export { default as bearer } from './bearer'; export { default as bearer } from './bearer';
export { default as cloudflare } from './cloudflare'; export { default as cloudflare } from './cloudflare';