update all files

master
Matthew 2024-10-25 16:57:33 -04:00
parent 599159c6ea
commit bc10712329
Signed by: matthew
SSH Key Fingerprint: SHA256:piIXekA9q1p0ZGi4ogFbNY1embip5Ytbi3v8AZ8UYq4
17 changed files with 665 additions and 585 deletions

View File

@ -1,5 +1,9 @@
import { prop, getModelForClass, Ref } from "@typegoose/typegoose"
import Member, { MemberAdditionalAcknowledgement, MemberUsedLanguages, MemberUsedOperatingSystems } from "./Member";
import { prop, getModelForClass, Ref } from "@typegoose/typegoose";
import Member, {
MemberAdditionalAcknowledgement,
MemberUsedLanguages,
MemberUsedOperatingSystems,
} from "./Member";
export enum GenerationMethod {
TIMER_INTERNAL, // generated by the internal cron-job timer automatically
@ -16,9 +20,9 @@ export interface AddtlScoreData {
}
/* TODO
* Comments
* Further attributes for class
* */
* Comments
* Further attributes for class
* */
export default class CommunityReport {
@prop({ required: true, index: true, ref: () => Member })

View File

@ -1,4 +1,4 @@
import { prop, getModelForClass, Ref } from "@typegoose/typegoose"
import { prop, getModelForClass, Ref } from "@typegoose/typegoose";
import Inquiry from "./Inquiry";
/**

View File

@ -1,6 +1,6 @@
import { prop, getModelForClass, Ref } from "@typegoose/typegoose"
import { prop, getModelForClass, Ref } from "@typegoose/typegoose";
import Member from "./Member";
import CommunityReport from "./CommunityReport"
import CommunityReport from "./CommunityReport";
/**
* TODO:
@ -9,7 +9,6 @@ import CommunityReport from "./CommunityReport"
* - Reason
*/
export default abstract class Inquiry {
@prop({ required: true, unique: true })
// the Inquiry Identifier (previously known as `iid`). this is an UUIDv4 string

View File

@ -1,19 +1,19 @@
import { prop, getModelForClass } from "@typegoose/typegoose"
import { prop, getModelForClass } from "@typegoose/typegoose";
/* TODO
* Comments
* Further attributes for class
* */
* Comments
* Further attributes for class
* */
export interface SharedMemberAttributes {
discordID: string | undefined;
}
export type MemberAdditionalAcknowledgement =
"Chair of the Board of Governors" |
"Vice Chair of the Board of Governors" |
"Voting Seat Member of the Board of Governors" |
string;
| "Chair of the Board of Governors"
| "Vice Chair of the Board of Governors"
| "Voting Seat Member of the Board of Governors"
| string;
export const MemberGuildRoleIDMap = {
// Chair/Vice Chair of the Board of Governors
@ -40,8 +40,7 @@ export const MemberGuildRoleIDMap = {
CORE_TEAM: "453689940140883988",
// Intern (Training)
INTERN: "701481967149121627",
}
};
// enum for the used programming languages in whois information
export enum MemberUsedLanguages {
@ -56,7 +55,7 @@ export enum MemberUsedLanguages {
RB = "lang-rb",
RS = "lang-rs",
SWIFT = "lang-swift",
TS = "lang-ts"
TS = "lang-ts",
}
// enum for the used operating systems in the whois information
@ -69,7 +68,7 @@ export enum MemberUsedOperatingSystems {
MANJARO = "os-manjaro",
REDHAT = "os-redhat",
UBUNTU = "os-ubuntu",
WIN = "os-win"
WIN = "os-win",
}
export default class Member implements SharedMemberAttributes {
@prop({ required: true, unique: true })

View File

@ -2,30 +2,29 @@ import { prop, getModelForClass } from "@typegoose/typegoose";
import Member from "./Member";
/* TODO
* Comments
* Further attributes for class
* */
* Comments
* Further attributes for class
* */
import { SharedMemberAttributes } from "./Member";
export type PartnerTitle =
"Director of Engineering" |
"Director of Operations" |
"Deputy Director of Engineering" |
"Deputy Director of Operations" |
"Services Manager" |
"Project Manager" |
"Engineering Core Partner" |
"Operations Core Partner" |
"Community Moderator" |
"Technician" |
string;
| "Director of Engineering"
| "Director of Operations"
| "Deputy Director of Engineering"
| "Deputy Director of Operations"
| "Services Manager"
| "Project Manager"
| "Engineering Core Partner"
| "Operations Core Partner"
| "Community Moderator"
| "Technician"
| string;
export enum PartnerDepartment {
INDEPENDENT_AGENCY,
ENGINEERING, // Department of Engineering
OPERATIONS // Department of Operations
OPERATIONS, // Department of Operations
}
export enum PartnerRoleType {

View File

@ -1,4 +1,4 @@
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.
export default class Vendor {

View File

@ -10,11 +10,20 @@ export default class Eval extends DiscordInteractionCommand {
constructor() {
super("eval", "Executes arbitrary JS code and returns the output.");
// 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) =>
option.setName("code").setDescription("The code to execute.").setRequired(true)
);
// this option is optional and is a boolean that determines whether the code should be run as an async function
this.builder.addBooleanOption(option => option.setName("async").setDescription("Whether to run the code as an async function.").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.builder.addIntegerOption((option) =>
option.setName("depth").setDescription("The depth of the inspection.").setRequired(false)
);
this.listOfAllowedIDs = [
"278620217221971968", // Matthew
@ -24,9 +33,11 @@ export default class Eval extends DiscordInteractionCommand {
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});
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);
@ -44,13 +55,12 @@ export default class Eval extends DiscordInteractionCommand {
}
try {
// eslint-disable-next-line no-eval
evaled = await eval(evalString);
if (typeof evaled !== 'string') {
if (typeof evaled !== "string") {
evaled = inspect(evaled, { depth });
}
if (evaled === undefined) {
evaled = 'undefined';
evaled = "undefined";
}
} catch (error) {
// @ts-ignore
@ -58,7 +68,7 @@ export default class Eval extends DiscordInteractionCommand {
}
// replaces all instances of the bot token with [REDACTED] in output
evaled = evaled.replace(new RegExp(discordBotToken, 'gi'), '[REDACTED]');
evaled = evaled.replace(new RegExp(discordBotToken, "gi"), "[REDACTED]");
// TODO: Figure this out.
/*const display = this.client.util.splitString(evaled, 1975);
@ -70,6 +80,6 @@ export default class Eval extends DiscordInteractionCommand {
return this.error(ctx.message.channel, `${error}`);
}
}*/
await interaction.editReply({content: `\`\`\`js\n${evaled}\n\`\`\``})
await interaction.editReply({ content: `\`\`\`js\n${evaled}\n\`\`\`` });
}
}

View File

@ -1,4 +1,6 @@
import DiscordInteractionCommand, { DiscordInteractionCommandSkeleton } from "../../util/DiscordInteractionCommand";
import DiscordInteractionCommand, {
DiscordInteractionCommandSkeleton,
} from "../../util/DiscordInteractionCommand";
import { guildID } from "../../config.json";
import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
import { MemberModel } from "../../database/Member";
@ -7,7 +9,7 @@ import { PartnerModel } from "../../database/Partner";
export default class PartnerAdd implements DiscordInteractionCommandSkeleton {
public GUILD_ID: string;
public name: string;
public description: string
public description: string;
public builder: SlashCommandBuilder;
constructor() {
this.name = "partner";
@ -18,8 +20,15 @@ export default class PartnerAdd implements DiscordInteractionCommandSkeleton {
public async execute(interaction: ChatInputCommandInteraction) {
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 (!(await PartnerModel.findOne({discordID: interaction.user.id}))) return interaction.reply({ content: "The specified partner already has a partner entry.", ephemeral: true });
if (!member)
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,
});
}
}

View File

@ -15,7 +15,7 @@ export default class Ping extends DiscordInteractionCommand {
const endTimestamp = Date.now(); // Mark the end of all processing (after 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\``,
});
}
}

View File

@ -1,14 +1,24 @@
import DiscordInteractionCommand from "../../util/DiscordInteractionCommand";
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 MemberUtil from "../../util/MemberUtil";
import EmojiConfig from "../../util/EmojiConfig"
import EmojiConfig from "../../util/EmojiConfig";
export default class Whois extends DiscordInteractionCommand {
constructor() {
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) {
@ -20,7 +30,8 @@ export default class Whois extends DiscordInteractionCommand {
const databaseMember = await MemberModel.findOne({ discordID: target.id });
const partner = await PartnerModel.findOne({ discordID: target.id });
// return an error if target was not located
if (!guildMember) return interaction.editReply({ content: `Member target ${target.id} was not located.`});
if (!guildMember)
return interaction.editReply({ content: `Member target ${target.id} was not located.` });
// build our embed
const embed = new EmbedBuilder();
// if the role type is managerial, add a [k] to the end of the name
@ -30,7 +41,7 @@ export default class Whois extends DiscordInteractionCommand {
// set the thumbnail to the user's avatar
embed.setThumbnail(guildMember.user.displayAvatarURL());
// initialize the description string
let embedDescription = '';
let embedDescription = "";
if (partner) {
// set the title to the partner's title if applicable
if (partner.title) embedDescription += `## __${EmojiConfig.LOC} ${partner.title}__\n`;
@ -76,7 +87,8 @@ export default class Whois extends DiscordInteractionCommand {
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
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 });
@ -96,7 +108,9 @@ export default class Whois extends DiscordInteractionCommand {
break;
}
}
embed.setFooter({ text: `Discord ID: ${guildMember.id}${databaseMember ? `Internal ID: ${databaseMember?._id}` : ''}` });
embed.setFooter({
text: `Discord ID: ${guildMember.id}${databaseMember ? `Internal ID: ${databaseMember?._id}` : ""}`,
});
return await interaction.editReply({ embeds: [embed] });
}

View File

@ -13,13 +13,23 @@ export default class InteractionCreate extends DiscordEvent {
if (!command) return console.error(`No command matching ${interaction.commandName} was found.`);
try {
await command.execute(interaction);
console.info(`[Info - Discord] Command '${interaction.commandName}' executed by '${interaction.user.username}'`);
console.info(
`[Info - Discord] Command '${interaction.commandName}' executed by '${interaction.user.username}'`
);
} catch (error) {
console.error(`Error executing command '${interaction.commandName}': by '${interaction.user.username}'\n${error}`);
console.error(
`Error executing command '${interaction.commandName}': by '${interaction.user.username}'\n${error}`
);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
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 });
await interaction.reply({
content: "There was an error while executing this command!",
ephemeral: true,
});
}
}
}

View File

@ -9,7 +9,9 @@ export interface DiscordInteractionCommandSkeleton {
name: string;
}
export default abstract class DiscordInteractionCommand implements DiscordInteractionCommandSkeleton {
export default abstract class DiscordInteractionCommand
implements DiscordInteractionCommandSkeleton
{
public name: string;
public description: string;
public builder: SlashCommandBuilder;

View File

@ -3,7 +3,7 @@ import Partner, {
PartnerDepartment,
PartnerModel,
PartnerRoleType,
PartnerTitle
PartnerTitle,
} from "../database/Partner";
import Member, { MemberAdditionalAcknowledgement, MemberModel } from "../database/Member";
import { Client, GuildMember, User } from "discord.js";
@ -25,10 +25,24 @@ export interface FormatNameOptions {
// TODO: Add the rest of the remaining role configurations
export const PartnerDiscordRoleMap = {
// Director of Engineering, Management, Staff, Technician, Core Team, Play Caller
"Director of Engineering": ["1077646568091570236", "1077646956890951690", "446104438969466890", "701454780828221450", "453689940140883988", "1014978134573064293"],
"Director of Engineering": [
"1077646568091570236",
"1077646956890951690",
"446104438969466890",
"701454780828221450",
"453689940140883988",
"1014978134573064293",
],
// Director of Operations, Management, Staff, Moderator, Core Team, Play Caller
"Director of Operations": ["1077647072163020840", "1077646956890951690", "446104438969466890", "455972169449734144", "453689940140883988", "1014978134573064293"]
}
"Director of Operations": [
"1077647072163020840",
"1077646956890951690",
"446104438969466890",
"455972169449734144",
"453689940140883988",
"1014978134573064293",
],
};
export default class MemberUtil {
public static async createNewPartner(member: Member, options: PartnerOptions) {
@ -51,34 +65,54 @@ export default class MemberUtil {
return PartnerModel.deleteOne({ discordID: member.discordID });
}
public static addAcknowledgementToMember(member: Member, acknowledgement: MemberAdditionalAcknowledgement) {
public static addAcknowledgementToMember(
member: Member,
acknowledgement: MemberAdditionalAcknowledgement
) {
if (!member.additionalAcknowledgement || member.additionalAcknowledgement?.length === 0) {
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 } });
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
public static formatName(target: GuildMember | User, partner?: Partner | null): FormatNameOptions {
console.log(`[MemberUtil] Formatting name for ${target.displayName} at url ${target instanceof GuildMember ? target.user.displayAvatarURL() : target.displayAvatarURL()}`);
public static formatName(
target: GuildMember | User,
partner?: Partner | null
): FormatNameOptions {
console.log(
`[MemberUtil] Formatting name for ${target.displayName} at url ${target instanceof GuildMember ? target.user.displayAvatarURL() : 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
if (partner?.roleType == PartnerRoleType.MANAGERIAL) {
return {
text: `${target.displayName} [k]`,
iconURL: target.displayAvatarURL(),
}
} else if (partner?.commissionType == PartnerCommissionType.CONTRACTUAL) { // if the commission type is contractual, add a [c] to the end of the name
};
} else if (partner?.commissionType == PartnerCommissionType.CONTRACTUAL) {
// if the commission type is contractual, add a [c] to the end of the name
return {
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
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(),
}
iconURL:
target instanceof GuildMember
? target.user.displayAvatarURL()
: target.displayAvatarURL(),
};
}
}
}