Compare commits
No commits in common. "98c1e8377031d514f08c5803a4e1acb2c8b27405" and "ed90a4c3f9bbab801c72bc632dcb4813aa3120b2" have entirely different histories.
98c1e83770
...
ed90a4c3f9
|
@ -5,10 +5,6 @@ import { prop, getModelForClass } from "@typegoose/typegoose"
|
||||||
* Further attributes for class
|
* Further attributes for class
|
||||||
* */
|
* */
|
||||||
|
|
||||||
export interface SharedMemberAttributes {
|
|
||||||
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" |
|
||||||
|
@ -43,7 +39,7 @@ export enum MemberUsedOperatingSystems {
|
||||||
UBUNTU = "os-ubuntu",
|
UBUNTU = "os-ubuntu",
|
||||||
WIN = "os-win"
|
WIN = "os-win"
|
||||||
}
|
}
|
||||||
export default class Member implements SharedMemberAttributes {
|
export default class Member {
|
||||||
@prop({ required: true, unique: true })
|
@prop({ required: true, unique: true })
|
||||||
public discordID: string | undefined;
|
public discordID: string | undefined;
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,6 @@ import Member from "./Member";
|
||||||
* Further attributes for class
|
* Further attributes for class
|
||||||
* */
|
* */
|
||||||
|
|
||||||
import { SharedMemberAttributes } from "./Member";
|
|
||||||
|
|
||||||
export type PartnerTitle =
|
export type PartnerTitle =
|
||||||
"Director of Engineering" |
|
"Director of Engineering" |
|
||||||
"Director of Operations" |
|
"Director of Operations" |
|
||||||
|
@ -42,13 +40,10 @@ export enum PartnerCommissionType {
|
||||||
TRIAL,
|
TRIAL,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Partner implements SharedMemberAttributes {
|
export default class Partner {
|
||||||
@prop({ required: true, unique: true })
|
@prop({ required: true, unique: true })
|
||||||
public discordID: string | undefined;
|
public discordID: string | undefined;
|
||||||
|
|
||||||
@prop()
|
|
||||||
public emailAddress: string | undefined;
|
|
||||||
|
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
public roleType: PartnerRoleType | undefined;
|
public roleType: PartnerRoleType | undefined;
|
||||||
|
|
||||||
|
|
|
@ -1,81 +0,0 @@
|
||||||
import DiscordInteractionCommand from "../../util/DiscordInteractionCommand";
|
|
||||||
import { MemberModel } from "../../database/Member";
|
|
||||||
import Partner, {PartnerCommissionType, PartnerDepartment, PartnerModel, PartnerRoleType} from "../../database/Partner";
|
|
||||||
import { ChatInputCommandInteraction, EmbedBuilder } from "discord.js";
|
|
||||||
import MemberUtil from "../../util/MemberUtil";
|
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
public async execute(interaction: ChatInputCommandInteraction) {
|
|
||||||
// defer our reply and perform database/external API operations/lookups
|
|
||||||
await interaction.deferReply({ ephemeral: false });
|
|
||||||
const target = interaction.options.getUser("member", true);
|
|
||||||
const guild = interaction.guild || interaction.client.guilds.cache.get(this.GUILD_ID);
|
|
||||||
const guildMember = await guild?.members.fetch(target.id);
|
|
||||||
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.`});
|
|
||||||
// build our embed
|
|
||||||
const embed = new EmbedBuilder();
|
|
||||||
// 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
|
|
||||||
const formattedName = MemberUtil.formatName(guildMember, partner);
|
|
||||||
embed.setAuthor({ name: formattedName.text, iconURL: formattedName.iconURL });
|
|
||||||
// set the title to the partner's title if applicable
|
|
||||||
if (partner?.title) embed.setTitle(partner.title);
|
|
||||||
// set the thumbnail to the user's avatar
|
|
||||||
embed.setThumbnail(guildMember.user.displayAvatarURL());
|
|
||||||
// initialize the description string
|
|
||||||
let embedDescription = '';
|
|
||||||
if (partner) {
|
|
||||||
embedDescription += "__**Partner Information**__\n";
|
|
||||||
if (partner.emailAddress) embedDescription += `**Email Address**: ${partner.emailAddress}\n`;
|
|
||||||
switch (partner.department) {
|
|
||||||
case PartnerDepartment.ENGINEERING:
|
|
||||||
embedDescription += "**Department**: Dept. of Engineering\n";
|
|
||||||
break;
|
|
||||||
case PartnerDepartment.OPERATIONS:
|
|
||||||
embedDescription += "**Department**: Dept. of Operations\n";
|
|
||||||
break;
|
|
||||||
case PartnerDepartment.INDEPENDENT_AGENCY:
|
|
||||||
embedDescription += "**Department**: Independent Agency/Contractor\n";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
switch (partner.commissionType) {
|
|
||||||
case PartnerCommissionType.TENURE:
|
|
||||||
embedDescription += "**Commission Type**: Tenure\n";
|
|
||||||
break;
|
|
||||||
case PartnerCommissionType.PROVISIONAL:
|
|
||||||
embedDescription += "**Commission Type**: Provisional\n";
|
|
||||||
break;
|
|
||||||
case PartnerCommissionType.CONTRACTUAL:
|
|
||||||
embedDescription += "**Commission Type**: Contractual/Independent/Collaborator\n";
|
|
||||||
break;
|
|
||||||
case PartnerCommissionType.ACTING:
|
|
||||||
embedDescription += "**Commission Type**: Acting\n";
|
|
||||||
break;
|
|
||||||
case PartnerCommissionType.INTERIM:
|
|
||||||
embedDescription += "**Commission Type**: Interim\n";
|
|
||||||
break;
|
|
||||||
case PartnerCommissionType.TRIAL:
|
|
||||||
embedDescription += "**Commission Type**: Trial/Intern\n";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (partner.directReport) {
|
|
||||||
if (partner.directReport instanceof Partner) {
|
|
||||||
embedDescription += `**Direct Report**: ${partner.directReport.title}\n`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
embed.setColor(guildMember.displayColor);
|
|
||||||
embed.setDescription(embedDescription);
|
|
||||||
embed.setFooter({ text: `Discord ID: ${guildMember.id}${databaseMember ? `Internal ID: ${databaseMember?._id}` : ''}` });
|
|
||||||
|
|
||||||
return await interaction.editReply({ embeds: [embed] });
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,2 +1 @@
|
||||||
export { default as Ping } from "./Ping";
|
export { default as Ping } from "./Ping";
|
||||||
export { default as Whois } from "./Whois";
|
|
||||||
|
|
12
index.ts
12
index.ts
|
@ -5,7 +5,6 @@ import DiscordInteractionCommand from "./util/DiscordInteractionCommand";
|
||||||
import DiscordEvent from "./util/DiscordEvent";
|
import DiscordEvent from "./util/DiscordEvent";
|
||||||
import * as DiscordInteractionCommandsIndex from "./discord/commands";
|
import * as DiscordInteractionCommandsIndex from "./discord/commands";
|
||||||
import * as DiscordEventsIndex from "./discord/events";
|
import * as DiscordEventsIndex from "./discord/events";
|
||||||
import mongoose from "mongoose";
|
|
||||||
|
|
||||||
export const DiscordInteractionCommands: Collection<DiscordInteractionCommand> = new Collection();
|
export const DiscordInteractionCommands: Collection<DiscordInteractionCommand> = new Collection();
|
||||||
export const DiscordEvents: Collection<DiscordEvent> = new Collection();
|
export const DiscordEvents: Collection<DiscordEvent> = new Collection();
|
||||||
|
@ -26,17 +25,6 @@ const discordREST = new REST().setToken(discordBotToken);
|
||||||
// const stripeClient = new Stripe(stripeToken, { typescript: true });
|
// const stripeClient = new Stripe(stripeToken, { typescript: true });
|
||||||
|
|
||||||
export async function main() {
|
export async function main() {
|
||||||
// Connect to the databases
|
|
||||||
try {
|
|
||||||
mongoose.connection.once("open", () => {
|
|
||||||
console.info("[Info - Database] Connected to MongoDB");
|
|
||||||
})
|
|
||||||
// TODO: Fetch the MongoDB URI from the config file
|
|
||||||
await mongoose.connect("mongodb://localhost:27017/crra-main", {});
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`[Error - Database] Failed to connect to MongoDB: ${error}`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
// Load Discord interaction commands
|
// Load Discord interaction commands
|
||||||
for (const Command of Object.values(DiscordInteractionCommandsIndex)) {
|
for (const Command of Object.values(DiscordInteractionCommandsIndex)) {
|
||||||
const instance = new Command();
|
const instance = new Command();
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
import { SlashCommandBuilder, ChatInputCommandInteraction } from "discord.js";
|
import { SlashCommandBuilder, ChatInputCommandInteraction } from "discord.js";
|
||||||
import { guildID } from "../config.json";
|
|
||||||
|
|
||||||
export default abstract class DiscordInteractionCommand {
|
export default abstract class DiscordInteractionCommand {
|
||||||
public name: string;
|
public name: string;
|
||||||
public description: string;
|
public description: string;
|
||||||
public builder: SlashCommandBuilder;
|
public builder: SlashCommandBuilder;
|
||||||
|
|
||||||
protected 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;
|
||||||
|
@ -15,9 +12,7 @@ export default abstract class DiscordInteractionCommand {
|
||||||
|
|
||||||
this.builder.setName(this.name);
|
this.builder.setName(this.name);
|
||||||
this.builder.setDescription(this.description);
|
this.builder.setDescription(this.description);
|
||||||
|
|
||||||
this.GUILD_ID = guildID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract execute(interaction: ChatInputCommandInteraction): Error | Promise<void | any>;
|
public abstract execute(interaction: ChatInputCommandInteraction): Error | Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import Partner, {
|
||||||
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 } from "discord.js";
|
||||||
import { guildID } from "../config.json";
|
import { guildID } from "../config.json";
|
||||||
|
|
||||||
export interface PartnerOptions {
|
export interface PartnerOptions {
|
||||||
|
@ -17,11 +17,6 @@ export interface PartnerOptions {
|
||||||
directReport: Partner | string;
|
directReport: Partner | string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FormatNameOptions {
|
|
||||||
text: 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
|
||||||
|
@ -58,26 +53,4 @@ export default class MemberUtil {
|
||||||
if (member.additionalAcknowledgement?.includes(acknowledgement)) throw new Error("This member already has this acknowledgement.")
|
if (member.additionalAcknowledgement?.includes(acknowledgement)) throw new Error("This member already has this acknowledgement.")
|
||||||
return MemberModel.updateOne({ discordID: member.discordID }, { $push: { additionalAcknowledgement: 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 {
|
|
||||||
// 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: "https://static.libraryofcode.org/library_of_code_redeg.png"
|
|
||||||
}
|
|
||||||
} 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: "https://static.libraryofcode.org/library_of_code_redeg.png"
|
|
||||||
}
|
|
||||||
} else { // otherwise, just set the author to the member's display name
|
|
||||||
return {
|
|
||||||
text: target.displayName,
|
|
||||||
iconURL: target.displayAvatarURL()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue