forked from engineering/crv2
update all files
parent
599159c6ea
commit
bc10712329
|
@ -1,42 +1,46 @@
|
||||||
import { prop, getModelForClass, Ref } from "@typegoose/typegoose"
|
import { prop, getModelForClass, Ref } from "@typegoose/typegoose";
|
||||||
import Member, { MemberAdditionalAcknowledgement, MemberUsedLanguages, MemberUsedOperatingSystems } from "./Member";
|
import Member, {
|
||||||
|
MemberAdditionalAcknowledgement,
|
||||||
|
MemberUsedLanguages,
|
||||||
|
MemberUsedOperatingSystems,
|
||||||
|
} from "./Member";
|
||||||
|
|
||||||
export enum GenerationMethod {
|
export enum GenerationMethod {
|
||||||
TIMER_INTERNAL, // generated by the internal cron-job timer automatically
|
TIMER_INTERNAL, // generated by the internal cron-job timer automatically
|
||||||
INQUIRY_INTERNAL, // internal inquiry generated internally directly through the system. user checks their own inquiry, hard inquiry is performed by a staff member, etc.
|
INQUIRY_INTERNAL, // internal inquiry generated internally directly through the system. user checks their own inquiry, hard inquiry is performed by a staff member, etc.
|
||||||
INQUIRY_EXTERNAL, // external inquiry generated externally through the system via an external authorized request, such as via EDS
|
INQUIRY_EXTERNAL, // external inquiry generated externally through the system via an external authorized request, such as via EDS
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AddtlScoreData {
|
export interface AddtlScoreData {
|
||||||
activity: number;
|
activity: number;
|
||||||
roles: number;
|
roles: number;
|
||||||
moderation: number;
|
moderation: number;
|
||||||
cloudServices: number;
|
cloudServices: number;
|
||||||
misc: number;
|
misc: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO
|
/* TODO
|
||||||
* Comments
|
* Comments
|
||||||
* Further attributes for class
|
* Further attributes for class
|
||||||
* */
|
* */
|
||||||
|
|
||||||
export default class CommunityReport {
|
export default class CommunityReport {
|
||||||
@prop({ required: true, index: true, ref: () => Member })
|
@prop({ required: true, index: true, ref: () => Member })
|
||||||
// the member on which this report was generated for
|
// the member on which this report was generated for
|
||||||
public member: Ref<Member> | undefined;
|
public member: Ref<Member> | undefined;
|
||||||
|
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
// the date in which this report was generated on
|
// the date in which this report was generated on
|
||||||
public date: Date | undefined;
|
public date: Date | undefined;
|
||||||
|
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
// the CommScore of the member specified
|
// the CommScore of the member specified
|
||||||
public score: number | undefined;
|
public score: number | undefined;
|
||||||
|
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
// the method in which this report was generated under
|
// the method in which this report was generated under
|
||||||
public generationMethod: GenerationMethod | undefined;
|
public generationMethod: GenerationMethod | undefined;
|
||||||
|
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
public additionalScoreData: AddtlScoreData | undefined;
|
public additionalScoreData: AddtlScoreData | undefined;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { prop, getModelForClass, Ref } from "@typegoose/typegoose"
|
import { prop, getModelForClass, Ref } from "@typegoose/typegoose";
|
||||||
import Inquiry from "./Inquiry";
|
import Inquiry from "./Inquiry";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,6 +6,6 @@ import Inquiry from "./Inquiry";
|
||||||
* Structure is performed this way to have two separate collections for Hard and Soft inquiries.
|
* Structure is performed this way to have two separate collections for Hard and Soft inquiries.
|
||||||
*/
|
*/
|
||||||
export default class HardInquiry extends Inquiry {
|
export default class HardInquiry extends Inquiry {
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
public reason: string | undefined;
|
public reason: string | undefined;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { prop, getModelForClass, Ref } from "@typegoose/typegoose"
|
import { prop, getModelForClass, Ref } from "@typegoose/typegoose";
|
||||||
import Member from "./Member";
|
import Member from "./Member";
|
||||||
import CommunityReport from "./CommunityReport"
|
import CommunityReport from "./CommunityReport";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO:
|
* TODO:
|
||||||
|
@ -9,29 +9,28 @@ import CommunityReport from "./CommunityReport"
|
||||||
* - Reason
|
* - Reason
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
export default abstract class Inquiry {
|
export default abstract class Inquiry {
|
||||||
@prop({ required: true, unique: true })
|
@prop({ required: true, unique: true })
|
||||||
// the Inquiry Identifier (previously known as `iid`). this is an UUIDv4 string
|
// the Inquiry Identifier (previously known as `iid`). this is an UUIDv4 string
|
||||||
public id: string | undefined;
|
public id: string | undefined;
|
||||||
|
|
||||||
@prop({ required: true, index: true, ref: () => Member })
|
@prop({ required: true, index: true, ref: () => Member })
|
||||||
// the member on which this inquiry was performed on
|
// the member on which this inquiry was performed on
|
||||||
public member: Ref<Member> | undefined;
|
public member: Ref<Member> | undefined;
|
||||||
|
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
// the date in which this inquiry was performed
|
// the date in which this inquiry was performed
|
||||||
public date: Date | undefined;
|
public date: Date | undefined;
|
||||||
|
|
||||||
@prop({ required: true, ref: () => Member })
|
@prop({ required: true, ref: () => Member })
|
||||||
// the reference to the member who initiated this inquiry or a string value representing the name of a system that initiated the inquiry
|
// the reference to the member who initiated this inquiry or a string value representing the name of a system that initiated the inquiry
|
||||||
public initiatedBy: Ref<Member> | string | undefined;
|
public initiatedBy: Ref<Member> | string | undefined;
|
||||||
|
|
||||||
@prop({ required: true, ref: () => CommunityReport })
|
@prop({ required: true, ref: () => CommunityReport })
|
||||||
// the report that was generated or fetched from this inquiry as of current date
|
// the report that was generated or fetched from this inquiry as of current date
|
||||||
public report: Ref<CommunityReport> | undefined;
|
public report: Ref<CommunityReport> | undefined;
|
||||||
|
|
||||||
@prop()
|
@prop()
|
||||||
// a reason for the inquiry, if applicable. this value is required for HardInquiry
|
// a reason for the inquiry, if applicable. this value is required for HardInquiry
|
||||||
public reason: string | "N/A" | undefined;
|
public reason: string | "N/A" | undefined;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,88 +1,87 @@
|
||||||
import { prop, getModelForClass } from "@typegoose/typegoose"
|
import { prop, getModelForClass } from "@typegoose/typegoose";
|
||||||
|
|
||||||
/* TODO
|
/* TODO
|
||||||
* Comments
|
* Comments
|
||||||
* Further attributes for class
|
* Further attributes for class
|
||||||
* */
|
* */
|
||||||
|
|
||||||
export interface SharedMemberAttributes {
|
export interface SharedMemberAttributes {
|
||||||
discordID: string | undefined;
|
discordID: string | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MemberAdditionalAcknowledgement =
|
export type MemberAdditionalAcknowledgement =
|
||||||
"Chair of the Board of Governors" |
|
| "Chair of the Board of Governors"
|
||||||
"Vice Chair of the Board of Governors" |
|
| "Vice Chair of the Board of Governors"
|
||||||
"Voting Seat Member of the Board of Governors" |
|
| "Voting Seat Member of the Board of Governors"
|
||||||
string;
|
| string;
|
||||||
|
|
||||||
export const MemberGuildRoleIDMap = {
|
export const MemberGuildRoleIDMap = {
|
||||||
// Chair/Vice Chair of the Board of Governors
|
// Chair/Vice Chair of the Board of Governors
|
||||||
CHAIR_OR_VICE_OF_BOARD: "608394038466445320",
|
CHAIR_OR_VICE_OF_BOARD: "608394038466445320",
|
||||||
// Management
|
// Management
|
||||||
MANAGEMENT: "1077646568091570236",
|
MANAGEMENT: "1077646568091570236",
|
||||||
// Director of Operations
|
// Director of Operations
|
||||||
DIRECTOR_OF_OPERATIONS: "1077647072163020840",
|
DIRECTOR_OF_OPERATIONS: "1077647072163020840",
|
||||||
// Director of Engineering
|
// Director of Engineering
|
||||||
DIRECTOR_OF_ENGINEERING: "1077646956890951690",
|
DIRECTOR_OF_ENGINEERING: "1077646956890951690",
|
||||||
// Board of Governors
|
// Board of Governors
|
||||||
BOARD_OF_GOVERNORS: "662163685439045632",
|
BOARD_OF_GOVERNORS: "662163685439045632",
|
||||||
// Project Manager
|
// Project Manager
|
||||||
PROJECT_MANAGER: "1077647157928132711",
|
PROJECT_MANAGER: "1077647157928132711",
|
||||||
// Services Manager
|
// Services Manager
|
||||||
SERVICES_MANAGER: "1077647467056742482",
|
SERVICES_MANAGER: "1077647467056742482",
|
||||||
// Staff
|
// Staff
|
||||||
STAFF: "446104438969466890",
|
STAFF: "446104438969466890",
|
||||||
// Technician
|
// Technician
|
||||||
TECHNICIAN: "701454780828221450",
|
TECHNICIAN: "701454780828221450",
|
||||||
// Moderator
|
// Moderator
|
||||||
MODERATOR: "455972169449734144",
|
MODERATOR: "455972169449734144",
|
||||||
// Core Team
|
// Core Team
|
||||||
CORE_TEAM: "453689940140883988",
|
CORE_TEAM: "453689940140883988",
|
||||||
// Intern (Training)
|
// Intern (Training)
|
||||||
INTERN: "701481967149121627",
|
INTERN: "701481967149121627",
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
||||||
// enum for the used programming languages in whois information
|
// enum for the used programming languages in whois information
|
||||||
export enum MemberUsedLanguages {
|
export enum MemberUsedLanguages {
|
||||||
ASM = "lang-asm",
|
ASM = "lang-asm",
|
||||||
CFAM = "lang-cfam",
|
CFAM = "lang-cfam",
|
||||||
CSHARP = "lang-csharp",
|
CSHARP = "lang-csharp",
|
||||||
GO = "lang-go",
|
GO = "lang-go",
|
||||||
JAVA = "lang-java",
|
JAVA = "lang-java",
|
||||||
JS = "lang-js",
|
JS = "lang-js",
|
||||||
KT = "lang-kt",
|
KT = "lang-kt",
|
||||||
PY = "lang-py",
|
PY = "lang-py",
|
||||||
RB = "lang-rb",
|
RB = "lang-rb",
|
||||||
RS = "lang-rs",
|
RS = "lang-rs",
|
||||||
SWIFT = "lang-swift",
|
SWIFT = "lang-swift",
|
||||||
TS = "lang-ts"
|
TS = "lang-ts",
|
||||||
}
|
}
|
||||||
|
|
||||||
// enum for the used operating systems in the whois information
|
// enum for the used operating systems in the whois information
|
||||||
export enum MemberUsedOperatingSystems {
|
export enum MemberUsedOperatingSystems {
|
||||||
ARCH = "os-arch",
|
ARCH = "os-arch",
|
||||||
DEB = "os-deb",
|
DEB = "os-deb",
|
||||||
CENT = "os-cent",
|
CENT = "os-cent",
|
||||||
FEDORA = "os-fedora",
|
FEDORA = "os-fedora",
|
||||||
MDARWIN = "os-mdarwin",
|
MDARWIN = "os-mdarwin",
|
||||||
MANJARO = "os-manjaro",
|
MANJARO = "os-manjaro",
|
||||||
REDHAT = "os-redhat",
|
REDHAT = "os-redhat",
|
||||||
UBUNTU = "os-ubuntu",
|
UBUNTU = "os-ubuntu",
|
||||||
WIN = "os-win"
|
WIN = "os-win",
|
||||||
}
|
}
|
||||||
export default class Member implements SharedMemberAttributes {
|
export default class Member implements SharedMemberAttributes {
|
||||||
@prop({ required: true, unique: true })
|
@prop({ required: true, unique: true })
|
||||||
public discordID: string | undefined;
|
public discordID: string | undefined;
|
||||||
|
|
||||||
@prop()
|
@prop()
|
||||||
public usedOperatingSystems: MemberUsedOperatingSystems[] | undefined;
|
public usedOperatingSystems: MemberUsedOperatingSystems[] | undefined;
|
||||||
|
|
||||||
@prop()
|
@prop()
|
||||||
public usedLanguages: MemberUsedLanguages[] | undefined;
|
public usedLanguages: MemberUsedLanguages[] | undefined;
|
||||||
|
|
||||||
@prop()
|
@prop()
|
||||||
public additionalAcknowledgement: MemberAdditionalAcknowledgement[] | undefined;
|
public additionalAcknowledgement: MemberAdditionalAcknowledgement[] | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MemberModel = getModelForClass(Member);
|
export const MemberModel = getModelForClass(Member);
|
||||||
|
|
|
@ -2,72 +2,71 @@ import { prop, getModelForClass } from "@typegoose/typegoose";
|
||||||
import Member from "./Member";
|
import Member from "./Member";
|
||||||
|
|
||||||
/* TODO
|
/* TODO
|
||||||
* Comments
|
* Comments
|
||||||
* Further attributes for class
|
* Further attributes for class
|
||||||
* */
|
* */
|
||||||
|
|
||||||
import { SharedMemberAttributes } from "./Member";
|
import { SharedMemberAttributes } from "./Member";
|
||||||
|
|
||||||
export type PartnerTitle =
|
export type PartnerTitle =
|
||||||
"Director of Engineering" |
|
| "Director of Engineering"
|
||||||
"Director of Operations" |
|
| "Director of Operations"
|
||||||
"Deputy Director of Engineering" |
|
| "Deputy Director of Engineering"
|
||||||
"Deputy Director of Operations" |
|
| "Deputy Director of Operations"
|
||||||
"Services Manager" |
|
| "Services Manager"
|
||||||
"Project Manager" |
|
| "Project Manager"
|
||||||
"Engineering Core Partner" |
|
| "Engineering Core Partner"
|
||||||
"Operations Core Partner" |
|
| "Operations Core Partner"
|
||||||
"Community Moderator" |
|
| "Community Moderator"
|
||||||
"Technician" |
|
| "Technician"
|
||||||
string;
|
| string;
|
||||||
|
|
||||||
|
|
||||||
export enum PartnerDepartment {
|
export enum PartnerDepartment {
|
||||||
INDEPENDENT_AGENCY,
|
INDEPENDENT_AGENCY,
|
||||||
ENGINEERING, // Department of Engineering
|
ENGINEERING, // Department of Engineering
|
||||||
OPERATIONS // Department of Operations
|
OPERATIONS, // Department of Operations
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum PartnerRoleType {
|
export enum PartnerRoleType {
|
||||||
MANAGERIAL,
|
MANAGERIAL,
|
||||||
NONMANAGERIAL,
|
NONMANAGERIAL,
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum PartnerCommissionType {
|
export enum PartnerCommissionType {
|
||||||
TENURE,
|
TENURE,
|
||||||
PROVISIONAL,
|
PROVISIONAL,
|
||||||
CONTRACTUAL,
|
CONTRACTUAL,
|
||||||
ACTING,
|
ACTING,
|
||||||
INTERIM,
|
INTERIM,
|
||||||
TRIAL,
|
TRIAL,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Partner implements SharedMemberAttributes {
|
export default class Partner implements SharedMemberAttributes {
|
||||||
@prop({ required: true, unique: true })
|
@prop({ required: true, unique: true })
|
||||||
public discordID: string | undefined;
|
public discordID: string | undefined;
|
||||||
|
|
||||||
@prop()
|
@prop()
|
||||||
public emailAddress: string | undefined;
|
public emailAddress: string | undefined;
|
||||||
|
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
public roleType: PartnerRoleType | undefined;
|
public roleType: PartnerRoleType | undefined;
|
||||||
|
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
public commissionType: PartnerCommissionType | undefined;
|
public commissionType: PartnerCommissionType | undefined;
|
||||||
|
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
public department: PartnerDepartment | undefined;
|
public department: PartnerDepartment | undefined;
|
||||||
|
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
public title: PartnerTitle | "Partner" | undefined;
|
public title: PartnerTitle | "Partner" | undefined;
|
||||||
|
|
||||||
@prop()
|
@prop()
|
||||||
//
|
//
|
||||||
public directReport: Partner | string | undefined;
|
public directReport: Partner | string | undefined;
|
||||||
|
|
||||||
@prop()
|
@prop()
|
||||||
// this field dictates if the partner is able to perform developer commands, such as "eval"
|
// this field dictates if the partner is able to perform developer commands, such as "eval"
|
||||||
public canPerformDevCommands: boolean | undefined;
|
public canPerformDevCommands: boolean | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PartnerModel = getModelForClass(Partner);
|
export const PartnerModel = getModelForClass(Partner);
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
import { prop } from '@typegoose/typegoose';
|
import { prop } from "@typegoose/typegoose";
|
||||||
|
|
||||||
// This class represents a Vendor, which ia an entity that is permitted to access CommunityReport information, and may be permitted to manipulate data, through the HTtP API.
|
// This class represents a Vendor, which ia an entity that is permitted to access CommunityReport information, and may be permitted to manipulate data, through the HTtP API.
|
||||||
export default class Vendor {
|
export default class Vendor {
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
public name: string | undefined;
|
public name: string | undefined;
|
||||||
|
|
||||||
@prop({ required: true, unique: true })
|
@prop({ required: true, unique: true })
|
||||||
// the uuidv4 string identifier of the vendor; this functions as the identifier and api key for the vendor
|
// the uuidv4 string identifier of the vendor; this functions as the identifier and api key for the vendor
|
||||||
public key: string | undefined;
|
public key: string | undefined;
|
||||||
|
|
||||||
@prop({ default: false })
|
@prop({ default: false })
|
||||||
// determines if this vendor can perform a Hard Inquiry and receive additional privileged information
|
// determines if this vendor can perform a Hard Inquiry and receive additional privileged information
|
||||||
public privileged: boolean | undefined;
|
public privileged: boolean | undefined;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,64 +4,74 @@ import { inspect } from "util";
|
||||||
import { discordBotToken } from "../../config.json";
|
import { discordBotToken } from "../../config.json";
|
||||||
|
|
||||||
export default class Eval extends DiscordInteractionCommand {
|
export default class Eval extends DiscordInteractionCommand {
|
||||||
// This is a list of IDs that are allowed to use this command.
|
// This is a list of IDs that are allowed to use this command.
|
||||||
private listOfAllowedIDs: string[];
|
private listOfAllowedIDs: string[];
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super("eval", "Executes arbitrary JS code and returns the output.");
|
super("eval", "Executes arbitrary JS code and returns the output.");
|
||||||
// this option is required and is a string of JavaScript code to execute
|
// this option is required and is a string of JavaScript code to execute
|
||||||
this.builder.addStringOption(option => option.setName("code").setDescription("The code to execute.").setRequired(true));
|
this.builder.addStringOption((option) =>
|
||||||
// this option is optional and is a boolean that determines whether the code should be run as an async function
|
option.setName("code").setDescription("The code to execute.").setRequired(true)
|
||||||
this.builder.addBooleanOption(option => option.setName("async").setDescription("Whether to run the code as an async function.").setRequired(false));
|
);
|
||||||
// this option is optional and is an integer that determines the depth of the eval inspection
|
// this option is optional and is a boolean that determines whether the code should be run as an async function
|
||||||
this.builder.addIntegerOption(option => option.setName("depth").setDescription("The depth of the inspection.").setRequired(false));
|
this.builder.addBooleanOption((option) =>
|
||||||
|
option
|
||||||
|
.setName("async")
|
||||||
|
.setDescription("Whether to run the code as an async function.")
|
||||||
|
.setRequired(false)
|
||||||
|
);
|
||||||
|
// this option is optional and is an integer that determines the depth of the eval inspection
|
||||||
|
this.builder.addIntegerOption((option) =>
|
||||||
|
option.setName("depth").setDescription("The depth of the inspection.").setRequired(false)
|
||||||
|
);
|
||||||
|
|
||||||
this.listOfAllowedIDs = [
|
this.listOfAllowedIDs = [
|
||||||
"278620217221971968", // Matthew
|
"278620217221971968", // Matthew
|
||||||
];
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public async execute(interaction: ChatInputCommandInteraction) {
|
||||||
|
// @ts-ignore
|
||||||
|
let evalString = interaction.options.getString("code").trim();
|
||||||
|
if (evalString == null)
|
||||||
|
return interaction.reply({ content: "You must provide code to evaluate.", ephemeral: true });
|
||||||
|
if (!this.listOfAllowedIDs.includes(interaction.user.id))
|
||||||
|
return interaction.reply({ content: "Permission denied.", ephemeral: true });
|
||||||
|
await interaction.deferReply({ ephemeral: true });
|
||||||
|
|
||||||
|
// set scoped variables to be able to access over eval
|
||||||
|
const guild = interaction.guild || interaction.client.guilds.cache.get(this.GUILD_ID);
|
||||||
|
// the output of eval() is stored in evaled
|
||||||
|
let evaled: any;
|
||||||
|
let depth: number | null = 0;
|
||||||
|
// if depth option exists, set the depth variable to the value provided by the user
|
||||||
|
if (interaction.options.getInteger("depth") != null) {
|
||||||
|
depth = interaction.options.getInteger("depth");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async execute(interaction: ChatInputCommandInteraction) {
|
// if command specified as async, swap the evalString in an async function
|
||||||
// @ts-ignore
|
if (interaction.options.getBoolean("async")) {
|
||||||
let evalString = interaction.options.getString("code").trim();
|
evalString = `(async () => { ${evalString} })()`;
|
||||||
if (evalString == null) return interaction.reply({ content: "You must provide code to evaluate.", ephemeral: true });
|
}
|
||||||
if (!this.listOfAllowedIDs.includes(interaction.user.id)) return interaction.reply({ content: "Permission denied.", ephemeral: true });
|
|
||||||
await interaction.deferReply({ephemeral: true});
|
|
||||||
|
|
||||||
// set scoped variables to be able to access over eval
|
try {
|
||||||
const guild = interaction.guild || interaction.client.guilds.cache.get(this.GUILD_ID);
|
evaled = await eval(evalString);
|
||||||
// the output of eval() is stored in evaled
|
if (typeof evaled !== "string") {
|
||||||
let evaled: any;
|
evaled = inspect(evaled, { depth });
|
||||||
let depth: number | null = 0;
|
}
|
||||||
// if depth option exists, set the depth variable to the value provided by the user
|
if (evaled === undefined) {
|
||||||
if (interaction.options.getInteger("depth") != null) {
|
evaled = "undefined";
|
||||||
depth = interaction.options.getInteger("depth");
|
}
|
||||||
}
|
} catch (error) {
|
||||||
|
// @ts-ignore
|
||||||
|
evaled = error.stack;
|
||||||
|
}
|
||||||
|
|
||||||
// if command specified as async, swap the evalString in an async function
|
// replaces all instances of the bot token with [REDACTED] in output
|
||||||
if (interaction.options.getBoolean("async")) {
|
evaled = evaled.replace(new RegExp(discordBotToken, "gi"), "[REDACTED]");
|
||||||
evalString = `(async () => { ${evalString} })()`;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
// TODO: Figure this out.
|
||||||
// eslint-disable-next-line no-eval
|
/*const display = this.client.util.splitString(evaled, 1975);
|
||||||
evaled = await eval(evalString);
|
|
||||||
if (typeof evaled !== 'string') {
|
|
||||||
evaled = inspect(evaled, { depth });
|
|
||||||
}
|
|
||||||
if (evaled === undefined) {
|
|
||||||
evaled = 'undefined';
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
// @ts-ignore
|
|
||||||
evaled = error.stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
// replaces all instances of the bot token with [REDACTED] in output
|
|
||||||
evaled = evaled.replace(new RegExp(discordBotToken, 'gi'), '[REDACTED]');
|
|
||||||
|
|
||||||
// TODO: Figure this out.
|
|
||||||
/*const display = this.client.util.splitString(evaled, 1975);
|
|
||||||
if (display[5]) {
|
if (display[5]) {
|
||||||
try {
|
try {
|
||||||
const { data } = await axios.post('https://snippets.cloud.libraryofcode.org/documents', display.join(''));
|
const { data } = await axios.post('https://snippets.cloud.libraryofcode.org/documents', display.join(''));
|
||||||
|
@ -70,6 +80,6 @@ export default class Eval extends DiscordInteractionCommand {
|
||||||
return this.error(ctx.message.channel, `${error}`);
|
return this.error(ctx.message.channel, `${error}`);
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
await interaction.editReply({content: `\`\`\`js\n${evaled}\n\`\`\``})
|
await interaction.editReply({ content: `\`\`\`js\n${evaled}\n\`\`\`` });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,12 @@ import DiscordInteractionCommand from "../../util/DiscordInteractionCommand";
|
||||||
import { ChatInputCommandInteraction } from "discord.js";
|
import { ChatInputCommandInteraction } from "discord.js";
|
||||||
|
|
||||||
export default class Ping extends DiscordInteractionCommand {
|
export default class Ping extends DiscordInteractionCommand {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("partner", "Manipulates partner information.");
|
super("partner", "Manipulates partner information.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async execute(interaction: ChatInputCommandInteraction): Promise<void> {
|
public async execute(interaction: ChatInputCommandInteraction): Promise<void> {
|
||||||
if (interaction.options?.getSubcommand(true) === "add") {
|
if (interaction.options?.getSubcommand(true) === "add") {
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,34 @@
|
||||||
import DiscordInteractionCommand, { DiscordInteractionCommandSkeleton } from "../../util/DiscordInteractionCommand";
|
import DiscordInteractionCommand, {
|
||||||
|
DiscordInteractionCommandSkeleton,
|
||||||
|
} from "../../util/DiscordInteractionCommand";
|
||||||
import { guildID } from "../../config.json";
|
import { guildID } from "../../config.json";
|
||||||
import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
|
import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
|
||||||
import { MemberModel } from "../../database/Member";
|
import { MemberModel } from "../../database/Member";
|
||||||
import { PartnerModel } from "../../database/Partner";
|
import { PartnerModel } from "../../database/Partner";
|
||||||
|
|
||||||
export default class PartnerAdd implements DiscordInteractionCommandSkeleton {
|
export default class PartnerAdd implements DiscordInteractionCommandSkeleton {
|
||||||
public GUILD_ID: string;
|
public GUILD_ID: string;
|
||||||
public name: string;
|
public name: string;
|
||||||
public description: string
|
public description: string;
|
||||||
public builder: SlashCommandBuilder;
|
public builder: SlashCommandBuilder;
|
||||||
constructor() {
|
constructor() {
|
||||||
this.name = "partner";
|
this.name = "partner";
|
||||||
this.description = "Creates a new partner entry.";
|
this.description = "Creates a new partner entry.";
|
||||||
this.builder = new SlashCommandBuilder();
|
this.builder = new SlashCommandBuilder();
|
||||||
this.GUILD_ID = guildID;
|
this.GUILD_ID = guildID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async execute(interaction: ChatInputCommandInteraction) {
|
public async execute(interaction: ChatInputCommandInteraction) {
|
||||||
const member = MemberModel.findOne({ discordID: interaction.user.id });
|
const member = MemberModel.findOne({ discordID: interaction.user.id });
|
||||||
if (!member) return interaction.reply({ content: "The specified partner does not have a base member entry.", ephemeral: true });
|
if (!member)
|
||||||
if (!(await PartnerModel.findOne({discordID: interaction.user.id}))) return interaction.reply({ content: "The specified partner already has a partner entry.", ephemeral: true });
|
return interaction.reply({
|
||||||
|
content: "The specified partner does not have a base member entry.",
|
||||||
}
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
if (!(await PartnerModel.findOne({ discordID: interaction.user.id })))
|
||||||
|
return interaction.reply({
|
||||||
|
content: "The specified partner already has a partner entry.",
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,20 +2,20 @@ import DiscordInteractionCommand from "../../util/DiscordInteractionCommand";
|
||||||
import { ChatInputCommandInteraction } from "discord.js";
|
import { ChatInputCommandInteraction } from "discord.js";
|
||||||
|
|
||||||
export default class Ping extends DiscordInteractionCommand {
|
export default class Ping extends DiscordInteractionCommand {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("ping", "Pings the bot");
|
super("ping", "Pings the bot");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async execute(interaction: ChatInputCommandInteraction): Promise<void> {
|
public async execute(interaction: ChatInputCommandInteraction): Promise<void> {
|
||||||
const startTimestamp = Date.now(); // Mark the start of processing
|
const startTimestamp = Date.now(); // Mark the start of processing
|
||||||
|
|
||||||
await interaction.reply({ content: "Pong!", ephemeral: false });
|
await interaction.reply({ content: "Pong!", ephemeral: false });
|
||||||
const repliedTimestamp = Date.now(); // Mark the timestamp after replying
|
const repliedTimestamp = Date.now(); // Mark the timestamp after replying
|
||||||
|
|
||||||
const endTimestamp = Date.now(); // Mark the end of all processing (after editReply)
|
const endTimestamp = Date.now(); // Mark the end of all processing (after editReply)
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
content: `🏓 Pong!\nClient: \`${repliedTimestamp - interaction.createdTimestamp}ms\`\nResponse: \`${endTimestamp - startTimestamp}ms\``
|
content: `🏓 Pong!\nClient: \`${repliedTimestamp - interaction.createdTimestamp}ms\`\nResponse: \`${endTimestamp - startTimestamp}ms\``,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,103 +1,117 @@
|
||||||
import DiscordInteractionCommand from "../../util/DiscordInteractionCommand";
|
import DiscordInteractionCommand from "../../util/DiscordInteractionCommand";
|
||||||
import { MemberModel } from "../../database/Member";
|
import { MemberModel } from "../../database/Member";
|
||||||
import Partner, { PartnerCommissionType, PartnerDepartment, PartnerModel, PartnerRoleType } from "../../database/Partner";
|
import Partner, {
|
||||||
|
PartnerCommissionType,
|
||||||
|
PartnerDepartment,
|
||||||
|
PartnerModel,
|
||||||
|
PartnerRoleType,
|
||||||
|
} from "../../database/Partner";
|
||||||
import { ChatInputCommandInteraction, EmbedBuilder, GuildMember } from "discord.js";
|
import { ChatInputCommandInteraction, EmbedBuilder, GuildMember } from "discord.js";
|
||||||
import MemberUtil from "../../util/MemberUtil";
|
import MemberUtil from "../../util/MemberUtil";
|
||||||
import EmojiConfig from "../../util/EmojiConfig"
|
import EmojiConfig from "../../util/EmojiConfig";
|
||||||
|
|
||||||
export default class Whois extends DiscordInteractionCommand {
|
export default class Whois extends DiscordInteractionCommand {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("whois", "Retrieves information about a user.");
|
super("whois", "Retrieves information about a user.");
|
||||||
this.builder.addUserOption(option => option.setName("member").setDescription("The member to get information about.").setRequired(true));
|
this.builder.addUserOption((option) =>
|
||||||
}
|
option
|
||||||
|
.setName("member")
|
||||||
|
.setDescription("The member to get information about.")
|
||||||
|
.setRequired(true)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public async execute(interaction: ChatInputCommandInteraction) {
|
public async execute(interaction: ChatInputCommandInteraction) {
|
||||||
// defer our reply and perform database/external API operations/lookups
|
// defer our reply and perform database/external API operations/lookups
|
||||||
await interaction.deferReply({ ephemeral: false });
|
await interaction.deferReply({ ephemeral: false });
|
||||||
const target = interaction.options.getUser("member", true);
|
const target = interaction.options.getUser("member", true);
|
||||||
const guild = interaction.guild || interaction.client.guilds.cache.get(this.GUILD_ID);
|
const guild = interaction.guild || interaction.client.guilds.cache.get(this.GUILD_ID);
|
||||||
const guildMember = await guild?.members.fetch(target.id);
|
const guildMember = await guild?.members.fetch(target.id);
|
||||||
const databaseMember = await MemberModel.findOne({ discordID: target.id });
|
const databaseMember = await MemberModel.findOne({ discordID: target.id });
|
||||||
const partner = await PartnerModel.findOne({ discordID: target.id });
|
const partner = await PartnerModel.findOne({ discordID: target.id });
|
||||||
// return an error if target was not located
|
// return an error if target was not located
|
||||||
if (!guildMember) return interaction.editReply({ content: `Member target ${target.id} was not located.`});
|
if (!guildMember)
|
||||||
// build our embed
|
return interaction.editReply({ content: `Member target ${target.id} was not located.` });
|
||||||
const embed = new EmbedBuilder();
|
// build our embed
|
||||||
// if the role type is managerial, add a [k] to the end of the name
|
const embed = new EmbedBuilder();
|
||||||
// if the partner exists, set the iconURL to the organizational logo
|
// if the role type is managerial, add a [k] to the end of the name
|
||||||
const formattedName = MemberUtil.formatName(guildMember, partner);
|
// if the partner exists, set the iconURL to the organizational logo
|
||||||
embed.setAuthor({ name: formattedName.text, iconURL: formattedName.iconURL });
|
const formattedName = MemberUtil.formatName(guildMember, partner);
|
||||||
// set the thumbnail to the user's avatar
|
embed.setAuthor({ name: formattedName.text, iconURL: formattedName.iconURL });
|
||||||
embed.setThumbnail(guildMember.user.displayAvatarURL());
|
// set the thumbnail to the user's avatar
|
||||||
// initialize the description string
|
embed.setThumbnail(guildMember.user.displayAvatarURL());
|
||||||
let embedDescription = '';
|
// initialize the description string
|
||||||
if (partner) {
|
let embedDescription = "";
|
||||||
// set the title to the partner's title if applicable
|
if (partner) {
|
||||||
if (partner.title) embedDescription += `## __${EmojiConfig.LOC} ${partner.title}__\n`;
|
// set the title to the partner's title if applicable
|
||||||
embedDescription += "### Partner Information\n";
|
if (partner.title) embedDescription += `## __${EmojiConfig.LOC} ${partner.title}__\n`;
|
||||||
if (partner.emailAddress) embedDescription += `**Email Address**: ${partner.emailAddress}\n`;
|
embedDescription += "### Partner Information\n";
|
||||||
switch (partner.department) {
|
if (partner.emailAddress) embedDescription += `**Email Address**: ${partner.emailAddress}\n`;
|
||||||
case PartnerDepartment.ENGINEERING:
|
switch (partner.department) {
|
||||||
embedDescription += "**Department**: Dept. of Engineering\n";
|
case PartnerDepartment.ENGINEERING:
|
||||||
break;
|
embedDescription += "**Department**: Dept. of Engineering\n";
|
||||||
case PartnerDepartment.OPERATIONS:
|
break;
|
||||||
embedDescription += "**Department**: Dept. of Operations\n";
|
case PartnerDepartment.OPERATIONS:
|
||||||
break;
|
embedDescription += "**Department**: Dept. of Operations\n";
|
||||||
case PartnerDepartment.INDEPENDENT_AGENCY:
|
break;
|
||||||
embedDescription += "**Department**: Independent Agency/Contractor\n";
|
case PartnerDepartment.INDEPENDENT_AGENCY:
|
||||||
break;
|
embedDescription += "**Department**: Independent Agency/Contractor\n";
|
||||||
}
|
break;
|
||||||
switch (partner.commissionType) {
|
}
|
||||||
case PartnerCommissionType.TENURE:
|
switch (partner.commissionType) {
|
||||||
embedDescription += "**Commission Type**: Tenure\n";
|
case PartnerCommissionType.TENURE:
|
||||||
break;
|
embedDescription += "**Commission Type**: Tenure\n";
|
||||||
case PartnerCommissionType.PROVISIONAL:
|
break;
|
||||||
embedDescription += "**Commission Type**: Provisional\n";
|
case PartnerCommissionType.PROVISIONAL:
|
||||||
break;
|
embedDescription += "**Commission Type**: Provisional\n";
|
||||||
case PartnerCommissionType.CONTRACTUAL:
|
break;
|
||||||
embedDescription += "**Commission Type**: Contractual/Independent/Collaborator\n";
|
case PartnerCommissionType.CONTRACTUAL:
|
||||||
break;
|
embedDescription += "**Commission Type**: Contractual/Independent/Collaborator\n";
|
||||||
case PartnerCommissionType.ACTING:
|
break;
|
||||||
embedDescription += "**Commission Type**: Acting\n";
|
case PartnerCommissionType.ACTING:
|
||||||
break;
|
embedDescription += "**Commission Type**: Acting\n";
|
||||||
case PartnerCommissionType.INTERIM:
|
break;
|
||||||
embedDescription += "**Commission Type**: Interim\n";
|
case PartnerCommissionType.INTERIM:
|
||||||
break;
|
embedDescription += "**Commission Type**: Interim\n";
|
||||||
case PartnerCommissionType.TRIAL:
|
break;
|
||||||
embedDescription += "**Commission Type**: Trial/Intern\n";
|
case PartnerCommissionType.TRIAL:
|
||||||
break;
|
embedDescription += "**Commission Type**: Trial/Intern\n";
|
||||||
}
|
break;
|
||||||
if (partner.directReport) {
|
}
|
||||||
if (partner.directReport instanceof Partner) {
|
if (partner.directReport) {
|
||||||
embedDescription += `**Direct Report**: ${partner.directReport.title}\n`;
|
if (partner.directReport instanceof Partner) {
|
||||||
}
|
embedDescription += `**Direct Report**: ${partner.directReport.title}\n`;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
embed.setColor(guildMember.displayColor);
|
}
|
||||||
if (embedDescription?.length > 0) embed.setDescription(embedDescription);
|
|
||||||
// add status to embed
|
|
||||||
if (guildMember.presence?.status) { // TODO: this currently doesn't work for some reason
|
|
||||||
switch (guildMember.presence.status) {
|
|
||||||
case "online":
|
|
||||||
embed.addFields({ name: "Status", value: "Online", inline: true });
|
|
||||||
break;
|
|
||||||
case "idle":
|
|
||||||
embed.addFields({ name: "Status", value: "Idle", inline: true });
|
|
||||||
break;
|
|
||||||
case "dnd":
|
|
||||||
embed.addFields({ name: "Status", value: "Do Not Disturb", inline: true });
|
|
||||||
break;
|
|
||||||
case "offline" || "invisible":
|
|
||||||
embed.addFields({ name: "Status", value: "Online", inline: true });
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// TODO: decide what placeholder we should use for values that fall "out of range"
|
|
||||||
embed.addFields({ name: "Status", value: "", inline: true });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
embed.setFooter({ text: `Discord ID: ${guildMember.id}${databaseMember ? `Internal ID: ${databaseMember?._id}` : ''}` });
|
|
||||||
|
|
||||||
return await interaction.editReply({ embeds: [embed] });
|
|
||||||
}
|
}
|
||||||
|
embed.setColor(guildMember.displayColor);
|
||||||
|
if (embedDescription?.length > 0) embed.setDescription(embedDescription);
|
||||||
|
// add status to embed
|
||||||
|
if (guildMember.presence?.status) {
|
||||||
|
// TODO: this currently doesn't work for some reason
|
||||||
|
switch (guildMember.presence.status) {
|
||||||
|
case "online":
|
||||||
|
embed.addFields({ name: "Status", value: "Online", inline: true });
|
||||||
|
break;
|
||||||
|
case "idle":
|
||||||
|
embed.addFields({ name: "Status", value: "Idle", inline: true });
|
||||||
|
break;
|
||||||
|
case "dnd":
|
||||||
|
embed.addFields({ name: "Status", value: "Do Not Disturb", inline: true });
|
||||||
|
break;
|
||||||
|
case "offline" || "invisible":
|
||||||
|
embed.addFields({ name: "Status", value: "Online", inline: true });
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// TODO: decide what placeholder we should use for values that fall "out of range"
|
||||||
|
embed.addFields({ name: "Status", value: "", inline: true });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
embed.setFooter({
|
||||||
|
text: `Discord ID: ${guildMember.id}${databaseMember ? `Internal ID: ${databaseMember?._id}` : ""}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
return await interaction.editReply({ embeds: [embed] });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,24 +3,34 @@ import { DiscordInteractionCommands } from "../../index";
|
||||||
import { Client, Interaction } from "discord.js";
|
import { Client, Interaction } from "discord.js";
|
||||||
|
|
||||||
export default class InteractionCreate extends DiscordEvent {
|
export default class InteractionCreate extends DiscordEvent {
|
||||||
constructor(client: Client) {
|
constructor(client: Client) {
|
||||||
super("interactionCreate", client);
|
super("interactionCreate", client);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async execute(interaction: Interaction): Promise<void> {
|
public async execute(interaction: Interaction): Promise<void> {
|
||||||
if (!interaction.isChatInputCommand()) return;
|
if (!interaction.isChatInputCommand()) return;
|
||||||
const command = DiscordInteractionCommands.get(interaction.commandName);
|
const command = DiscordInteractionCommands.get(interaction.commandName);
|
||||||
if (!command) return console.error(`No command matching ${interaction.commandName} was found.`);
|
if (!command) return console.error(`No command matching ${interaction.commandName} was found.`);
|
||||||
try {
|
try {
|
||||||
await command.execute(interaction);
|
await command.execute(interaction);
|
||||||
console.info(`[Info - Discord] Command '${interaction.commandName}' executed by '${interaction.user.username}'`);
|
console.info(
|
||||||
} catch (error) {
|
`[Info - Discord] Command '${interaction.commandName}' executed by '${interaction.user.username}'`
|
||||||
console.error(`Error executing command '${interaction.commandName}': by '${interaction.user.username}'\n${error}`);
|
);
|
||||||
if (interaction.replied || interaction.deferred) {
|
} catch (error) {
|
||||||
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
|
console.error(
|
||||||
} else {
|
`Error executing command '${interaction.commandName}': by '${interaction.user.username}'\n${error}`
|
||||||
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
|
);
|
||||||
}
|
if (interaction.replied || interaction.deferred) {
|
||||||
}
|
await interaction.followUp({
|
||||||
|
content: "There was an error while executing this command!",
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await interaction.reply({
|
||||||
|
content: "There was an error while executing this command!",
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,153 +2,153 @@
|
||||||
* Hold a bunch of something
|
* Hold a bunch of something
|
||||||
*/
|
*/
|
||||||
export default class Collection<V> extends Map<string, V> {
|
export default class Collection<V> extends Map<string, V> {
|
||||||
baseObject: (new (...args: any[]) => V) | undefined;
|
baseObject: (new (...args: any[]) => V) | undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance of Collection
|
* Creates an instance of Collection
|
||||||
*/
|
*/
|
||||||
constructor(iterable: Iterable<[string, V]> | object | null = null) {
|
constructor(iterable: Iterable<[string, V]> | object | null = null) {
|
||||||
if (iterable && iterable instanceof Array) {
|
if (iterable && iterable instanceof Array) {
|
||||||
super(iterable);
|
super(iterable);
|
||||||
} else if (iterable && iterable instanceof Object) {
|
} else if (iterable && iterable instanceof Object) {
|
||||||
super(Object.entries(iterable));
|
super(Object.entries(iterable));
|
||||||
} else {
|
} else {
|
||||||
super();
|
super();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map to array
|
* Map to array
|
||||||
* ```js
|
* ```js
|
||||||
* [value, value, value]
|
* [value, value, value]
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
toArray(): V[] {
|
toArray(): V[] {
|
||||||
return [...this.values()];
|
return [...this.values()];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map to object
|
||||||
|
* ```js
|
||||||
|
* { key: value, key: value, key: value }
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
toObject(): { [key: string]: V } {
|
||||||
|
const obj: { [key: string]: V } = {};
|
||||||
|
for (const [key, value] of this.entries()) {
|
||||||
|
obj[key] = value;
|
||||||
}
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map to object
|
* Add an object
|
||||||
* ```js
|
*
|
||||||
* { key: value, key: value, key: value }
|
* If baseObject, add only if instance of baseObject
|
||||||
* ```
|
*
|
||||||
*/
|
* If no baseObject, add
|
||||||
toObject(): { [key: string]: V } {
|
* @param key The key of the object
|
||||||
const obj: { [key: string]: V } = {};
|
* @param value The object data
|
||||||
for (const [key, value] of this.entries()) {
|
* @param replace Whether to replace an existing object with the same key
|
||||||
obj[key] = value;
|
* @return The existing or newly created object
|
||||||
}
|
*/
|
||||||
return obj;
|
add(key: string, value: V, replace: boolean = false): V | undefined | null {
|
||||||
|
if (this.has(key) && !replace) {
|
||||||
|
return this.get(key);
|
||||||
}
|
}
|
||||||
|
if (this.baseObject && !(value instanceof this.baseObject)) return null;
|
||||||
|
|
||||||
/**
|
this.set(key, value);
|
||||||
* Add an object
|
return value;
|
||||||
*
|
}
|
||||||
* If baseObject, add only if instance of baseObject
|
|
||||||
*
|
|
||||||
* If no baseObject, add
|
|
||||||
* @param key The key of the object
|
|
||||||
* @param value The object data
|
|
||||||
* @param replace Whether to replace an existing object with the same key
|
|
||||||
* @return The existing or newly created object
|
|
||||||
*/
|
|
||||||
add(key: string, value: V, replace: boolean = false): V | undefined | null {
|
|
||||||
if (this.has(key) && !replace) {
|
|
||||||
return this.get(key);
|
|
||||||
}
|
|
||||||
if (this.baseObject && !(value instanceof this.baseObject)) return null;
|
|
||||||
|
|
||||||
this.set(key, value);
|
/**
|
||||||
return value;
|
* Return the first object to make the function evaluate true
|
||||||
|
* @param func A function that takes an object and returns something
|
||||||
|
* @return The first matching object, or `null` if no match
|
||||||
|
*/
|
||||||
|
find(func: Function): V | null {
|
||||||
|
for (const item of this.values()) {
|
||||||
|
if (func(item)) return item;
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the first object to make the function evaluate true
|
* Return an array with the results of applying the given function to each element
|
||||||
* @param func A function that takes an object and returns something
|
* @param callbackfn A function that takes an object and returns something
|
||||||
* @return The first matching object, or `null` if no match
|
*/
|
||||||
*/
|
map<U>(callbackfn: (value?: V, index?: number, array?: V[]) => U): U[] {
|
||||||
find(func: Function): V | null {
|
const arr = [];
|
||||||
for (const item of this.values()) {
|
for (const item of this.values()) {
|
||||||
if (func(item)) return item;
|
arr.push(callbackfn(item));
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an array with the results of applying the given function to each element
|
* Return all the objects that make the function evaluate true
|
||||||
* @param callbackfn A function that takes an object and returns something
|
* @param func A function that takes an object and returns true if it matches
|
||||||
*/
|
*/
|
||||||
map<U>(callbackfn: (value?: V, index?: number, array?: V[]) => U): U[] {
|
filter(func: (value: V) => boolean): V[] {
|
||||||
const arr = [];
|
const arr = [];
|
||||||
for (const item of this.values()) {
|
for (const item of this.values()) {
|
||||||
arr.push(callbackfn(item));
|
if (func(item)) {
|
||||||
}
|
arr.push(item);
|
||||||
return arr;
|
}
|
||||||
}
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all the objects that make the function evaluate true
|
* Test if at least one element passes the test implemented by the provided function. Returns true if yes, or false if not.
|
||||||
* @param func A function that takes an object and returns true if it matches
|
* @param func A function that takes an object and returns true if it matches
|
||||||
*/
|
*/
|
||||||
filter(func: (value: V) => boolean): V[] {
|
some(func: (value: V) => boolean) {
|
||||||
const arr = [];
|
for (const item of this.values()) {
|
||||||
for (const item of this.values()) {
|
if (func(item)) {
|
||||||
if (func(item)) {
|
return true;
|
||||||
arr.push(item);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return arr;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if at least one element passes the test implemented by the provided function. Returns true if yes, or false if not.
|
* Update an object
|
||||||
* @param func A function that takes an object and returns true if it matches
|
* @param key The key of the object
|
||||||
*/
|
* @param value The updated object data
|
||||||
some(func: (value: V) => boolean) {
|
*/
|
||||||
for (const item of this.values()) {
|
update(key: string, value: V) {
|
||||||
if (func(item)) {
|
return this.add(key, value, true);
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update an object
|
* Remove an object
|
||||||
* @param key The key of the object
|
* @param key The key of the object
|
||||||
* @param value The updated object data
|
* @returns The removed object, or `null` if nothing was removed
|
||||||
*/
|
*/
|
||||||
update(key: string, value: V) {
|
remove(key: string): V | null {
|
||||||
return this.add(key, value, true);
|
const item = this.get(key);
|
||||||
|
if (!item) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
this.delete(key);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove an object
|
* Get a random object from the Collection
|
||||||
* @param key The key of the object
|
* @returns The random object or `null` if empty
|
||||||
* @returns The removed object, or `null` if nothing was removed
|
*/
|
||||||
*/
|
random(): V | null {
|
||||||
remove(key: string): V | null {
|
if (!this.size) {
|
||||||
const item = this.get(key);
|
return null;
|
||||||
if (!item) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
this.delete(key);
|
|
||||||
return item;
|
|
||||||
}
|
}
|
||||||
|
return Array.from(this.values())[Math.floor(Math.random() * this.size)];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
toString() {
|
||||||
* Get a random object from the Collection
|
// @ts-ignore
|
||||||
* @returns The random object or `null` if empty
|
return `[Collection<${this.baseObject.name}>]`;
|
||||||
*/
|
}
|
||||||
random(): V | null {
|
|
||||||
if (!this.size) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return Array.from(this.values())[Math.floor(Math.random() * this.size)];
|
|
||||||
}
|
|
||||||
|
|
||||||
toString() {
|
|
||||||
// @ts-ignore
|
|
||||||
return `[Collection<${this.baseObject.name}>]`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import { Client } from "discord.js";
|
import { Client } from "discord.js";
|
||||||
export default abstract class DiscordEvent {
|
export default abstract class DiscordEvent {
|
||||||
public name: string;
|
public name: string;
|
||||||
protected client: Client;
|
protected client: Client;
|
||||||
|
|
||||||
protected constructor(name: string = "", client: Client) {
|
protected constructor(name: string = "", client: Client) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.execute = this.execute.bind(this);
|
this.execute = this.execute.bind(this);
|
||||||
}
|
}
|
||||||
public abstract execute(...args: any[]): Error | Promise<void>;
|
public abstract execute(...args: any[]): Error | Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,30 +2,32 @@ import { SlashCommandBuilder, ChatInputCommandInteraction } from "discord.js";
|
||||||
import { guildID } from "../config.json";
|
import { guildID } from "../config.json";
|
||||||
|
|
||||||
export interface DiscordInteractionCommandSkeleton {
|
export interface DiscordInteractionCommandSkeleton {
|
||||||
GUILD_ID: string;
|
GUILD_ID: string;
|
||||||
builder?: SlashCommandBuilder;
|
builder?: SlashCommandBuilder;
|
||||||
description: string;
|
description: string;
|
||||||
execute: (interaction: ChatInputCommandInteraction) => Error | Promise<void | any>;
|
execute: (interaction: ChatInputCommandInteraction) => Error | Promise<void | any>;
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default abstract class DiscordInteractionCommand implements DiscordInteractionCommandSkeleton {
|
export default abstract class DiscordInteractionCommand
|
||||||
public name: string;
|
implements DiscordInteractionCommandSkeleton
|
||||||
public description: string;
|
{
|
||||||
public builder: SlashCommandBuilder;
|
public name: string;
|
||||||
|
public description: string;
|
||||||
|
public builder: SlashCommandBuilder;
|
||||||
|
|
||||||
public GUILD_ID: string;
|
public GUILD_ID: string;
|
||||||
|
|
||||||
protected constructor(name: string, description: string) {
|
protected constructor(name: string, description: string) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.builder = new SlashCommandBuilder();
|
this.builder = new SlashCommandBuilder();
|
||||||
|
|
||||||
this.builder.setName(this.name);
|
this.builder.setName(this.name);
|
||||||
this.builder.setDescription(this.description);
|
this.builder.setDescription(this.description);
|
||||||
|
|
||||||
this.GUILD_ID = guildID;
|
this.GUILD_ID = guildID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract execute(interaction: ChatInputCommandInteraction): Error | Promise<void | any>;
|
public abstract execute(interaction: ChatInputCommandInteraction): Error | Promise<void | any>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export default class EmojiConfig {
|
export default class EmojiConfig {
|
||||||
public static LOC = "<:loc:607695848612167700>";
|
public static LOC = "<:loc:607695848612167700>";
|
||||||
public static EMAIL = "<:email:699786452267040878>";
|
public static EMAIL = "<:email:699786452267040878>";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,84 +1,118 @@
|
||||||
import Partner, {
|
import Partner, {
|
||||||
PartnerCommissionType,
|
PartnerCommissionType,
|
||||||
PartnerDepartment,
|
PartnerDepartment,
|
||||||
PartnerModel,
|
PartnerModel,
|
||||||
PartnerRoleType,
|
PartnerRoleType,
|
||||||
PartnerTitle
|
PartnerTitle,
|
||||||
} from "../database/Partner";
|
} from "../database/Partner";
|
||||||
import Member, { MemberAdditionalAcknowledgement, MemberModel } from "../database/Member";
|
import Member, { MemberAdditionalAcknowledgement, MemberModel } from "../database/Member";
|
||||||
import { Client, GuildMember, User } from "discord.js";
|
import { Client, GuildMember, User } from "discord.js";
|
||||||
import { guildID } from "../config.json";
|
import { guildID } from "../config.json";
|
||||||
|
|
||||||
export interface PartnerOptions {
|
export interface PartnerOptions {
|
||||||
roleType: PartnerRoleType;
|
roleType: PartnerRoleType;
|
||||||
commissionType: PartnerCommissionType;
|
commissionType: PartnerCommissionType;
|
||||||
department: PartnerDepartment;
|
department: PartnerDepartment;
|
||||||
title: PartnerTitle;
|
title: PartnerTitle;
|
||||||
directReport: Partner | string;
|
directReport: Partner | string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FormatNameOptions {
|
export interface FormatNameOptions {
|
||||||
text: string;
|
text: string;
|
||||||
iconURL: string;
|
iconURL: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add the rest of the remaining role configurations
|
// TODO: Add the rest of the remaining role configurations
|
||||||
export const PartnerDiscordRoleMap = {
|
export const PartnerDiscordRoleMap = {
|
||||||
// Director of Engineering, Management, Staff, Technician, Core Team, Play Caller
|
// Director of Engineering, Management, Staff, Technician, Core Team, Play Caller
|
||||||
"Director of Engineering": ["1077646568091570236", "1077646956890951690", "446104438969466890", "701454780828221450", "453689940140883988", "1014978134573064293"],
|
"Director of Engineering": [
|
||||||
// Director of Operations, Management, Staff, Moderator, Core Team, Play Caller
|
"1077646568091570236",
|
||||||
"Director of Operations": ["1077647072163020840", "1077646956890951690", "446104438969466890", "455972169449734144", "453689940140883988", "1014978134573064293"]
|
"1077646956890951690",
|
||||||
}
|
"446104438969466890",
|
||||||
|
"701454780828221450",
|
||||||
|
"453689940140883988",
|
||||||
|
"1014978134573064293",
|
||||||
|
],
|
||||||
|
// Director of Operations, Management, Staff, Moderator, Core Team, Play Caller
|
||||||
|
"Director of Operations": [
|
||||||
|
"1077647072163020840",
|
||||||
|
"1077646956890951690",
|
||||||
|
"446104438969466890",
|
||||||
|
"455972169449734144",
|
||||||
|
"453689940140883988",
|
||||||
|
"1014978134573064293",
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
export default class MemberUtil {
|
export default class MemberUtil {
|
||||||
public static async createNewPartner(member: Member, options: PartnerOptions) {
|
public static async createNewPartner(member: Member, options: PartnerOptions) {
|
||||||
const partner = new PartnerModel();
|
const partner = new PartnerModel();
|
||||||
partner.discordID = member.discordID;
|
partner.discordID = member.discordID;
|
||||||
partner.roleType = options.roleType;
|
partner.roleType = options.roleType;
|
||||||
partner.commissionType = options.commissionType;
|
partner.commissionType = options.commissionType;
|
||||||
partner.department = options.department;
|
partner.department = options.department;
|
||||||
partner.title = options.title;
|
partner.title = options.title;
|
||||||
partner.directReport = options.directReport;
|
partner.directReport = options.directReport;
|
||||||
await partner.save();
|
await partner.save();
|
||||||
return partner;
|
return partner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getPartner(member: Member) {
|
public static async getPartner(member: Member) {
|
||||||
return PartnerModel.findOne({ discordID: member.discordID });
|
return PartnerModel.findOne({ discordID: member.discordID });
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async deletePartner(member: Member) {
|
public static async deletePartner(member: Member) {
|
||||||
return PartnerModel.deleteOne({ discordID: member.discordID });
|
return PartnerModel.deleteOne({ discordID: member.discordID });
|
||||||
}
|
}
|
||||||
|
|
||||||
public static addAcknowledgementToMember(member: Member, acknowledgement: MemberAdditionalAcknowledgement) {
|
public static addAcknowledgementToMember(
|
||||||
if (!member.additionalAcknowledgement || member.additionalAcknowledgement?.length === 0) {
|
member: Member,
|
||||||
MemberModel.updateOne({ discordID: member.discordID }, { additionalAcknowledgement: [] });
|
acknowledgement: MemberAdditionalAcknowledgement
|
||||||
}
|
) {
|
||||||
if (member.additionalAcknowledgement?.includes(acknowledgement)) throw new Error("This member already has this acknowledgement.")
|
if (!member.additionalAcknowledgement || member.additionalAcknowledgement?.length === 0) {
|
||||||
return MemberModel.updateOne({ discordID: member.discordID }, { $push: { additionalAcknowledgement: acknowledgement } });
|
MemberModel.updateOne({ discordID: member.discordID }, { additionalAcknowledgement: [] });
|
||||||
}
|
}
|
||||||
|
if (member.additionalAcknowledgement?.includes(acknowledgement))
|
||||||
|
throw new Error("This member already has this acknowledgement.");
|
||||||
|
return MemberModel.updateOne(
|
||||||
|
{ discordID: member.discordID },
|
||||||
|
{ $push: { additionalAcknowledgement: acknowledgement } }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: comments and extended formatting
|
// TODO: comments and extended formatting
|
||||||
public static formatName(target: GuildMember | User, partner?: Partner | null): FormatNameOptions {
|
public static formatName(
|
||||||
console.log(`[MemberUtil] Formatting name for ${target.displayName} at url ${target instanceof GuildMember ? target.user.displayAvatarURL() : target.displayAvatarURL()}`);
|
target: GuildMember | User,
|
||||||
// if the role type is managerial, add a [k] to the end of the name
|
partner?: Partner | null
|
||||||
// if the partner exists, set the iconURL to the organizational logo
|
): FormatNameOptions {
|
||||||
if (partner?.roleType == PartnerRoleType.MANAGERIAL) {
|
console.log(
|
||||||
return {
|
`[MemberUtil] Formatting name for ${target.displayName} at url ${target instanceof GuildMember ? target.user.displayAvatarURL() : target.displayAvatarURL()}`
|
||||||
text: `${target.displayName} [k]`,
|
);
|
||||||
iconURL: target.displayAvatarURL(),
|
// if the role type is managerial, add a [k] to the end of the name
|
||||||
}
|
// if the partner exists, set the iconURL to the organizational logo
|
||||||
} else if (partner?.commissionType == PartnerCommissionType.CONTRACTUAL) { // if the commission type is contractual, add a [c] to the end of the name
|
if (partner?.roleType == PartnerRoleType.MANAGERIAL) {
|
||||||
return {
|
return {
|
||||||
text: `${target.displayName} [c]`,
|
text: `${target.displayName} [k]`,
|
||||||
iconURL: target instanceof GuildMember ? target.user.displayAvatarURL() : target.displayAvatarURL(),
|
iconURL: target.displayAvatarURL(),
|
||||||
}
|
};
|
||||||
} else { // otherwise, just set the author to the member's display name
|
} else if (partner?.commissionType == PartnerCommissionType.CONTRACTUAL) {
|
||||||
return {
|
// if the commission type is contractual, add a [c] to the end of the name
|
||||||
text: target.displayName,
|
return {
|
||||||
iconURL: target instanceof GuildMember ? target.user.displayAvatarURL() : target.displayAvatarURL(),
|
text: `${target.displayName} [c]`,
|
||||||
}
|
iconURL:
|
||||||
}
|
target instanceof GuildMember
|
||||||
|
? target.user.displayAvatarURL()
|
||||||
|
: target.displayAvatarURL(),
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// otherwise, just set the author to the member's display name
|
||||||
|
return {
|
||||||
|
text: target.displayName,
|
||||||
|
iconURL:
|
||||||
|
target instanceof GuildMember
|
||||||
|
? target.user.displayAvatarURL()
|
||||||
|
: target.displayAvatarURL(),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue