diff --git a/src/api/routes/Webhook.ts b/src/api/routes/Webhook.ts index 65c5fe4..a0e1766 100644 --- a/src/api/routes/Webhook.ts +++ b/src/api/routes/Webhook.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-continue */ import { TextChannel } from 'eris'; import { Server } from '..'; import { Route, RichEmbed } from '../../class'; @@ -28,5 +29,46 @@ export default class Webhook extends Route { return this.handleError(err, res); } }); + + this.router.get('/score', async (req, res) => { + try { + if (req.query?.authorization !== this.server.security.keys.iv.toString('hex')) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED }); + if (!req.query?.id) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR }); + + const account = await this.server.client.db.Account.findOne({ userID: req.query.id.toString() }).lean().exec(); + if (!account) return res.status(200).send({ error: true }); + const moderations = await this.server.client.db.Moderation.find({ userID: req.query.id.toString() }).lean().exec(); + + const response: { + error: boolean, + tier: number, + totalReferrals?: number, + createdAt?: Date, + warns?: Date[], + locks?: Date[], + deletes?: Date[], + } = { + error: false, + tier: account.tier, + totalReferrals: 0, + createdAt: account.createdAt, + warns: [], + locks: [], + deletes: [], + }; + if (account.totalReferrals && account.totalReferrals > 0) response.totalReferrals = account.totalReferrals; + if (moderations.length > 0) { + for (const moderation of moderations) { + if (moderation.reason?.includes('DN/C')) continue; + if (moderation.type === 1) response.warns.push(moderation.date); + if (moderation.type === 2) response.locks.push(moderation.date); + if (moderation.type === 4) response.deletes.push(moderation.date); + } + } + return res.status(200).json(response); + } catch (err) { + return this.handleError(err, res); + } + }); } } diff --git a/src/class/Security.ts b/src/class/Security.ts index bd00631..a59f9a2 100644 --- a/src/class/Security.ts +++ b/src/class/Security.ts @@ -7,7 +7,7 @@ import { AccountInterface } from '../models'; export default class Security { public client: Client; - protected readonly keyBase: { key: string, iv: string }; + protected readonly keyBase: { key: string, iv: string, internal: string }; constructor(client: Client) { this.client = client; @@ -18,6 +18,7 @@ export default class Security { return { key: Buffer.from(this.keyBase.key, 'base64'), iv: Buffer.from(this.keyBase.iv, 'base64'), + internal: Buffer.from(this.keyBase.internal, 'hex'), }; }