1
0
Fork 0

update technician name formatting function

pull/1/head
Matthew 2024-01-07 13:29:57 -05:00
parent 276467519f
commit e653484be4
Signed by: matthew
SSH Key Fingerprint: SHA256:piIXekA9q1p0ZGi4ogFbNY1embip5Ytbi3v8AZ8UYq4
5 changed files with 93 additions and 84 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -23,7 +23,7 @@ export default class CWG_Delete extends Command {
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('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());

View File

@ -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();

View File

@ -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);