add ability to req temporary t3 thru eds
parent
8ce7f51f8d
commit
95468f3cf1
|
@ -1,28 +1,29 @@
|
|||
# Package Management & Libraries
|
||||
node_modules
|
||||
.yarn
|
||||
#.yarn/*
|
||||
#!.yarn/cache
|
||||
#!.yarn/patches
|
||||
#!.yarn/plugins
|
||||
#!.yarn/releases
|
||||
#!.yarn/sdks
|
||||
#!.yarn/versions
|
||||
|
||||
# Configuration Files
|
||||
config.yaml
|
||||
configs/config.yaml
|
||||
src/config.yaml
|
||||
build/config.yaml
|
||||
.vscode
|
||||
yarn-error.log
|
||||
google.json
|
||||
src/google.json
|
||||
build/google.json
|
||||
|
||||
# Build/Distribution Files
|
||||
build
|
||||
dist
|
||||
|
||||
# Storage/DB Files
|
||||
localstorage
|
||||
# Package Management & Libraries
|
||||
node_modules
|
||||
.yarn
|
||||
#.yarn/*
|
||||
#!.yarn/cache
|
||||
#!.yarn/patches
|
||||
#!.yarn/plugins
|
||||
#!.yarn/releases
|
||||
#!.yarn/sdks
|
||||
#!.yarn/versions
|
||||
|
||||
# Configuration Files
|
||||
config.yaml
|
||||
configs/config.yaml
|
||||
src/config.yaml
|
||||
build/config.yaml
|
||||
.vscode
|
||||
.idea
|
||||
yarn-error.log
|
||||
google.json
|
||||
src/google.json
|
||||
build/google.json
|
||||
|
||||
# Build/Distribution Files
|
||||
build
|
||||
dist
|
||||
|
||||
# Storage/DB Files
|
||||
localstorage
|
||||
|
|
File diff suppressed because it is too large
Load Diff
134
package.json
134
package.json
|
@ -1,67 +1,67 @@
|
|||
{
|
||||
"name": "loccr",
|
||||
"version": "1.0.0",
|
||||
"description": "The official system for handling Community Relations in the LOC Discord server.",
|
||||
"main": "build/main.js",
|
||||
"scripts": {
|
||||
"lint": "eslint -c ./.eslintrc.json src --ext ts"
|
||||
},
|
||||
"repository": "https://gitlab.libraryofcode.org/engineering/communityrelations.git",
|
||||
"author": "Matthew R, AD, FSEN <matthew@staff.libraryofcode.org>",
|
||||
"license": "AGPL-3.0",
|
||||
"devDependencies": {
|
||||
"@types/ari-client": "^2.2.2",
|
||||
"@types/auth0": "^2.33.3",
|
||||
"@types/bull": "^3.14.4",
|
||||
"@types/cron": "^1.7.2",
|
||||
"@types/express": "^4.17.6",
|
||||
"@types/helmet": "^0.0.47",
|
||||
"@types/jsonwebtoken": "^8.5.0",
|
||||
"@types/mathjs": "^6.0.7",
|
||||
"@types/mongoose": "^5.7.19",
|
||||
"@types/node": "^14.14.25",
|
||||
"@types/nodemailer": "^6.4.0",
|
||||
"@types/puppeteer": "^5.4.3",
|
||||
"@types/signale": "^1.4.1",
|
||||
"@types/uuid": "^7.0.3",
|
||||
"@typescript-eslint/eslint-plugin": "^2.33.0",
|
||||
"@typescript-eslint/parser": "^2.33.0",
|
||||
"eslint": "^7.19.0",
|
||||
"eslint-config-airbnb-base": "^14.1.0",
|
||||
"eslint-plugin-import": "^2.20.2",
|
||||
"tslib": "^2.1.0",
|
||||
"typescript": "^3.9.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@google-cloud/text-to-speech": "^3.1.2",
|
||||
"ari-client": "^2.2.0",
|
||||
"asterisk-manager": "^0.1.16",
|
||||
"auth0": "^2.35.0",
|
||||
"awesome-phonenumber": "^2.45.0",
|
||||
"axios": "^0.19.2",
|
||||
"body-parser": "^1.19.0",
|
||||
"brain.js": "^2.0.0-beta.2",
|
||||
"bull": "^3.20.1",
|
||||
"cheerio": "^1.0.0-rc.5",
|
||||
"cron": "^1.8.2",
|
||||
"eris": "^0.15.0",
|
||||
"eris-pagination": "github:bsian03/eris-pagination",
|
||||
"express": "^4.17.1",
|
||||
"helmet": "^3.22.0",
|
||||
"ioredis": "^4.26.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"mathjs": "^7.6.0",
|
||||
"moment": "^2.25.3",
|
||||
"mongoose": "^5.11.15",
|
||||
"nanoid": "^3.1.22",
|
||||
"nodemailer": "^6.4.8",
|
||||
"pluris": "^0.2.5",
|
||||
"puppeteer": "^5.5.0",
|
||||
"sd-notify": "^2.8.0",
|
||||
"signale": "^1.4.0",
|
||||
"stock-info": "^1.2.0",
|
||||
"stripe": "^8.120.0",
|
||||
"uuid": "^8.0.0",
|
||||
"yaml": "^1.9.2"
|
||||
}
|
||||
}
|
||||
{
|
||||
"name": "loccr",
|
||||
"version": "1.0.0",
|
||||
"description": "The official system for handling Community Relations in the LOC Discord server.",
|
||||
"main": "build/main.js",
|
||||
"scripts": {
|
||||
"lint": "eslint -c ./.eslintrc.json src --ext ts"
|
||||
},
|
||||
"repository": "https://gitlab.libraryofcode.org/engineering/communityrelations.git",
|
||||
"author": "Matthew R, AD, FSEN <matthew@staff.libraryofcode.org>",
|
||||
"license": "AGPL-3.0",
|
||||
"devDependencies": {
|
||||
"@types/ari-client": "^2.2.7",
|
||||
"@types/auth0": "^2.34.7",
|
||||
"@types/bull": "^3.15.7",
|
||||
"@types/cron": "^1.7.3",
|
||||
"@types/express": "^4.17.13",
|
||||
"@types/helmet": "^0.0.48",
|
||||
"@types/jsonwebtoken": "^8.5.6",
|
||||
"@types/mathjs": "^9.4.1",
|
||||
"@types/mongoose": "^5.11.96",
|
||||
"@types/node": "^16.11.12",
|
||||
"@types/nodemailer": "^6.4.4",
|
||||
"@types/puppeteer": "^5.4.4",
|
||||
"@types/signale": "^1.4.2",
|
||||
"@types/uuid": "^8.3.3",
|
||||
"@typescript-eslint/eslint-plugin": "^5.6.0",
|
||||
"@typescript-eslint/parser": "^5.6.0",
|
||||
"eslint": "^8.4.1",
|
||||
"eslint-config-airbnb-base": "^15.0.0",
|
||||
"eslint-plugin-import": "^2.25.3",
|
||||
"tslib": "^2.3.1",
|
||||
"typescript": "^4.5.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@google-cloud/text-to-speech": "^3.4.0",
|
||||
"ari-client": "^2.2.0",
|
||||
"asterisk-manager": "^0.2.0",
|
||||
"auth0": "^2.37.0",
|
||||
"awesome-phonenumber": "^2.65.0",
|
||||
"axios": "^0.24.0",
|
||||
"body-parser": "^1.19.0",
|
||||
"brain.js": "^2.0.0-beta.4",
|
||||
"bull": "^4.1.1",
|
||||
"cheerio": "^1.0.0-rc.10",
|
||||
"cron": "^1.8.2",
|
||||
"eris": "^0.16.1",
|
||||
"eris-pagination": "github:libraryofcode/eris-pagination",
|
||||
"express": "^4.17.1",
|
||||
"helmet": "^4.6.0",
|
||||
"ioredis": "^4.28.2",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"mathjs": "^10.0.0",
|
||||
"moment": "^2.29.1",
|
||||
"mongoose": "^6.1.1",
|
||||
"nanoid": "^3.1.30",
|
||||
"nodemailer": "^6.7.2",
|
||||
"pluris": "^0.3.7",
|
||||
"puppeteer": "^12.0.1",
|
||||
"sd-notify": "^2.8.0",
|
||||
"signale": "^1.4.0",
|
||||
"stock-info": "^1.5.1",
|
||||
"stripe": "^8.193.0",
|
||||
"uuid": "^8.3.2",
|
||||
"yaml": "^1.10.2"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -335,7 +335,7 @@ export default class Report extends Route {
|
|||
createdAt: new Date(mem.createdAt),
|
||||
avatarURL: mem.avatarURL,
|
||||
flags,
|
||||
nitroBoost: mem.premiumSince === null,
|
||||
nitroBoost: mem.premiumSince ?? null,
|
||||
},
|
||||
totalScore,
|
||||
percentile: Math.round(this.server.client.util.percentile(set, report.total)),
|
||||
|
|
|
@ -1,181 +1,213 @@
|
|||
/* eslint-disable no-continue */
|
||||
import type { AxiosError, AxiosStatic } from 'axios';
|
||||
import axios from 'axios';
|
||||
import { Member, Message } from 'eris';
|
||||
import { Client, Command, RichEmbed } from '../class';
|
||||
|
||||
export default class Apply extends Command {
|
||||
public services: Map<string, { description: string, type: 'HARD' | 'SOFT', saaOnly?: boolean, url: string, validation: (...cond: any) => Promise<boolean> | boolean, func?: Function }>;
|
||||
|
||||
constructor(client: Client) {
|
||||
super(client);
|
||||
this.name = 'apply';
|
||||
this.description = 'Application frontend for EDS.';
|
||||
this.usage = `${this.client.config.prefix}apply [serviceName]\n${this.client.config.prefix}apply full`;
|
||||
this.permissions = 0;
|
||||
this.guildOnly = true;
|
||||
this.enabled = true;
|
||||
this.setServices();
|
||||
}
|
||||
|
||||
protected setServices() {
|
||||
this.services = new Map();
|
||||
this.services.set('role::proficient', {
|
||||
description: 'Proficient role assignment.',
|
||||
type: 'HARD',
|
||||
saaOnly: true,
|
||||
url: 'https://eds.libraryofcode.org/roles/proficient',
|
||||
validation: (member: Member) => !member.roles.includes('506943223680466955'),
|
||||
func: async (client: Client, ...data: any[]) => {
|
||||
const member = await client.guilds.get(client.config.guildID).getRESTMember(data[0]);
|
||||
await member.addRole('506943223680466955', 'Proficient Approval from EDS');
|
||||
},
|
||||
});
|
||||
this.services.set('role::regulars', {
|
||||
description: 'Regulars role assignment.',
|
||||
type: 'HARD',
|
||||
saaOnly: true,
|
||||
url: 'https://eds.libraryofcode.org/roles/regulars',
|
||||
validation: (member: Member) => !member.roles.includes('472524444083159050'),
|
||||
func: async (client: Client, ...data: any[]) => {
|
||||
const member = await client.guilds.get(client.config.guildID).getRESTMember(data[0]);
|
||||
await member.addRole('472524444083159050', 'Regulars Approval from EDS');
|
||||
},
|
||||
});
|
||||
this.services.set('role::constants', {
|
||||
description: 'Constants role assignment.',
|
||||
type: 'HARD',
|
||||
url: 'https://eds.libraryofcode.org/roles/constants',
|
||||
validation: (member: Member) => !member.roles.includes('511771731891847168'),
|
||||
func: async (client: Client, ...data: any[]) => {
|
||||
const member = await client.guilds.get(client.config.guildID).getRESTMember(data[0]);
|
||||
await member.addRole('511771731891847168', 'Constants Approval from EDS');
|
||||
},
|
||||
});
|
||||
|
||||
this.services.set('cs::t2', {
|
||||
description: 'Tier 2 upgrade for Cloud Services account.',
|
||||
type: 'HARD',
|
||||
url: 'https://eds.libraryofcode.org/cs/t2',
|
||||
validation: (member: Member) => member.roles.includes('546457886440685578'),
|
||||
func: async (client: Client, ...data: any[]) => {
|
||||
const member = await client.guilds.get(client.config.guildID).getRESTMember(data[0]);
|
||||
const ax = <AxiosStatic>require('axios');
|
||||
await ax({
|
||||
method: 'get',
|
||||
url: `https://api.cloud.libraryofcode.org/wh/t2?userID=${member.id}&auth=${client.config.internalKey}`,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
this.services.set('cs::promot3', {
|
||||
description: 'Receive 25% off your first purchase of Tier 3.',
|
||||
type: 'SOFT',
|
||||
url: 'https://eds.libraryofcode.org/cs/t3-promo',
|
||||
validation: async (member: Member) => {
|
||||
if (!member.roles.includes('546457886440685578')) return false;
|
||||
const customer = await this.client.db.Customer.findOne({ userID: member.user.id }).lean().exec();
|
||||
if (!customer) return false;
|
||||
return true;
|
||||
},
|
||||
func: async (client: Client, ...data: any[]) => {
|
||||
const member = await client.guilds.get(client.config.guildID).getRESTMember(data[0]);
|
||||
const customer = await client.db.Customer.findOne({ userID: member.user.id }).lean().exec();
|
||||
const coupon = await client.stripe.coupons.create({
|
||||
percent_off: 25,
|
||||
duration: 'once',
|
||||
max_redemptions: 1,
|
||||
name: 'Tier 3 - EDS Discount',
|
||||
metadata: {
|
||||
userID: member.user.id,
|
||||
},
|
||||
});
|
||||
const promo = await client.stripe.promotionCodes.create({
|
||||
coupon: coupon.id,
|
||||
customer: customer.cusID,
|
||||
max_redemptions: 1,
|
||||
restrictions: {
|
||||
first_time_transaction: true,
|
||||
},
|
||||
});
|
||||
const doc = new client.db.Promo({
|
||||
code: promo.code,
|
||||
pID: promo.id,
|
||||
});
|
||||
await doc.save();
|
||||
const chan = await client.getDMChannel(customer.userID);
|
||||
chan.createMessage(`__**Tier 3 Coupon Code**__\n\`${promo.code}\`\n\n*Do not share this promotional code with anyone else. This promo code is good for your first purchase of Tier 2, 25% off applied. Will apply to your first invoice only, for more questions contact support.*`);
|
||||
},
|
||||
});
|
||||
|
||||
this.services.set('p::role::constants', {
|
||||
description: 'Pre-approval for Constants role assignment.',
|
||||
type: 'SOFT',
|
||||
url: 'https://eds.libraryofcode.org/roles/preconstants',
|
||||
validation: (member: Member) => !member.roles.includes('511771731891847168'),
|
||||
});
|
||||
|
||||
this.services.set('p::cs::t2', {
|
||||
description: 'Pre-approval for Tier 2.',
|
||||
type: 'SOFT',
|
||||
url: 'https://eds.libraryofcode.org/cs/t2pre',
|
||||
validation: (member: Member) => member.roles.includes('546457886440685578'),
|
||||
});
|
||||
}
|
||||
|
||||
public async run(message: Message, args: string[]) {
|
||||
try {
|
||||
if (!args[0] || args[0] === 'full') {
|
||||
const embed = new RichEmbed();
|
||||
embed.setTitle('Instant Application Service [IAS]');
|
||||
embed.setColor('#556cd6');
|
||||
if (args[0] !== 'full') {
|
||||
embed.setDescription(`*These applications are specifically targeted to you based on validation conditions. Run \`${this.client.config.prefix}apply full\` for a full list of all applications.*`);
|
||||
embed.setThumbnail(message.member.avatarURL);
|
||||
embed.setAuthor(message.member.username, message.member.avatarURL);
|
||||
}
|
||||
for (const service of this.services) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const test = await service[1].validation(message.member);
|
||||
if (!test && args[0] !== 'full') continue;
|
||||
embed.addField(service[0], `**Description**: ${service[1].description}\n**Inquiry Type:** ${service[1].type}\n\n${service[1].saaOnly ? '*This application can only be ran as a Staff-Assisted Application and cannot be ran automatically. Please DM <@457750238208327691> to apply.*' : `*Run \`${this.client.config.prefix}apply ${service[0]}\` to apply.*`}`);
|
||||
}
|
||||
if (embed.fields?.length <= 0) embed.setDescription(`*We have no offers for you at this time. To see a full list of offers, please run \`${this.client.config.prefix}apply full\`.*`);
|
||||
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
||||
embed.setTimestamp();
|
||||
return message.channel.createMessage({ embed });
|
||||
}
|
||||
|
||||
if (!this.services.has(args[0])) return this.error(message.channel, 'Invalid service/product name.');
|
||||
const service = this.services.get(args[0]);
|
||||
const test = await this.services.get(args[0]).validation(message.member);
|
||||
if (!test) return this.error(message.channel, 'A condition exists which prevents you from applying, please try again later.');
|
||||
if (service.saaOnly) return this.error(message.channel, 'This application can only be ran as a Staff-Assisted Application and cannot be ran automatically. Please DM <@457750238208327691> to apply.');
|
||||
const msg = await this.loading(message.channel, 'Thank you for submitting an application. We are currently processing it, you will receive a DM with a decision.');
|
||||
return await this.client.queue.processApplication({ channelID: message.channel.id, guildID: this.mainGuild.id, messageID: msg.id }, service.url, message.author.id, service.func ? service.func.toString() : undefined);
|
||||
} catch (err) {
|
||||
return this.client.util.handleError(err, message, this);
|
||||
}
|
||||
}
|
||||
|
||||
public static async apply(client: Client, url: string, userID: string) {
|
||||
try {
|
||||
const { data } = await axios({
|
||||
method: 'get',
|
||||
url: `${url}?userID=${userID}&auth=${client.config.internalKey}`,
|
||||
});
|
||||
|
||||
return {
|
||||
status: 'SUCCESS',
|
||||
decision: data.decision,
|
||||
id: data.id,
|
||||
processedBy: data.processedBy,
|
||||
token: data.token,
|
||||
};
|
||||
} catch (err) {
|
||||
const error = <AxiosError>err;
|
||||
if (error.response?.status === 404 || error.response.status === 400 || error.response.status === 401) return { id: 'N/A', processedBy: 'N/A', status: 'CLIENT_ERROR', decision: 'PRE-DECLINED' };
|
||||
return { id: 'N/A', processedBy: 'N/A', status: 'SERVER_ERROR', decision: 'PRE-DECLINED' };
|
||||
}
|
||||
}
|
||||
}
|
||||
/* eslint-disable no-continue */
|
||||
import type { AxiosError, AxiosStatic } from 'axios';
|
||||
import axios from 'axios';
|
||||
import { Member, Message } from 'eris';
|
||||
import { Client, Command, RichEmbed } from '../class';
|
||||
import { CloudServicesUtil } from '../util';
|
||||
|
||||
export default class Apply extends Command {
|
||||
public services: Map<string, { description: string, type: 'HARD' | 'SOFT', saaOnly?: boolean, url: string, validation: (...cond: any) => Promise<boolean> | boolean, func?: Function }>;
|
||||
|
||||
constructor(client: Client) {
|
||||
super(client);
|
||||
this.name = 'apply';
|
||||
this.description = 'Application frontend for EDS.';
|
||||
this.usage = `${this.client.config.prefix}apply [serviceName]\n${this.client.config.prefix}apply full`;
|
||||
this.permissions = 0;
|
||||
this.guildOnly = true;
|
||||
this.enabled = true;
|
||||
this.setServices();
|
||||
}
|
||||
|
||||
protected setServices() {
|
||||
this.services = new Map();
|
||||
this.services.set('role::proficient', {
|
||||
description: 'Proficient role assignment.',
|
||||
type: 'HARD',
|
||||
saaOnly: true,
|
||||
url: 'https://eds.libraryofcode.org/roles/proficient',
|
||||
validation: (member: Member) => !member.roles.includes('506943223680466955'),
|
||||
func: async (client: Client, ...data: any[]) => {
|
||||
const member = await client.guilds.get(client.config.guildID).getRESTMember(data[0]);
|
||||
await member.addRole('506943223680466955', 'Proficient Approval from EDS');
|
||||
},
|
||||
});
|
||||
this.services.set('role::regulars', {
|
||||
description: 'Regulars role assignment.',
|
||||
type: 'HARD',
|
||||
saaOnly: true,
|
||||
url: 'https://eds.libraryofcode.org/roles/regulars',
|
||||
validation: (member: Member) => !member.roles.includes('472524444083159050'),
|
||||
func: async (client: Client, ...data: any[]) => {
|
||||
const member = await client.guilds.get(client.config.guildID).getRESTMember(data[0]);
|
||||
await member.addRole('472524444083159050', 'Regulars Approval from EDS');
|
||||
},
|
||||
});
|
||||
this.services.set('role::constants', {
|
||||
description: 'Constants role assignment.',
|
||||
type: 'HARD',
|
||||
url: 'https://eds.libraryofcode.org/roles/constants',
|
||||
validation: (member: Member) => !member.roles.includes('511771731891847168'),
|
||||
func: async (client: Client, ...data: any[]) => {
|
||||
const member = await client.guilds.get(client.config.guildID).getRESTMember(data[0]);
|
||||
await member.addRole('511771731891847168', 'Constants Approval from EDS');
|
||||
},
|
||||
});
|
||||
|
||||
this.services.set('cs::t2', {
|
||||
description: 'Tier 2 upgrade for Cloud Services account.',
|
||||
type: 'HARD',
|
||||
url: 'https://eds.libraryofcode.org/cs/t2',
|
||||
validation: async (member: Member) => {
|
||||
if (!member.roles.includes('546457886440685578')) return false;
|
||||
const csAccount = await CloudServicesUtil.fetchAccountStatus(member.id, this.client.config.internalKey);
|
||||
if (csAccount.tier > 2) return false;
|
||||
return true;
|
||||
},
|
||||
func: async (client: Client, ...data: any[]) => {
|
||||
const member = await client.guilds.get(client.config.guildID).getRESTMember(data[0]);
|
||||
const ax = <AxiosStatic>require('axios');
|
||||
await ax({
|
||||
method: 'get',
|
||||
url: `https://api.cloud.libraryofcode.org/wh/t2?userID=${member.id}&auth=${client.config.internalKey}`,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
this.services.set('cs::temp-upgrade', {
|
||||
description: 'Temporary Tier 3 upgrade for your Cloud Services account to install dependencies or RAM-dependent operations.',
|
||||
type: 'SOFT',
|
||||
url: 'https://eds.libraryofcode.org/cs/t3-temp',
|
||||
validation: async (member: Member) => {
|
||||
const csAccount = await CloudServicesUtil.fetchAccountStatus(member.id, this.client.config.internalKey);
|
||||
// const memberCheck = await this.client.db.Member.findOne({ userID: member.id }).lean().exec();
|
||||
// if (new Date() > memberCheck?.misc?.t3TemporaryExpiration?.date) return false;
|
||||
if (csAccount.tier === 3) return false;
|
||||
return true;
|
||||
},
|
||||
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();
|
||||
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 CloudServicesUtil.upgradeT2(dmember.id, this.client.config.internalKey);
|
||||
},
|
||||
});
|
||||
|
||||
this.services.set('cs::promot3', {
|
||||
description: 'Receive 25% off your first purchase of Tier 3.',
|
||||
type: 'SOFT',
|
||||
url: 'https://eds.libraryofcode.org/cs/t3-promo',
|
||||
validation: async (member: Member) => {
|
||||
if (!member.roles.includes('546457886440685578')) return false;
|
||||
const customer = await this.client.db.Customer.findOne({ userID: member.user.id }).lean().exec();
|
||||
if (!customer) return false;
|
||||
return true;
|
||||
},
|
||||
func: async (client: Client, ...data: any[]) => {
|
||||
const member = await client.guilds.get(client.config.guildID).getRESTMember(data[0]);
|
||||
const customer = await client.db.Customer.findOne({ userID: member.user.id }).lean().exec();
|
||||
const coupon = await client.stripe.coupons.create({
|
||||
percent_off: 25,
|
||||
duration: 'once',
|
||||
max_redemptions: 1,
|
||||
name: 'Tier 3 - EDS Discount',
|
||||
metadata: {
|
||||
userID: member.user.id,
|
||||
},
|
||||
});
|
||||
const promo = await client.stripe.promotionCodes.create({
|
||||
coupon: coupon.id,
|
||||
customer: customer.cusID,
|
||||
max_redemptions: 1,
|
||||
restrictions: {
|
||||
first_time_transaction: true,
|
||||
},
|
||||
});
|
||||
const doc = new client.db.Promo({
|
||||
code: promo.code,
|
||||
pID: promo.id,
|
||||
});
|
||||
await doc.save();
|
||||
const chan = await client.getDMChannel(customer.userID);
|
||||
chan.createMessage(`__**Tier 3 Coupon Code**__\n\`${promo.code}\`\n\n*Do not share this promotional code with anyone else. This promo code is good for your first purchase of Tier 2, 25% off applied. Will apply to your first invoice only, for more questions contact support.*`);
|
||||
},
|
||||
});
|
||||
|
||||
this.services.set('p::role::constants', {
|
||||
description: 'Pre-approval for Constants role assignment.',
|
||||
type: 'SOFT',
|
||||
url: 'https://eds.libraryofcode.org/roles/preconstants',
|
||||
validation: (member: Member) => !member.roles.includes('511771731891847168'),
|
||||
});
|
||||
|
||||
this.services.set('p::cs::t2', {
|
||||
description: 'Pre-approval for Tier 2.',
|
||||
type: 'SOFT',
|
||||
url: 'https://eds.libraryofcode.org/cs/t2pre',
|
||||
validation: (member: Member) => member.roles.includes('546457886440685578'),
|
||||
});
|
||||
}
|
||||
|
||||
public async run(message: Message, args: string[]) {
|
||||
try {
|
||||
if (!args[0] || args[0] === 'full') {
|
||||
const embed = new RichEmbed();
|
||||
embed.setTitle('Instant Application Service [IAS]');
|
||||
embed.setColor('#556cd6');
|
||||
if (args[0] !== 'full') {
|
||||
embed.setDescription(`*These applications are specifically targeted to you based on validation conditions. Run \`${this.client.config.prefix}apply full\` for a full list of all applications.*`);
|
||||
embed.setThumbnail(message.member.avatarURL);
|
||||
embed.setAuthor(message.member.username, message.member.avatarURL);
|
||||
}
|
||||
for (const service of this.services) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const test = await service[1].validation(message.member);
|
||||
if (!test && args[0] !== 'full') continue;
|
||||
embed.addField(service[0], `**Description**: ${service[1].description}\n**Inquiry Type:** ${service[1].type}\n\n${service[1].saaOnly ? '*This application can only be ran as a Staff-Assisted Application and cannot be ran automatically. Please DM <@457750238208327691> to apply.*' : `*Run \`${this.client.config.prefix}apply ${service[0]}\` to apply.*`}`);
|
||||
}
|
||||
if (embed.fields?.length <= 0) embed.setDescription(`*We have no offers for you at this time. To see a full list of offers, please run \`${this.client.config.prefix}apply full\`.*`);
|
||||
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
||||
embed.setTimestamp();
|
||||
return message.channel.createMessage({ embed });
|
||||
}
|
||||
|
||||
if (!this.services.has(args[0])) return this.error(message.channel, 'Invalid service/product name.');
|
||||
const service = this.services.get(args[0]);
|
||||
const test = await this.services.get(args[0]).validation(message.member);
|
||||
if (!test) return this.error(message.channel, 'A condition exists which prevents you from applying, please try again later.');
|
||||
if (service.saaOnly) return this.error(message.channel, 'This application can only be ran as a Staff-Assisted Application and cannot be ran automatically. Please DM <@457750238208327691> to apply.');
|
||||
const msg = await this.loading(message.channel, 'Thank you for submitting an application. We are currently processing it, you will receive a DM with a decision.');
|
||||
return await this.client.queue.processApplication({ channelID: message.channel.id, guildID: this.mainGuild.id, messageID: msg.id }, service.url, message.author.id, service.func ? service.func.toString() : undefined);
|
||||
} catch (err) {
|
||||
return this.client.util.handleError(err, message, this);
|
||||
}
|
||||
}
|
||||
|
||||
public static async apply(client: Client, url: string, userID: string) {
|
||||
try {
|
||||
const { data } = await axios({
|
||||
method: 'get',
|
||||
url: `${url}?userID=${userID}&auth=${client.config.internalKey}`,
|
||||
});
|
||||
|
||||
return {
|
||||
status: 'SUCCESS',
|
||||
decision: data.decision,
|
||||
id: data.id,
|
||||
processedBy: data.processedBy,
|
||||
token: data.token,
|
||||
};
|
||||
} catch (err) {
|
||||
const error = <AxiosError>err;
|
||||
if (error.response?.status === 404 || error.response.status === 400 || error.response.status === 401) return { id: 'N/A', processedBy: 'N/A', status: 'CLIENT_ERROR', decision: 'PRE-DECLINED' };
|
||||
return { id: 'N/A', processedBy: 'N/A', status: 'SERVER_ERROR', decision: 'PRE-DECLINED' };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
/* eslint-disable no-undef */
|
||||
import { TextChannel } from 'eris';
|
||||
import { Client, RichEmbed } from '../class';
|
||||
import { CloudServicesUtil } from '../util';
|
||||
|
||||
let interval: NodeJS.Timeout;
|
||||
|
||||
|
@ -8,6 +10,16 @@ export default function checkLock(client: Client): NodeJS.Timeout {
|
|||
try {
|
||||
const moderations = await client.db.Moderation.find();
|
||||
const judgements = await client.db.Judgement.find().lean().exec();
|
||||
const members = await client.db.Member.find();
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
judgements.forEach(async (judgement) => {
|
||||
if (!judgement.expires) return;
|
||||
if (new Date() > judgement.expires) {
|
||||
|
|
|
@ -1,29 +1,41 @@
|
|||
import { Document, Schema, model } from 'mongoose';
|
||||
|
||||
export interface MemberInterface extends Document {
|
||||
userID: string,
|
||||
additional: {
|
||||
langs: ['js', 'py', 'rb', 'ts', 'rs', 'go', 'cfam', 'csharp', 'swift', 'java', 'kt', 'asm'],
|
||||
operatingSystems: ['arch', 'deb', 'cent', 'fedora', 'manjaro', 'mdarwin', 'redhat', 'ubuntu', 'win'],
|
||||
github: string,
|
||||
gitlab: string,
|
||||
bio: string,
|
||||
},
|
||||
x509?: string,
|
||||
pgp?: string
|
||||
}
|
||||
|
||||
const Member: Schema = new Schema({
|
||||
userID: String,
|
||||
additional: {
|
||||
langs: Array,
|
||||
operatingSystems: Array,
|
||||
github: String,
|
||||
gitlab: String,
|
||||
bio: String,
|
||||
},
|
||||
x509: String,
|
||||
pgp: String,
|
||||
});
|
||||
|
||||
export default model<MemberInterface>('Member', Member);
|
||||
import { Document, Schema, model } from 'mongoose';
|
||||
|
||||
export interface MemberInterface extends Document {
|
||||
userID: string,
|
||||
additional?: {
|
||||
langs: ['js', 'py', 'rb', 'ts', 'rs', 'go', 'cfam', 'csharp', 'swift', 'java', 'kt', 'asm'],
|
||||
operatingSystems: ['arch', 'deb', 'cent', 'fedora', 'manjaro', 'mdarwin', 'redhat', 'ubuntu', 'win'],
|
||||
github: string,
|
||||
gitlab: string,
|
||||
bio: string,
|
||||
},
|
||||
misc?: {
|
||||
t3TemporaryExpiration?: {
|
||||
date: Date,
|
||||
processed: boolean
|
||||
}
|
||||
}
|
||||
x509?: string,
|
||||
pgp?: string,
|
||||
}
|
||||
|
||||
const Member: Schema = new Schema({
|
||||
userID: String,
|
||||
additional: {
|
||||
langs: Array,
|
||||
operatingSystems: Array,
|
||||
github: String,
|
||||
gitlab: String,
|
||||
bio: String,
|
||||
},
|
||||
misc: {
|
||||
t3TemporaryExpiration: {
|
||||
date: Date,
|
||||
processed: Boolean,
|
||||
},
|
||||
},
|
||||
x509: String,
|
||||
pgp: String,
|
||||
});
|
||||
|
||||
export default model<MemberInterface>('Member', Member);
|
||||
|
|
|
@ -1,37 +1,37 @@
|
|||
import { Document, Schema, model } from 'mongoose';
|
||||
|
||||
export interface ModerationInterface extends Document {
|
||||
userID: string,
|
||||
logID: string,
|
||||
moderatorID: string,
|
||||
reason: string,
|
||||
/**
|
||||
* @field 0 - Warn
|
||||
* @field 1 - Unmute
|
||||
* @field 2 - Mute
|
||||
* @field 3 - Kick
|
||||
* @field 4 - Unban
|
||||
* @field 5 - Ban
|
||||
*/
|
||||
type: 0 | 1 | 2 | 3 | 4 | 5
|
||||
date: Date,
|
||||
expiration?: {
|
||||
date: Date,
|
||||
processed: boolean
|
||||
}
|
||||
}
|
||||
|
||||
const Moderation: Schema = new Schema({
|
||||
userID: String,
|
||||
logID: String,
|
||||
moderatorID: String,
|
||||
reason: String,
|
||||
type: Number,
|
||||
date: Date,
|
||||
expiration: {
|
||||
date: Date,
|
||||
processed: Boolean,
|
||||
},
|
||||
});
|
||||
|
||||
export default model<ModerationInterface>('Moderation', Moderation);
|
||||
import { Document, Schema, model } from 'mongoose';
|
||||
|
||||
export interface ModerationInterface extends Document {
|
||||
userID: string,
|
||||
logID: string,
|
||||
moderatorID: string,
|
||||
reason: string,
|
||||
/**
|
||||
* @field 0 - Warn
|
||||
* @field 1 - Unmute
|
||||
* @field 2 - Mute
|
||||
* @field 3 - Kick
|
||||
* @field 4 - Unban
|
||||
* @field 5 - Ban
|
||||
*/
|
||||
type: 0 | 1 | 2 | 3 | 4 | 5
|
||||
date: Date,
|
||||
expiration?: {
|
||||
date: Date,
|
||||
processed: boolean
|
||||
}
|
||||
}
|
||||
|
||||
const Moderation: Schema = new Schema({
|
||||
userID: String,
|
||||
logID: String,
|
||||
moderatorID: String,
|
||||
reason: String,
|
||||
type: Number,
|
||||
date: Date,
|
||||
expiration: {
|
||||
date: Date,
|
||||
processed: Boolean,
|
||||
},
|
||||
});
|
||||
|
||||
export default model<ModerationInterface>('Moderation', Moderation);
|
||||
|
|
Loading…
Reference in New Issue