forked from engineering/cloudservices
update technician name formatting function
parent
276467519f
commit
e653484be4
|
@ -2,18 +2,24 @@
|
||||||
/* eslint-disable no-await-in-loop */
|
/* eslint-disable no-await-in-loop */
|
||||||
/* eslint-disable no-param-reassign */
|
/* eslint-disable no-param-reassign */
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import {randomBytes} from 'crypto';
|
import { randomBytes } from 'crypto';
|
||||||
import childProcess from 'child_process';
|
import childProcess from 'child_process';
|
||||||
import nodemailer from 'nodemailer';
|
import nodemailer from 'nodemailer';
|
||||||
import {ColorResolvable, DMChannel, Message, MessageEmbed, TextChannel, User} from 'discord.js';
|
import { ColorResolvable, DMChannel, Message, MessageEmbed, TextChannel, User } from 'discord.js';
|
||||||
import {v4 as uuid} from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import hastebin from 'hastebin-gen';
|
import hastebin from 'hastebin-gen';
|
||||||
import {getUserByUid} from '../functions';
|
import { getUserByUid } from '../functions';
|
||||||
import {AccountUtil, Client, Command, PaginationEmbed} from '.';
|
import { AccountUtil, Client, Command, PaginationEmbed } from '.';
|
||||||
import {AccountInterface, ModerationInterface} from '../models';
|
import { AccountInterface, ModerationInterface } from '../models';
|
||||||
import {Certificate} from '../../types/x509';
|
import { Certificate } from '../../types/x509';
|
||||||
|
|
||||||
|
enum TechnicianNameFormatOpt {
|
||||||
|
Full = 0,
|
||||||
|
Partial,
|
||||||
|
Basic
|
||||||
|
}
|
||||||
|
|
||||||
export default class Util {
|
export default class Util {
|
||||||
public client: Client;
|
public client: Client;
|
||||||
|
@ -309,13 +315,18 @@ export default class Util {
|
||||||
return Promise.resolve(log);
|
return Promise.resolve(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getTechnicianFullName(tech: User) {
|
public async getTechnicianName(tech: User, format: TechnicianNameFormatOpt = TechnicianNameFormatOpt.Full) {
|
||||||
if (!tech) throw new Error('\'tech\' is undefined.');
|
if (!tech) return 'SYSTEM (U)';
|
||||||
if (tech.id === this.client.user.id) return 'SYSTEM';
|
if (tech.id === this.client.user.id) return 'SYSTEM (S)';
|
||||||
|
|
||||||
const req = await axios.get('https://loc.sh/int/directory');
|
const req = await axios.get('https://loc.sh/int/directory');
|
||||||
const find = req.data.find((mem) => mem.userID === tech.id);
|
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) {
|
public parseCertificate(pem: string) {
|
||||||
|
|
|
@ -84,7 +84,7 @@ export default class CWG_Create extends Command {
|
||||||
.setTitle('Domain Creation')
|
.setTitle('Domain Creation')
|
||||||
.setColor(3066993)
|
.setColor(3066993)
|
||||||
.addField('Account Username', `${account.username} | <@${account.userID}>`, true)
|
.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('Domain', domain.domain, true)
|
||||||
.addField('Port', String(domain.port), true);
|
.addField('Port', String(domain.port), true);
|
||||||
|
|
||||||
|
|
|
@ -1,61 +1,61 @@
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { Message, MessageEmbed, TextChannel } from 'discord.js';
|
import { Message, MessageEmbed, TextChannel } from 'discord.js';
|
||||||
import { Client, Command } from '../class';
|
import { Client, Command } from '../class';
|
||||||
|
|
||||||
export default class CWG_Delete extends Command {
|
export default class CWG_Delete extends Command {
|
||||||
constructor(client: Client) {
|
constructor(client: Client) {
|
||||||
super(client);
|
super(client);
|
||||||
this.name = 'delete';
|
this.name = 'delete';
|
||||||
this.description = 'Unbind a domain from the CWG';
|
this.description = 'Unbind a domain from the CWG';
|
||||||
this.usage = `${this.client.config.prefix}cwg delete [Domain | Port]`;
|
this.usage = `${this.client.config.prefix}cwg delete [Domain | Port]`;
|
||||||
this.permissions = { roles: ['662163685439045632', '701454780828221450'] };
|
this.permissions = { roles: ['662163685439045632', '701454780828221450'] };
|
||||||
this.aliases = ['unbind'];
|
this.aliases = ['unbind'];
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async run(message: Message, args: string[]) {
|
public async run(message: Message, args: string[]) {
|
||||||
try {
|
try {
|
||||||
if (!args[0]) return this.client.commands.get('help').run(message, ['cwg', this.name]);
|
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 }] });
|
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.');
|
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 edit = await this.loading(message.channel, 'Deleting domain...');
|
||||||
const embed = new MessageEmbed();
|
const embed = new MessageEmbed();
|
||||||
embed.setTitle('Domain Deletion');
|
embed.setTitle('Domain Deletion');
|
||||||
embed.addField('Account Username', `${domain.account.username} | <@${domain.account.userID}>`, true);
|
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('Domain', domain.domain, true);
|
||||||
embed.addField('Port', String(domain.port), true);
|
embed.addField('Port', String(domain.port), true);
|
||||||
embed.setFooter(this.client.user.username, this.client.user.avatarURL());
|
embed.setFooter(this.client.user.username, this.client.user.avatarURL());
|
||||||
embed.setTimestamp();
|
embed.setTimestamp();
|
||||||
if (domain.domain.includes('cloud.libraryofcode.org')) {
|
if (domain.domain.includes('cloud.libraryofcode.org')) {
|
||||||
const resultID = await axios({
|
const resultID = await axios({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
url: `https://api.cloudflare.com/client/v4/zones/5e82fc3111ed4fbf9f58caa34f7553a7/dns_records?name=${domain.domain}`,
|
url: `https://api.cloudflare.com/client/v4/zones/5e82fc3111ed4fbf9f58caa34f7553a7/dns_records?name=${domain.domain}`,
|
||||||
headers: { Authorization: `Bearer ${this.client.config.cloudflare}` },
|
headers: { Authorization: `Bearer ${this.client.config.cloudflare}` },
|
||||||
});
|
});
|
||||||
this.client.signale.debug(resultID.data);
|
this.client.signale.debug(resultID.data);
|
||||||
if (resultID.data.result[0]) {
|
if (resultID.data.result[0]) {
|
||||||
const recordID = resultID.data.result[0].id;
|
const recordID = resultID.data.result[0].id;
|
||||||
await axios({
|
await axios({
|
||||||
method: 'delete',
|
method: 'delete',
|
||||||
url: `https://api.cloudflare.com/client/v4/zones/5e82fc3111ed4fbf9f58caa34f7553a7/dns_records/${recordID}`,
|
url: `https://api.cloudflare.com/client/v4/zones/5e82fc3111ed4fbf9f58caa34f7553a7/dns_records/${recordID}`,
|
||||||
headers: { Authorization: `Bearer ${this.client.config.cloudflare}` },
|
headers: { Authorization: `Bearer ${this.client.config.cloudflare}` },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await fs.unlink(`/etc/nginx/sites-enabled/${domain.domain}`);
|
await fs.unlink(`/etc/nginx/sites-enabled/${domain.domain}`);
|
||||||
await fs.unlink(`/etc/nginx/sites-available/${domain.domain}`);
|
await fs.unlink(`/etc/nginx/sites-available/${domain.domain}`);
|
||||||
} catch (e) { this.client.signale.error(e); }
|
} catch (e) { this.client.signale.error(e); }
|
||||||
await this.client.db.Domain.deleteOne({ domain: domain.domain });
|
await this.client.db.Domain.deleteOne({ domain: domain.domain });
|
||||||
await this.client.util.exec('systemctl reload nginx');
|
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.***`);
|
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;
|
const ch = this.client.channels.cache.get('580950455581147146') as TextChannel;
|
||||||
ch.send({ embeds: [embed] });
|
ch.send({ embeds: [embed] });
|
||||||
return this.client.users.fetch(domain.account.userID).then((u) => u.send({ embeds: [embed] })).catch(() => {});
|
return this.client.users.fetch(domain.account.userID).then((u) => u.send({ embeds: [embed] })).catch(() => {});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return this.client.util.handleError(error, message, this);
|
return this.client.util.handleError(error, message, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ export default class Tier extends Command {
|
||||||
embed.setTitle('Cloud Account | Tier Change');
|
embed.setTitle('Cloud Account | Tier Change');
|
||||||
embed.setColor('#0099ff');
|
embed.setColor('#0099ff');
|
||||||
embed.addField('User', `${account.username} | <@${account.userID}>`, true);
|
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.addField('Old Tier -> New Tier', `${account.tier} -> ${args[1]}`, true);
|
||||||
embed.setFooter(this.client.user.username, this.client.user.avatarURL());
|
embed.setFooter(this.client.user.username, this.client.user.avatarURL());
|
||||||
embed.setTimestamp();
|
embed.setTimestamp();
|
||||||
|
|
|
@ -46,7 +46,7 @@ export default class Whois extends Command {
|
||||||
if (account.locked) details += '__This account is currently locked.__\n';
|
if (account.locked) details += '__This account is currently locked.__\n';
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case account.permissions.director:
|
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');
|
role = await message.member.guild.roles.fetch('662163685439045632');
|
||||||
break;
|
break;
|
||||||
case account.permissions.technician:
|
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);
|
role = await message.member.guild.roles.fetch(message.member.guild.id);
|
||||||
break;
|
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);
|
embed.setColor(role.color || 0x36393f);
|
||||||
if (details) embed.addField('Additional Details', details, true);
|
if (details) embed.addField('Additional Details', details, true);
|
||||||
|
|
||||||
|
@ -84,14 +84,13 @@ export default class Whois extends Command {
|
||||||
|
|
||||||
embed.setDescription(`${finger}\n${chage}`);
|
embed.setDescription(`${finger}\n${chage}`);
|
||||||
embed.addField('Username', `${account.username} | <@${account.userID}>`, true);
|
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('Email Address', account.emailAddress, true);
|
||||||
embed.addField('Tier', String(account.tier), true);
|
embed.addField('Tier', String(account.tier), true);
|
||||||
embed.addField('Support Key', account.supportKey, true);
|
embed.addField('Support Key', account.supportKey, true);
|
||||||
embed.addField('Referral Code & Total', `${account.referralCode} | ${account.totalReferrals}`, true);
|
embed.addField('Referral Code & Total', `${account.referralCode} | ${account.totalReferrals}`, true);
|
||||||
embed.addField('Created By', await this.client.users.fetch(account.createdBy)
|
embed.addField('Created By', await this.client.util.getTechnicianName(await this.client.users.fetch(account.createdBy)), true);
|
||||||
? (await this.client.users.fetch(account.createdBy)).toString()
|
|
||||||
: 'SYSTEM', true);
|
|
||||||
embed.addField('Created At', moment(account.createdAt).format('dddd, MMMM Do YYYY, h:mm:ss A'), 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('CPU Usage', `${cpuUsage.split('\n')[0] || '0'}%`, true);
|
||||||
embed.addField('Memory', dataConversion(Number(memory) * 1000), 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('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('Tier', String(account.tier), true);
|
||||||
embed.addField('Created By', await this.client.users.fetch(account.createdBy)
|
embed.addField('Created By', await this.client.util.getTechnicianName(await this.client.users.fetch(account.createdBy), 2), true);
|
||||||
? (await this.client.users.fetch(account.createdBy)).toString()
|
|
||||||
: 'SYSTEM', true);
|
|
||||||
embed.addField('Created At', moment(account.createdAt).format('dddd, MMMM Do YYYY, h:mm:ss A'), 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('CPU Usage', `${cpuUsage.split('\n')[0] || '0'}%`, true);
|
||||||
embed.addField('Memory', dataConversion(Number(memory) * 1000), true);
|
embed.addField('Memory', dataConversion(Number(memory) * 1000), true);
|
||||||
|
|
Loading…
Reference in New Issue