From a36b579a9c70abaecae99fd3befe52133997a389 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 31 Oct 2023 18:19:55 -0400 Subject: [PATCH 01/17] try to fix issue with Util's .join() func --- src/class/AccountUtil.ts | 2 +- src/class/Util.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/class/AccountUtil.ts b/src/class/AccountUtil.ts index 7b2243c..f7b03fe 100644 --- a/src/class/AccountUtil.ts +++ b/src/class/AccountUtil.ts @@ -85,7 +85,7 @@ export default class AccountUtil { return { account: accountInterface, tempPass }; } - public async lock(username: string, moderatorID: string, data?: { reason?: string, time?: number}) { + public async lock(username: string, moderatorID: string, data?: { reason?: string, time?: number }) { const account = await this.client.db.Account.findOne({ username }); if (!account) throw new Error('Account does not exist.'); if (account.locked) throw new Error('Account is already locked.'); diff --git a/src/class/Util.ts b/src/class/Util.ts index 4bf3246..759dc67 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -299,7 +299,7 @@ export default class Util { .setTitle(embedTitle) .setColor(color) .addField('User', `${username} | <@${userID}>`, true) - .addField(archType, moderatorID === this.client.user.id ? 'SYSTEM' : `${moderator.username}, ${find.pn.join(', ')} (<@${moderatorID}>)`, true) + .addField(archType, moderatorID === this.client.user.id ? 'SYSTEM' : `${moderator.username},${find.isManager ? ' [k] ' : ' '}(<@${moderatorID}>)`, true) .setFooter(this.client.user.username, this.client.user.avatarURL()) .setTimestamp(); if (reason) embed.addField('Reason', reason || 'Not specified'); From b6da450c943f6b44043c6aa9191670bdbad85e32 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 31 Oct 2023 18:48:39 -0400 Subject: [PATCH 02/17] fix .join() in notify --- src/commands/notify.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/notify.ts b/src/commands/notify.ts index 50fc8ee..2d288d8 100644 --- a/src/commands/notify.ts +++ b/src/commands/notify.ts @@ -30,7 +30,7 @@ export default class Notify extends Command { embed.addField('User', `${account.username} | <@${account.userID}>`, true); const req = await axios.get('https://loc.sh/int/directory'); const technician = req.data.find((mem) => mem.userID === message.author.id); - embed.addField('Technician', message.author.id === this.client.user.id ? 'SYSTEM' : `${message.author.username}, ${technician.pn.join(', ')} (<@${message.author.id}>)`, true); + embed.addField('Technician', message.author.id === this.client.user.id ? 'SYSTEM' : `${message.author.username},${technician.isManager ? ' [k] ' : ' '}(<@${message.author.id}>)`, true); const ch = this.client.channels.cache.get('580950455581147146') as TextChannel; ch.send({ embeds: [embed] }); this.client.util.transport.sendMail({ From f231cc4fdd97c7cb40534f4f50846900b095f5c6 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 14 Nov 2023 17:58:50 -0500 Subject: [PATCH 03/17] fix .join() in various commands --- src/class/AccountUtil.ts | 2 +- src/class/Util.ts | 2 +- src/commands/notify.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/class/AccountUtil.ts b/src/class/AccountUtil.ts index f7b03fe..cbb7022 100644 --- a/src/class/AccountUtil.ts +++ b/src/class/AccountUtil.ts @@ -47,7 +47,7 @@ export default class AccountUtil {

Username: ${data.username}

Support Key: ${code} || You may be asked for this support key when contacting Library of Code, please keep the code in a safe area.

SSH Login:

ssh ${data.username}@cloud.libraryofcode.org
-

Underwritten by: ${moderatorMember.user.username}, ${find.pn.join(', ')} +

Underwritten by: ${moderatorMember.user.username}${find.isManager ? ' [k]' : ' '}

Useful information

How to log in:

    diff --git a/src/class/Util.ts b/src/class/Util.ts index 759dc67..2d08abf 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -299,7 +299,7 @@ export default class Util { .setTitle(embedTitle) .setColor(color) .addField('User', `${username} | <@${userID}>`, true) - .addField(archType, moderatorID === this.client.user.id ? 'SYSTEM' : `${moderator.username},${find.isManager ? ' [k] ' : ' '}(<@${moderatorID}>)`, true) + .addField(archType, moderatorID === this.client.user.id ? 'SYSTEM' : `${moderator.username}${find.isManager ? ' [k] ' : ' '}(<@${moderatorID}>)`, true) .setFooter(this.client.user.username, this.client.user.avatarURL()) .setTimestamp(); if (reason) embed.addField('Reason', reason || 'Not specified'); diff --git a/src/commands/notify.ts b/src/commands/notify.ts index 2d288d8..5d20616 100644 --- a/src/commands/notify.ts +++ b/src/commands/notify.ts @@ -30,7 +30,7 @@ export default class Notify extends Command { embed.addField('User', `${account.username} | <@${account.userID}>`, true); const req = await axios.get('https://loc.sh/int/directory'); const technician = req.data.find((mem) => mem.userID === message.author.id); - embed.addField('Technician', message.author.id === this.client.user.id ? 'SYSTEM' : `${message.author.username},${technician.isManager ? ' [k] ' : ' '}(<@${message.author.id}>)`, true); + embed.addField('Technician', message.author.id === this.client.user.id ? 'SYSTEM' : `${message.author.username}${technician.isManager ? ' [k] ' : ' '}(<@${message.author.id}>)`, true); const ch = this.client.channels.cache.get('580950455581147146') as TextChannel; ch.send({ embeds: [embed] }); this.client.util.transport.sendMail({ From 88e2273f5fb7759cdfa30f080b8509fbbd27082f Mon Sep 17 00:00:00 2001 From: Matthew Date: Sat, 6 Jan 2024 19:01:40 -0500 Subject: [PATCH 04/17] fix dm issue with resetpassword.ts --- src/commands/resetpassword.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/commands/resetpassword.ts b/src/commands/resetpassword.ts index 7cc10ed..5785dd1 100644 --- a/src/commands/resetpassword.ts +++ b/src/commands/resetpassword.ts @@ -31,8 +31,7 @@ export default class ResetPassword extends Command { + `You will be asked to change your password when you log back in, \`(current) UNIX password\` is \`${tempPass}@\`, then create a password that is at least 12 characters long, with at least one number, special character, and an uppercase letter.\n` + 'Bear in mind that when you enter your password, it will be blank, so be careful not to type in your password incorrectly.'); } catch (error) { - if (error.code === 50007) completeMessage += '\n*Unable to DM user*'; - throw error; + completeMessage += '\n*Unable to DM user*'; } return msg.edit(completeMessage); } catch (error) { From 9d9485700a58152569585501d39236ee336364a8 Mon Sep 17 00:00:00 2001 From: Matthew Date: Sat, 6 Jan 2024 19:03:02 -0500 Subject: [PATCH 05/17] fix dm issue with createAccount func --- src/class/AccountUtil.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/class/AccountUtil.ts b/src/class/AccountUtil.ts index cbb7022..2fdcb70 100644 --- a/src/class/AccountUtil.ts +++ b/src/class/AccountUtil.ts @@ -76,12 +76,16 @@ export default class AccountUtil { const member = guild.members.cache.get(data.userID); await member.roles.add('546457886440685578'); const user = this.client.users.cache.get(data.userID); - user.send('<:loc:607695848612167700> **Thank you for creating an account with us!** <:loc:607695848612167700>\n' - + `Please log into your account by running \`ssh ${data.username}@cloud.libraryofcode.org\` in your terminal, then use the password \`${tempPass}\` to log in.\n` - + `You will be asked to change your password, \`(current) UNIX password\` is \`${tempPass}\`, then create a password that is at least 12 characters long, with at least one number, special character, and an uppercase letter\n` - + 'Bear in mind that when you enter your password, it will be blank, so be careful not to type in your password incorrectly.\n\n' - + 'An email containing some useful information has also been sent.\n' - + `Your support key is \`${code}\`. Pin this message, you may need this key to contact Library of Code in the future.`).catch(); + try { + await user.send('<:loc:607695848612167700> **Thank you for creating an account with us!** <:loc:607695848612167700>\n' + + `Please log into your account by running \`ssh ${data.username}@cloud.libraryofcode.org\` in your terminal, then use the password \`${tempPass}\` to log in.\n` + + `You will be asked to change your password, \`(current) UNIX password\` is \`${tempPass}\`, then create a password that is at least 12 characters long, with at least one number, special character, and an uppercase letter\n` + + 'Bear in mind that when you enter your password, it will be blank, so be careful not to type in your password incorrectly.\n\n' + + 'An email containing some useful information has also been sent.\n' + + `Your support key is \`${code}\`. Pin this message, you may need this key to contact Library of Code in the future.`); + } catch (error) { + this.client.util.handleError(error); + } return { account: accountInterface, tempPass }; } From 3d930792fe2df95584d1c2337adbbcb62596a02f Mon Sep 17 00:00:00 2001 From: Matthew Date: Sat, 6 Jan 2024 19:06:44 -0500 Subject: [PATCH 06/17] various improvements to handling modlogs --- src/class/Util.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index 2d08abf..279cacc 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -276,7 +276,7 @@ export default class Util { } else date = null; } - const expiration = { date, processed }; + const expiration: { date: Date; processed: boolean } = { date, processed }; logInput.expiration = expiration; const log = new this.client.db.Moderation(logInput); @@ -290,8 +290,8 @@ export default class Util { case 0: archType = 'Technician'; embedTitle = 'Cloud Account | Create'; color = '#00ff00'; break; case 1: archType = 'Technician'; embedTitle = 'Account Warning | Warn'; color = '#ffff00'; break; case 2: archType = 'Technician'; embedTitle = 'Account Infraction | Lock'; color = '#ff6600'; break; - case 3: archType = 'Technician'; embedTitle = 'Account Reclaim | Unlock'; color = '#0099ff'; break; - case 4: archType = 'Director'; embedTitle = 'Cloud Account | Delete'; color = '#ff0000'; break; + case 3: archType = 'Technician'; embedTitle = 'Account Infraction | Unlock'; color = '#0099ff'; break; + case 4: archType = 'Manager'; embedTitle = 'Cloud Account | Delete'; color = '#ff0000'; break; } const req = await axios.get('https://loc.sh/int/directory'); const find = req.data.find((mem) => mem.userID === moderator.id); From 60683688cea91ab687248041f5fd8926f5ade2fd Mon Sep 17 00:00:00 2001 From: Matthew Date: Sat, 6 Jan 2024 19:06:53 -0500 Subject: [PATCH 07/17] fix css in AccountUtil.ts --- src/class/AccountUtil.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/class/AccountUtil.ts b/src/class/AccountUtil.ts index 2fdcb70..679c9f3 100644 --- a/src/class/AccountUtil.ts +++ b/src/class/AccountUtil.ts @@ -41,7 +41,7 @@ export default class AccountUtil { subject: 'Approval for CS Account', html: ` - +

    Library of Code | Cloud Services

    Congratulations, your CS Account application has been approved. Welcome! Please see below for some details regarding your account and our services

    Username: ${data.username}

    From 77e50b61c5517d6f4aad36ecc48b96fb5d4cce71 Mon Sep 17 00:00:00 2001 From: Matthew Date: Sat, 6 Jan 2024 19:08:18 -0500 Subject: [PATCH 08/17] fix css in AccountUtil.ts (p2) --- src/class/AccountUtil.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/class/AccountUtil.ts b/src/class/AccountUtil.ts index 679c9f3..1b86906 100644 --- a/src/class/AccountUtil.ts +++ b/src/class/AccountUtil.ts @@ -46,7 +46,7 @@ export default class AccountUtil {

    Congratulations, your CS Account application has been approved. Welcome! Please see below for some details regarding your account and our services

    Username: ${data.username}

    Support Key: ${code} || You may be asked for this support key when contacting Library of Code, please keep the code in a safe area.

    -

    SSH Login:

    ssh ${data.username}@cloud.libraryofcode.org
    +

    SSH Login:

    ssh ${data.username}@cloud.libraryofcode.org

    Underwritten by: ${moderatorMember.user.username}${find.isManager ? ' [k]' : ' '}

    Useful information

    How to log in:

    From 276467519f828de3eb8423c3f6099510207e598a Mon Sep 17 00:00:00 2001 From: Matthew Date: Sat, 6 Jan 2024 19:10:42 -0500 Subject: [PATCH 09/17] qol changes for Util.ts --- src/class/Util.ts | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index 279cacc..d58b062 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -2,18 +2,18 @@ /* eslint-disable no-await-in-loop */ /* eslint-disable no-param-reassign */ import axios from 'axios'; -import { randomBytes } from 'crypto'; +import {randomBytes} from 'crypto'; import childProcess from 'child_process'; import nodemailer from 'nodemailer'; -import { Message, DMChannel, User, MessageEmbed, ColorResolvable, TextChannel } from 'discord.js'; -import { v4 as uuid } from 'uuid'; +import {ColorResolvable, DMChannel, Message, MessageEmbed, TextChannel, User} from 'discord.js'; +import {v4 as uuid} from 'uuid'; import moment from 'moment'; import fs from 'fs'; import hastebin from 'hastebin-gen'; -import { getUserByUid } from '../functions'; -import { AccountUtil, Client, Command, PaginationEmbed } from '.'; -import { ModerationInterface, AccountInterface } from '../models'; -import { Certificate } from '../../types/x509'; +import {getUserByUid} from '../functions'; +import {AccountUtil, Client, Command, PaginationEmbed} from '.'; +import {AccountInterface, ModerationInterface} from '../models'; +import {Certificate} from '../../types/x509'; export default class Util { public client: Client; @@ -46,7 +46,7 @@ export default class Util { cmd.stdout.on('data', writeFunction); cmd.stderr.on('data', writeFunction); cmd.on('error', writeFunction); - cmd.once('close', (code, signal) => { + cmd.once('close', (code) => { cmd.stdout.off('data', writeFunction); cmd.stderr.off('data', writeFunction); cmd.off('error', writeFunction); @@ -184,16 +184,14 @@ export default class Util { } public async createHash(password: string): Promise { - const hashed = await this.exec(`mkpasswd -m sha-512 "${password}"`); - return hashed; + return this.exec(`mkpasswd -m sha-512 "${password}"`); } public isValidEmail(email: string): boolean { const checkAt = email.indexOf('@'); if (checkAt < 1) return false; const checkDomain = email.indexOf('.', checkAt + 2); - if (checkDomain < checkAt) return false; - return true; + return checkDomain >= checkAt; } public randomPassword(): string { From e653484be43155ff4819915052bb799d7439028b Mon Sep 17 00:00:00 2001 From: Matthew Date: Sun, 7 Jan 2024 13:29:57 -0500 Subject: [PATCH 10/17] update technician name formatting function --- src/class/Util.ts | 33 ++++++---- src/commands/cwg_create.ts | 2 +- src/commands/cwg_delete.ts | 122 ++++++++++++++++++------------------- src/commands/tier.ts | 2 +- src/commands/whois.ts | 18 +++--- 5 files changed, 93 insertions(+), 84 deletions(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index d58b062..c4483be 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -2,18 +2,24 @@ /* eslint-disable no-await-in-loop */ /* eslint-disable no-param-reassign */ import axios from 'axios'; -import {randomBytes} from 'crypto'; +import { randomBytes } from 'crypto'; import childProcess from 'child_process'; import nodemailer from 'nodemailer'; -import {ColorResolvable, DMChannel, Message, MessageEmbed, TextChannel, User} from 'discord.js'; -import {v4 as uuid} from 'uuid'; +import { ColorResolvable, DMChannel, Message, MessageEmbed, TextChannel, User } from 'discord.js'; +import { v4 as uuid } from 'uuid'; import moment from 'moment'; import fs from 'fs'; import hastebin from 'hastebin-gen'; -import {getUserByUid} from '../functions'; -import {AccountUtil, Client, Command, PaginationEmbed} from '.'; -import {AccountInterface, ModerationInterface} from '../models'; -import {Certificate} from '../../types/x509'; +import { getUserByUid } from '../functions'; +import { AccountUtil, Client, Command, PaginationEmbed } from '.'; +import { AccountInterface, ModerationInterface } from '../models'; +import { Certificate } from '../../types/x509'; + +enum TechnicianNameFormatOpt { + Full = 0, + Partial, + Basic +} export default class Util { public client: Client; @@ -309,13 +315,18 @@ export default class Util { return Promise.resolve(log); } - public async getTechnicianFullName(tech: User) { - if (!tech) throw new Error('\'tech\' is undefined.'); - if (tech.id === this.client.user.id) return 'SYSTEM'; + public async getTechnicianName(tech: User, format: TechnicianNameFormatOpt = TechnicianNameFormatOpt.Full) { + if (!tech) return 'SYSTEM (U)'; + if (tech.id === this.client.user.id) return 'SYSTEM (S)'; const req = await axios.get('https://loc.sh/int/directory'); const find = req.data.find((mem) => mem.userID === tech.id); - return `${tech.username}${find.isManager ? '[k]' : ''}${find.title ? ` (${find.title} / ${find.dept})` : ` (${find.dept})`} <<@${tech.id}>>`; + if (format === TechnicianNameFormatOpt.Full) { + return `${tech.username}${find.isManager ? ' [k]' : ''}${find.title ? ` (${find.title} / ${find.dept})` : ` (${find.dept})`} <<@${tech.id}>>`; + } else if (format === TechnicianNameFormatOpt.Partial) { + return `${tech.username}${find.isManager ? ' [k]' : ''}${find.title ? ` (${find.title})` : ` (${find.dept})`} <<@${tech.id}>>`; + } + return `${tech.username}${find.isManager ? ' [k]' : ''} <<@${tech.id}>>`; } public parseCertificate(pem: string) { diff --git a/src/commands/cwg_create.ts b/src/commands/cwg_create.ts index 72a53b6..19a58b7 100644 --- a/src/commands/cwg_create.ts +++ b/src/commands/cwg_create.ts @@ -84,7 +84,7 @@ export default class CWG_Create extends Command { .setTitle('Domain Creation') .setColor(3066993) .addField('Account Username', `${account.username} | <@${account.userID}>`, true) - .addField('Technician', await this.client.util.getTechnicianFullName(message.author), true) + .addField('Technician', await this.client.util.getTechnicianName(message.author), 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 24c721e..da9e715 100644 --- a/src/commands/cwg_delete.ts +++ b/src/commands/cwg_delete.ts @@ -1,61 +1,61 @@ -import fs from 'fs-extra'; -import axios from 'axios'; -import { Message, MessageEmbed, TextChannel } from 'discord.js'; -import { Client, Command } from '../class'; - -export default class CWG_Delete extends Command { - constructor(client: Client) { - super(client); - this.name = 'delete'; - this.description = 'Unbind a domain from the CWG'; - this.usage = `${this.client.config.prefix}cwg delete [Domain | Port]`; - this.permissions = { roles: ['662163685439045632', '701454780828221450'] }; - this.aliases = ['unbind']; - this.enabled = true; - } - - public async run(message: Message, args: string[]) { - try { - if (!args[0]) return this.client.commands.get('help').run(message, ['cwg', this.name]); - const domain = await this.client.db.Domain.findOne({ $or: [{ domain: args[0] }, { port: Number(args[0]) || 0 }] }); - if (!domain) return this.error(message.channel, 'The domain or port you provided could not be found.'); - const edit = await this.loading(message.channel, 'Deleting domain...'); - const embed = new MessageEmbed(); - embed.setTitle('Domain Deletion'); - embed.addField('Account Username', `${domain.account.username} | <@${domain.account.userID}>`, true); - embed.addField('Technician', await this.client.util.getTechnicianFullName(message.author), true); - embed.addField('Domain', domain.domain, true); - embed.addField('Port', String(domain.port), true); - embed.setFooter(this.client.user.username, this.client.user.avatarURL()); - embed.setTimestamp(); - if (domain.domain.includes('cloud.libraryofcode.org')) { - const resultID = await axios({ - method: 'get', - url: `https://api.cloudflare.com/client/v4/zones/5e82fc3111ed4fbf9f58caa34f7553a7/dns_records?name=${domain.domain}`, - headers: { Authorization: `Bearer ${this.client.config.cloudflare}` }, - }); - this.client.signale.debug(resultID.data); - if (resultID.data.result[0]) { - const recordID = resultID.data.result[0].id; - await axios({ - method: 'delete', - url: `https://api.cloudflare.com/client/v4/zones/5e82fc3111ed4fbf9f58caa34f7553a7/dns_records/${recordID}`, - headers: { Authorization: `Bearer ${this.client.config.cloudflare}` }, - }); - } - } - try { - await fs.unlink(`/etc/nginx/sites-enabled/${domain.domain}`); - await fs.unlink(`/etc/nginx/sites-available/${domain.domain}`); - } catch (e) { this.client.signale.error(e); } - await this.client.db.Domain.deleteOne({ domain: domain.domain }); - await this.client.util.exec('systemctl reload nginx'); - edit.edit(`***${this.client.stores.emojis.success} Domain ${domain.domain} with port ${domain.port} has been successfully deleted.***`); - const ch = this.client.channels.cache.get('580950455581147146') as TextChannel; - ch.send({ embeds: [embed] }); - return this.client.users.fetch(domain.account.userID).then((u) => u.send({ embeds: [embed] })).catch(() => {}); - } catch (error) { - return this.client.util.handleError(error, message, this); - } - } -} +import fs from 'fs-extra'; +import axios from 'axios'; +import { Message, MessageEmbed, TextChannel } from 'discord.js'; +import { Client, Command } from '../class'; + +export default class CWG_Delete extends Command { + constructor(client: Client) { + super(client); + this.name = 'delete'; + this.description = 'Unbind a domain from the CWG'; + this.usage = `${this.client.config.prefix}cwg delete [Domain | Port]`; + this.permissions = { roles: ['662163685439045632', '701454780828221450'] }; + this.aliases = ['unbind']; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + try { + if (!args[0]) return this.client.commands.get('help').run(message, ['cwg', this.name]); + const domain = await this.client.db.Domain.findOne({ $or: [{ domain: args[0] }, { port: Number(args[0]) || 0 }] }); + if (!domain) return this.error(message.channel, 'The domain or port you provided could not be found.'); + const edit = await this.loading(message.channel, 'Deleting domain...'); + const embed = new MessageEmbed(); + embed.setTitle('Domain Deletion'); + embed.addField('Account Username', `${domain.account.username} | <@${domain.account.userID}>`, true); + embed.addField('Technician', await this.client.util.getTechnicianName(message.author), true); + embed.addField('Domain', domain.domain, true); + embed.addField('Port', String(domain.port), true); + embed.setFooter(this.client.user.username, this.client.user.avatarURL()); + embed.setTimestamp(); + if (domain.domain.includes('cloud.libraryofcode.org')) { + const resultID = await axios({ + method: 'get', + url: `https://api.cloudflare.com/client/v4/zones/5e82fc3111ed4fbf9f58caa34f7553a7/dns_records?name=${domain.domain}`, + headers: { Authorization: `Bearer ${this.client.config.cloudflare}` }, + }); + this.client.signale.debug(resultID.data); + if (resultID.data.result[0]) { + const recordID = resultID.data.result[0].id; + await axios({ + method: 'delete', + url: `https://api.cloudflare.com/client/v4/zones/5e82fc3111ed4fbf9f58caa34f7553a7/dns_records/${recordID}`, + headers: { Authorization: `Bearer ${this.client.config.cloudflare}` }, + }); + } + } + try { + await fs.unlink(`/etc/nginx/sites-enabled/${domain.domain}`); + await fs.unlink(`/etc/nginx/sites-available/${domain.domain}`); + } catch (e) { this.client.signale.error(e); } + await this.client.db.Domain.deleteOne({ domain: domain.domain }); + await this.client.util.exec('systemctl reload nginx'); + edit.edit(`***${this.client.stores.emojis.success} Domain ${domain.domain} with port ${domain.port} has been successfully deleted.***`); + const ch = this.client.channels.cache.get('580950455581147146') as TextChannel; + ch.send({ embeds: [embed] }); + return this.client.users.fetch(domain.account.userID).then((u) => u.send({ embeds: [embed] })).catch(() => {}); + } catch (error) { + return this.client.util.handleError(error, message, this); + } + } +} diff --git a/src/commands/tier.ts b/src/commands/tier.ts index 068dd83..7bc1e46 100644 --- a/src/commands/tier.ts +++ b/src/commands/tier.ts @@ -32,7 +32,7 @@ export default class Tier extends Command { embed.setTitle('Cloud Account | Tier Change'); embed.setColor('#0099ff'); embed.addField('User', `${account.username} | <@${account.userID}>`, true); - embed.addField('Technician', await this.client.util.getTechnicianFullName(message.author), true); + embed.addField('Technician', await this.client.util.getTechnicianName(message.author), true); embed.addField('Old Tier -> New Tier', `${account.tier} -> ${args[1]}`, true); embed.setFooter(this.client.user.username, this.client.user.avatarURL()); embed.setTimestamp(); diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 39a3989..fd40592 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -46,7 +46,7 @@ export default class Whois extends Command { if (account.locked) details += '__This account is currently locked.__\n'; switch (true) { case account.permissions.director: - details += 'This account belongs to a Director.\n'; + details += 'This account belongs to a Manager.\n'; role = await message.member.guild.roles.fetch('662163685439045632'); break; case account.permissions.technician: @@ -61,7 +61,7 @@ export default class Whois extends Command { role = await message.member.guild.roles.fetch(message.member.guild.id); break; } - if (account.root) details += '**This account has root/administrative privileges.**\n'; + if (account.root) details += '**This account has administrative privileges.**\n'; embed.setColor(role.color || 0x36393f); if (details) embed.addField('Additional Details', details, true); @@ -84,14 +84,13 @@ export default class Whois extends Command { embed.setDescription(`${finger}\n${chage}`); embed.addField('Username', `${account.username} | <@${account.userID}>`, true); - embed.addField('ID', account.userID, true); + embed.addField('Account ID', account._id, true); + embed.addField('Discord ID', account.userID, true); 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', await this.client.users.fetch(account.createdBy) - ? (await this.client.users.fetch(account.createdBy)).toString() - : 'SYSTEM', true); + embed.addField('Created By', await this.client.util.getTechnicianName(await this.client.users.fetch(account.createdBy)), 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); embed.addField('Memory', dataConversion(Number(memory) * 1000), true); @@ -106,11 +105,10 @@ export default class Whois extends Command { ]); embed.addField('Username', `${account.username} | <@${account.userID}>`, true); - embed.addField('ID', account.userID, true); + embed.addField('Account ID', account._id, true); + embed.addField('Discord ID', account.userID, true); embed.addField('Tier', String(account.tier), true); - embed.addField('Created By', await this.client.users.fetch(account.createdBy) - ? (await this.client.users.fetch(account.createdBy)).toString() - : 'SYSTEM', true); + embed.addField('Created By', await this.client.util.getTechnicianName(await this.client.users.fetch(account.createdBy), 2), 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); embed.addField('Memory', dataConversion(Number(memory) * 1000), true); From a2e9a87e69826895e72f1a41d4e9e1d304043911 Mon Sep 17 00:00:00 2001 From: Matthew Date: Sun, 7 Jan 2024 13:40:04 -0500 Subject: [PATCH 11/17] fix attempt --- src/commands/whois.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/commands/whois.ts b/src/commands/whois.ts index fd40592..83ad1e0 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -84,13 +84,12 @@ export default class Whois extends Command { embed.setDescription(`${finger}\n${chage}`); embed.addField('Username', `${account.username} | <@${account.userID}>`, true); - embed.addField('Account ID', account._id, true); embed.addField('Discord ID', account.userID, true); 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', await this.client.util.getTechnicianName(await this.client.users.fetch(account.createdBy)), true); + embed.addField('Created By', (await this.client.util.getTechnicianName(await this.client.users.fetch(account.createdBy))), 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); embed.addField('Memory', dataConversion(Number(memory) * 1000), true); @@ -105,10 +104,9 @@ export default class Whois extends Command { ]); embed.addField('Username', `${account.username} | <@${account.userID}>`, true); - embed.addField('Account ID', account._id, true); embed.addField('Discord ID', account.userID, true); embed.addField('Tier', String(account.tier), true); - embed.addField('Created By', await this.client.util.getTechnicianName(await this.client.users.fetch(account.createdBy), 2), true); + embed.addField('Created By', (await this.client.util.getTechnicianName(await this.client.users.fetch(account.createdBy), 2)), 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); embed.addField('Memory', dataConversion(Number(memory) * 1000), true); From 7337f7702717dfa72e9dfa76949952aee59d80dd Mon Sep 17 00:00:00 2001 From: Matthew Date: Sun, 7 Jan 2024 13:45:25 -0500 Subject: [PATCH 12/17] fix attempt x3 --- src/class/Util.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index c4483be..56cca06 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -316,11 +316,12 @@ export default class Util { } public async getTechnicianName(tech: User, format: TechnicianNameFormatOpt = TechnicianNameFormatOpt.Full) { - if (!tech) return 'SYSTEM (U)'; - if (tech.id === this.client.user.id) return 'SYSTEM (S)'; + if (!tech) return 'SYSTEM (UT)'; + if (tech.id === this.client.user.id) return 'SYSTEM (SELF)'; const req = await axios.get('https://loc.sh/int/directory'); const find = req.data.find((mem) => mem.userID === tech.id); + if (!find) return 'SYSTEM (UF)'; if (format === TechnicianNameFormatOpt.Full) { return `${tech.username}${find.isManager ? ' [k]' : ''}${find.title ? ` (${find.title} / ${find.dept})` : ` (${find.dept})`} <<@${tech.id}>>`; } else if (format === TechnicianNameFormatOpt.Partial) { From 2a9492ccbba204da5dbb27ab3e05444efe0501fa Mon Sep 17 00:00:00 2001 From: Matthew Date: Sun, 7 Jan 2024 13:51:40 -0500 Subject: [PATCH 13/17] prettify whois --- src/commands/whois.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 83ad1e0..3375075 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -83,7 +83,7 @@ export default class Whois extends Command { const finger = !member.roles.cache.has('662163685439045632') ? fingerInformation.replace(this.IP_REGEX, '[MASKED IP ADDRESS]') : fingerInformation; embed.setDescription(`${finger}\n${chage}`); - embed.addField('Username', `${account.username} | <@${account.userID}>`, true); + embed.addField('Username', `${account.username} <<@${account.userID}>>`, true); embed.addField('Discord ID', account.userID, true); embed.addField('Email Address', account.emailAddress, true); embed.addField('Tier', String(account.tier), true); @@ -103,7 +103,7 @@ export default class Whois extends Command { this.client.util.exec(`memory ${account.username}`), ]); - embed.addField('Username', `${account.username} | <@${account.userID}>`, true); + embed.addField('Username', `${account.username} <<@${account.userID}>>`, true); embed.addField('Discord ID', account.userID, true); embed.addField('Tier', String(account.tier), true); embed.addField('Created By', (await this.client.util.getTechnicianName(await this.client.users.fetch(account.createdBy), 2)), true); From 9ecc9f1324577d3ce611ea9536dbe93f975852ee Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 8 Jan 2024 20:32:32 -0500 Subject: [PATCH 14/17] qol changes for Util.ts --- src/commands/whois.ts | 2 ++ src/models/Tier.ts | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 3375075..2fa0693 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -66,6 +66,7 @@ export default class Whois extends Command { if (details) embed.addField('Additional Details', details, true); embed.setTimestamp(); + embed.setFooter('Library of Code | Cloud Services', message.guild.iconURL()); return message.channel.send({ embeds: [embed] }); } catch (error) { return this.client.util.handleError(error, message, this); @@ -103,6 +104,7 @@ export default class Whois extends Command { this.client.util.exec(`memory ${account.username}`), ]); + embed.setDescription('*CPU Usage and Memory are fetched in real-time, storage information is cached.*'); embed.addField('Username', `${account.username} <<@${account.userID}>>`, true); embed.addField('Discord ID', account.userID, true); embed.addField('Tier', String(account.tier), true); diff --git a/src/models/Tier.ts b/src/models/Tier.ts index 4bf81ed..d44a758 100644 --- a/src/models/Tier.ts +++ b/src/models/Tier.ts @@ -21,3 +21,7 @@ const Tier = new Schema({ }, { id: false }); export default model('Tier', Tier); + +(new this.client.db.Tier({ id: 0, { resourceLimits: { ram: 10000, storage: 50000 } } })) + +(new this.client.db.Tier({ id: 0, resourceLimits: { ram: 10000, storage: 50000 } })); From c283487b5a982d5d493b505ddff9015f87ddd332 Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 8 Jan 2024 20:34:30 -0500 Subject: [PATCH 15/17] fix auto tier --- src/commands/tier.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/tier.ts b/src/commands/tier.ts index 7bc1e46..ce0a0c9 100644 --- a/src/commands/tier.ts +++ b/src/commands/tier.ts @@ -18,8 +18,8 @@ export default class Tier extends Command { const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0].replace(/[<@!>]/gi, '') }] }); if (!account) return edit.edit(`***${this.client.stores.emojis.error} Cannot find user.***`); if (account.root) return edit.edit(`***${this.client.stores.emojis.error} Permission denied.***`); - if (Number.isNaN(Number(args[1]))) return edit.edit(`***${this.client.stores.emojis.error} The tier you provided is not a valid number. It should be between 1 and 3.***`); - if (Number(args[1]) > 3 || Number(args[1]) < 1) return edit.edit(`***${this.client.stores.emojis.error} You can only choose a Tier between 1 and 3.***`); + if (Number.isNaN(Number(args[1]))) return edit.edit(`***${this.client.stores.emojis.error} The tier you provided is not a valid number. It should be between 0 and 3.***`); + if (Number(args[1]) > 3 || Number(args[1]) < 0) return edit.edit(`***${this.client.stores.emojis.error} You can only choose a Tier between 0 and 3.***`); message.delete(); const tier = await this.client.db.Tier.findOne({ id: Number(args[1]) }); if (account.ramLimitNotification !== -1) { From 64f67c9a18e020ed0862720108fc90d8328c5a60 Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 8 Jan 2024 20:35:11 -0500 Subject: [PATCH 16/17] fix auto tier --- src/models/Tier.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/models/Tier.ts b/src/models/Tier.ts index d44a758..4bf81ed 100644 --- a/src/models/Tier.ts +++ b/src/models/Tier.ts @@ -21,7 +21,3 @@ const Tier = new Schema({ }, { id: false }); export default model('Tier', Tier); - -(new this.client.db.Tier({ id: 0, { resourceLimits: { ram: 10000, storage: 50000 } } })) - -(new this.client.db.Tier({ id: 0, resourceLimits: { ram: 10000, storage: 50000 } })); From 309f080b379a462814415040bb53d8cba0accb5e Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 8 Jan 2024 20:43:29 -0500 Subject: [PATCH 17/17] fix auto tier --- src/intervals/checkStaffStatus.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/intervals/checkStaffStatus.ts b/src/intervals/checkStaffStatus.ts index 7e8e9d2..0f09fb7 100644 --- a/src/intervals/checkStaffStatus.ts +++ b/src/intervals/checkStaffStatus.ts @@ -52,7 +52,7 @@ export default function checkStaffStatus(client: Client) { await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.intern': false } }); } - if ((acc.permissions.staff || acc.permissions.intern || acc.permissions.technician || acc.permissions.director || user.roles.cache.has('858049948401401866')) && acc.tier < 3) { + if ((acc.permissions.staff || acc.permissions.intern || acc.permissions.technician || acc.permissions.director || user.roles.cache.has('858049948401401866')) && (acc.tier < 3 && acc.tier > 0)) { await client.db.Account.updateOne({ username: acc.username }, { $set: { tier: 3 } }); const embed = new MessageEmbed(); embed.setTitle('Cloud Account | Tier Change');