1
0
Fork 0
master
Matthew 2021-10-11 20:57:44 -04:00
parent a075bfdc6e
commit 5ca005cf90
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
3 changed files with 67 additions and 1 deletions

View File

@ -14,6 +14,7 @@
"dependencies": { "dependencies": {
"axios": "^0.21.1", "axios": "^0.21.1",
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"cron": "^1.8.2",
"discord.js": "^13.0.0", "discord.js": "^13.0.0",
"express": "^4.17.1", "express": "^4.17.1",
"fs-extra": "^10.0.0", "fs-extra": "^10.0.0",

51
src/intervals/t2Checks.ts Normal file
View File

@ -0,0 +1,51 @@
/* eslint-disable no-await-in-loop */
import axios, { AxiosError } from 'axios';
import cron from 'cron';
import { MessageEmbed, TextChannel } from 'discord.js';
import { Client } from '../class';
async function checkt2(auth: string, userID: string) {
try {
const { data } = await axios({
method: 'get',
url: `https://eds.libraryofcode.org/cs/t2rev/?userID=${userID}&auth=${auth}`,
});
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' };
}
}
export default async function t2checkCron(client: Client) {
const checkTier2StatusJob = new cron.CronJob('0 21 * * *', async () => {
const users = await client.db.Account.find({ tier: 2 }).lean();
for (const user of users) {
const check = await checkt2(client.config.internalKey, user.userID);
if (check.decision === 'DECLINED') {
const embed = new MessageEmbed();
embed.setTitle('Cloud Account | Tier Change');
embed.setColor('#0099ff');
embed.addField('User', `${user.username} | <@${user.userID}>`, true);
embed.addField('Technician', 'SYSTEM', true);
embed.addField('Old Tier -> New Tier', `${user.tier} -> ${args[1]}`, true);
embed.setFooter(client.user.username, client.user.avatarURL());
embed.setTimestamp();
const ch = client.channels.cache.get('580950455581147146') as TextChannel;
ch.send({ embeds: [embed] });
return client.users.fetch(user.userID).then((u) => u.send({ embeds: [embed], content: `__**Tier 2 Account Review**__\n\nHello, <@${user.userID}>.\nWe periodically run automatic account review inquiries for users with Tier 2. This means we request an account review from EDS to determine if you're still eligible to keep Tier 2.\nUnfortunately, according to EDS' records, you are currently ineligible for Tier 2. Because of this, we're going to automatically revoke your Tier 2 status. You can re-apply to Tier 2 at any time if you feel that you meet the requirements. If you have any questions, or if you believe this may be a mistake, please contact our support team as soon as possible. Thank you.` })).catch();
}
}
});
checkTier2StatusJob.start();
}

View File

@ -687,6 +687,13 @@ core-util-is@~1.0.0:
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac= integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=
cron@^1.8.2:
version "1.8.2"
resolved "https://registry.yarnpkg.com/cron/-/cron-1.8.2.tgz#4ac5e3c55ba8c163d84f3407bde94632da8370ce"
integrity sha512-Gk2c4y6xKEO8FSAUTklqtfSr7oTq0CiPQeLBG5Fl0qoXpZyMcj1SG59YL+hqq04bu6/IuEA7lMkYDAplQNKkyg==
dependencies:
moment-timezone "^0.5.x"
cross-spawn@^7.0.2: cross-spawn@^7.0.2:
version "7.0.3" version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
@ -2127,7 +2134,14 @@ module-lookup-amd@^7.0.0:
requirejs "^2.3.5" requirejs "^2.3.5"
requirejs-config-file "^4.0.0" requirejs-config-file "^4.0.0"
moment@^2.29.1: moment-timezone@^0.5.x:
version "0.5.33"
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.33.tgz#b252fd6bb57f341c9b59a5ab61a8e51a73bbd22c"
integrity sha512-PTc2vcT8K9J5/9rDEPe5czSIKgLoGsH8UNpA4qZTVw0Vd/Uz19geE9abbIOQKaAQFcnQ3v5YEXrbSc5BpshH+w==
dependencies:
moment ">= 2.9.0"
"moment@>= 2.9.0", moment@^2.29.1:
version "2.29.1" version "2.29.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.1.tgz#b2be769fa31940be9eeea6469c075e35006fa3d3" resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.1.tgz#b2be769fa31940be9eeea6469c075e35006fa3d3"
integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ== integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==