merge-requests/4/head
Matthew 2020-11-08 22:58:18 -05:00
parent 4b7f4c26b7
commit 12cbb86f3f
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
1 changed files with 65 additions and 1 deletions

View File

@ -30,13 +30,76 @@ export default class Webhook extends Route {
} }
}); });
this.router.get('/t3', async (req, res) => {
if (req.query?.auth !== this.server.security.keys.internal.toString('hex')) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
if (!req.query?.userID) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR });
const account = await this.server.client.db.Account.findOne({ userID: req.query.userID.toString() });
if (!account) {
return res.sendStatus(404);
}
const tier = await this.server.client.db.Tier.findOne({ id: 3 });
if (account.tier >= 3) {
return res.sendStatus(200);
}
if (account.ramLimitNotification !== -1) {
await account.updateOne({ $set: { tier: 3, ramLimitNotification: tier.resourceLimits.ram - 20 } });
} else {
await account.updateOne({ $set: { tier: 3 } });
}
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} -> 3`, true);
embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL);
embed.setTimestamp();
await this.server.client.util.sendMessageToUserTerminal(account.username, 'A technician has changed your tier to 3').catch(() => { });
this.server.client.createMessage('580950455581147146', { embed });
this.server.client.getDMChannel(account.userID).then((channel) => channel.createMessage({ embed })).catch();
return res.sendStatus(200);
});
this.router.get('/t3-rm', async (req, res) => {
if (req.query?.auth !== this.server.security.keys.internal.toString('hex')) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
if (!req.query?.userID) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR });
const account = await this.server.client.db.Account.findOne({ userID: req.query.userID.toString() });
if (!account) return res.sendStatus(404);
const tier = await this.server.client.db.Tier.findOne({ id: 1 });
if (account.tier !== 3) return res.sendStatus(200);
if (account.ramLimitNotification !== -1) {
await account.updateOne({ $set: { tier: 1, ramLimitNotification: tier.resourceLimits.ram - 20 } });
} else {
await account.updateOne({ $set: { tier: 1 } });
}
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} -> 1`, true);
embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL);
embed.setTimestamp();
await this.server.client.util.sendMessageToUserTerminal(account.username, 'A technician has changed your tier.').catch(() => { });
this.server.client.createMessage('580950455581147146', { embed });
this.server.client.getDMChannel(account.userID).then((channel) => channel.createMessage({ embed })).catch();
return res.sendStatus(200);
});
this.router.get('/t2', async (req, res) => { this.router.get('/t2', async (req, res) => {
if (req.query?.auth !== this.server.security.keys.internal.toString('hex')) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED }); if (req.query?.auth !== this.server.security.keys.internal.toString('hex')) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
if (!req.query?.userID) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR }); if (!req.query?.userID) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR });
const account = await this.server.client.db.Account.findOne({ userID: req.query.userID.toString() }); const account = await this.server.client.db.Account.findOne({ userID: req.query.userID.toString() });
if (!account) {
return res.sendStatus(404);
}
const tier = await this.server.client.db.Tier.findOne({ id: 2 }); const tier = await this.server.client.db.Tier.findOne({ id: 2 });
if (account.tier >= 2) return res.sendStatus(200); if (account.tier >= 2) {
return res.sendStatus(200);
}
if (account.ramLimitNotification !== -1) { if (account.ramLimitNotification !== -1) {
await account.updateOne({ $set: { tier: 2, ramLimitNotification: tier.resourceLimits.ram - 20 } }); await account.updateOne({ $set: { tier: 2, ramLimitNotification: tier.resourceLimits.ram - 20 } });
} else { } else {
@ -61,6 +124,7 @@ export default class Webhook extends Route {
if (!req.query?.userID) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR }); if (!req.query?.userID) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR });
const account = await this.server.client.db.Account.findOne({ userID: req.query.userID.toString() }); const account = await this.server.client.db.Account.findOne({ userID: req.query.userID.toString() });
if (!account) return res.sendStatus(404);
const tier = await this.server.client.db.Tier.findOne({ id: 1 }); const tier = await this.server.client.db.Tier.findOne({ id: 1 });
if (account.tier !== 2) return res.sendStatus(200); if (account.tier !== 2) return res.sendStatus(200);
if (account.ramLimitNotification !== -1) { if (account.ramLimitNotification !== -1) {