From 079887ac8a5c5926d4d7e7438672b254ce465fd8 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Fri, 28 Aug 2020 02:35:39 -0400 Subject: [PATCH] add referral codes --- src/class/AccountUtil.ts | 2 ++ src/class/Util.ts | 4 ++-- src/commands/addreferral.ts | 27 +++++++++++++++++++++++++++ src/commands/cwg_create.ts | 4 ++-- src/commands/cwg_delete.ts | 2 +- src/commands/deleteaccount.ts | 1 + src/commands/getreferral.ts | 27 +++++++++++++++++++++++++++ src/commands/index.ts | 2 ++ src/commands/lock.ts | 1 + src/commands/notify.ts | 1 + src/commands/warn.ts | 1 + src/commands/whois.ts | 1 + 12 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 src/commands/addreferral.ts create mode 100644 src/commands/getreferral.ts diff --git a/src/class/AccountUtil.ts b/src/class/AccountUtil.ts index 61dcd3c..458a847 100644 --- a/src/class/AccountUtil.ts +++ b/src/class/AccountUtil.ts @@ -32,6 +32,7 @@ export default class AccountUtil { this.client.util.transport.sendMail({ to: data.emailAddress, from: 'Library of Code sp-us | Cloud Services ', + replyTo: 'cloud-help@libraryofcode.org', subject: 'Your account has been created!', html: ` @@ -89,6 +90,7 @@ export default class AccountUtil { this.client.util.transport.sendMail({ to: account.emailAddress, from: 'Library of Code sp-us | Cloud Services ', + replyTo: 'cloud-help@libraryofcode.org', subject: 'Your account has been locked', html: `

Library of Code | Cloud Services

diff --git a/src/class/Util.ts b/src/class/Util.ts index f7f5c68..05b550c 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -1,6 +1,6 @@ /* eslint-disable no-await-in-loop */ /* eslint-disable no-param-reassign */ -import { promisify, inspect } from 'util'; +import { randomBytes } from 'crypto'; import childProcess from 'child_process'; import nodemailer from 'nodemailer'; import { Message, PrivateChannel, GroupChannel, Member, User } from 'eris'; @@ -203,7 +203,7 @@ export default class Util { const tier = await this.client.db.Tier.findOne({ id: 1 }); const account = new this.client.db.Account({ - username, userID, emailAddress, createdBy: moderatorID, createdAt: new Date(), locked: false, tier: 1, supportKey: code, ssInit: false, ramLimitNotification: tier.resourceLimits.ram - 50, homepath: `/home/${username}`, + username, userID, emailAddress, createdBy: moderatorID, createdAt: new Date(), locked: false, tier: 1, supportKey: code, totalReferrals: 0, referralCode: randomBytes(9).toString('base64').toUpperCase(), ssInit: false, ramLimitNotification: tier.resourceLimits.ram - 50, homepath: `/home/${username}`, }); return account.save(); } diff --git a/src/commands/addreferral.ts b/src/commands/addreferral.ts new file mode 100644 index 0000000..ef7a057 --- /dev/null +++ b/src/commands/addreferral.ts @@ -0,0 +1,27 @@ +import { Message } from 'eris'; +import { Client, Command } from '../class'; + +export default class AddReferral extends Command { + constructor(client: Client) { + super(client); + this.name = 'addreferral'; + this.description = 'Adds a referral value to an account.'; + this.permissions = { roles: ['662163685439045632', '701454780828221450'] }; + this.enabled = true; + this.aliases = ['af', 'refer']; + this.usage = `${this.client.config.prefix}addreferral `; + } + + 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({ $or: [{ username: args[0] }, { userID: args[0].replace(/[<@!>]/gi, '') }] }); + if (!account) return this.error(message.channel, 'Cannot find user.'); + + await account.updateOne({ $inc: { totalReferrals: 1 } }); + return this.success(message.channel, 'Added referral value to account.'); + } catch (error) { + return this.client.util.handleError(error, message, this); + } + } +} diff --git a/src/commands/cwg_create.ts b/src/commands/cwg_create.ts index 2ace78e..bb1113f 100644 --- a/src/commands/cwg_create.ts +++ b/src/commands/cwg_create.ts @@ -83,9 +83,9 @@ export default class CWG_Create extends Command { const embed = new RichEmbed() .setTitle('Domain Creation') .setColor(3066993) - .addField('Account Username', account.username, true) + .addField('Account Username', `${account.username} | <@${account.userID}>`, true) .addField('Account ID', account.id, true) - .addField('Engineer', `<@${message.author.id}>`, true) + .addField('Technician', `<@${message.author.id}>`, true) .addField('Domain', domain.domain, true) .addField('Port', String(domain.port), true); diff --git a/src/commands/cwg_delete.ts b/src/commands/cwg_delete.ts index a1c50f1..fb3a855 100644 --- a/src/commands/cwg_delete.ts +++ b/src/commands/cwg_delete.ts @@ -22,7 +22,7 @@ export default class CWG_Delete extends Command { const edit = await this.loading(message.channel, 'Deleting domain...'); const embed = new RichEmbed(); embed.setTitle('Domain Deletion'); - embed.addField('Account Username', domain.account.username, true); + embed.addField('Account Username', `${domain.account.username} | <@${domain.account.userID}>`, true); embed.addField('Account ID', domain.account.userID, true); embed.addField('Domain', domain.domain, true); embed.addField('Port', String(domain.port), true); diff --git a/src/commands/deleteaccount.ts b/src/commands/deleteaccount.ts index b3818ca..d256194 100644 --- a/src/commands/deleteaccount.ts +++ b/src/commands/deleteaccount.ts @@ -45,6 +45,7 @@ export default class DeleteAccount extends Command { this.client.util.transport.sendMail({ to: account.emailAddress, from: 'Library of Code sp-us | Cloud Services ', + replyTo: 'cloud-help@libraryofcode.org', subject: 'Your account has been deleted', html: `

Library of Code | Cloud Services

diff --git a/src/commands/getreferral.ts b/src/commands/getreferral.ts new file mode 100644 index 0000000..beaa32a --- /dev/null +++ b/src/commands/getreferral.ts @@ -0,0 +1,27 @@ +import { Message } from 'eris'; +import { Client, Command } from '../class'; + +export default class GetReferral extends Command { + constructor(client: Client) { + super(client); + this.name = 'getreferral'; + this.description = 'Fetches your referral code.'; + this.usage = `${this.client.config.prefix}getreferral`; + this.aliases = ['gf']; + this.enabled = false; + } + + public async run(message: Message, args: string[]) { + try { + if (!args[0]) return this.client.commands.get('help').run(message, ['getreferral', this.name]); + const account = await this.client.db.Account.findOne({ userID: message.author.id }); + if (!account) return this.error(message.channel, 'You do not have a Cloud Services account.'); + + return this.client.getDMChannel(message.author.id).then((chan) => { + chan.createMessage(`__**CS Account Referral Code**__\n*Referral codes are considered to be somewhat private information. Applicants with referral codes have a greater chance of approval, don't refer someone you don't trust :).*\nYour referral code: \`${account.referralCode}\`\nReferrals Granted: \`${account.totalReferrals ? account.totalReferrals : '0'}`); + }).catch(() => this.error(message.channel, 'Could not send you a DM.')); + } catch (err) { + return this.client.util.handleError(err, message, this); + } + } +} diff --git a/src/commands/index.ts b/src/commands/index.ts index 0f7f9a9..66aa78c 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -1,3 +1,4 @@ +export { default as addreferral } from './addreferral'; export { default as announce } from './announce'; export { default as bearer } from './bearer'; export { default as cloudflare } from './cloudflare'; @@ -7,6 +8,7 @@ export { default as deleteaccount } from './deleteaccount'; export { default as emailcode } from './emailcode'; export { default as eval } from './eval'; export { default as exec } from './exec'; +export { default as getreferral } from './getreferral'; export { default as help } from './help'; export { default as info } from './info'; export { default as limits } from './limits'; diff --git a/src/commands/lock.ts b/src/commands/lock.ts index 273dc51..442902a 100644 --- a/src/commands/lock.ts +++ b/src/commands/lock.ts @@ -36,6 +36,7 @@ export default class Lock extends Command { this.client.util.transport.sendMail({ to: account.emailAddress, from: 'Library of Code sp-us | Cloud Services ', + replyTo: 'cloud-help@libraryofcode.org', subject: 'Your account has been locked', html: `

Library of Code | Cloud Services

diff --git a/src/commands/notify.ts b/src/commands/notify.ts index df7d76b..0572475 100644 --- a/src/commands/notify.ts +++ b/src/commands/notify.ts @@ -31,6 +31,7 @@ export default class Notify extends Command { this.client.util.transport.sendMail({ to: account.emailAddress, from: 'Library of Code sp-us | Cloud Services ', + replyTo: 'cloud-help@libraryofcode.org', subject: 'Notification', html: `

Library of Code sp-us | Cloud Services

diff --git a/src/commands/warn.ts b/src/commands/warn.ts index 607f5c9..07a7426 100644 --- a/src/commands/warn.ts +++ b/src/commands/warn.ts @@ -25,6 +25,7 @@ export default class Warn extends Command { return this.client.util.transport.sendMail({ to: account.emailAddress, from: 'Library of Code sp-us | Cloud Services ', + replyTo: 'cloud-help@libraryofcode.org', subject: 'Your account has been warned', html: `

Library of Code sp-us | Cloud Services

diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 51a9b12..16fb1f1 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -84,6 +84,7 @@ export default class Whois extends Command { embed.addField('Email Address', account.emailAddress, true); embed.addField('Tier', String(account.tier), true); embed.addField('Support Key', account.supportKey, true); + embed.addField('Referral Code & Total', `${account.referralCode} | ${account.totalReferrals}`, true); embed.addField('Created By', `<@${this.client.users.get(account.createdBy).id}>`, true); embed.addField('Created At', moment(account.createdAt).format('dddd, MMMM Do YYYY, h:mm:ss A'), true); embed.addField('CPU Usage', `${cpuUsage.split('\n')[0] || '0'}%`, true);