Please look over - not for production
diff --git a/src/utils/confirmationMessage.ts b/src/utils/confirmationMessage.ts
index 05c5494..5bfbfdb 100644
--- a/src/utils/confirmationMessage.ts
+++ b/src/utils/confirmationMessage.ts
@@ -1,4 +1,4 @@
-import { TextInputBuilder } from "discord.js";
+import { ButtonInteraction, TextInputBuilder } from "discord.js";
import Discord, {
CommandInteraction,
Message,
@@ -24,7 +24,7 @@
}
class confirmationMessage {
- interaction: CommandInteraction;
+ interaction: CommandInteraction | ButtonInteraction;
title = "";
emoji = "";
redEmoji: string | null = null;
@@ -37,7 +37,9 @@
inverted = false;
reason: string | null = null;
- constructor(interaction: CommandInteraction) {
+ modals: {buttonText: string, emoji: string, customId: string, modal: Discord.ModalBuilder, value: string | undefined}[] = [];
+
+ constructor(interaction: CommandInteraction | ButtonInteraction) {
this.interaction = interaction;
}
@@ -98,11 +100,17 @@
this.reason = reason;
return this;
}
+ addModal(buttonText: string, emoji: string, customId: string, current: string, modal: Discord.ModalBuilder) {
+ modal.setCustomId(customId);
+ this.modals.push({buttonText, emoji, customId, modal, value: current});
+ return this;
+ }
async send(editOnly?: boolean): Promise<{
success?: boolean;
cancelled?: boolean;
components?: Record<string, CustomBoolean<unknown>>;
newReason?: string;
+ modals?: {buttonText: string, emoji: string, customId: string, modal: Discord.ModalBuilder, value: string | undefined}[];
}> {
let cancelled = false;
let success: boolean | undefined = undefined;
@@ -131,6 +139,16 @@
if (v.emoji !== undefined) button.setEmoji(getEmojiByName(v.emoji, "id"));
fullComponents.push(button);
});
+ for (const modal of this.modals) {
+ fullComponents.push(
+ new Discord.ButtonBuilder()
+ .setCustomId(modal.customId)
+ .setLabel(modal.buttonText)
+ .setStyle(ButtonStyle.Primary)
+ .setEmoji(getEmojiByName(modal.emoji, "id"))
+ .setDisabled(false)
+ );
+ }
if (this.reason !== null)
fullComponents.push(
new Discord.ButtonBuilder()
@@ -183,7 +201,6 @@
m = (await this.interaction.reply(object)) as unknown as Message;
}
} catch (e) {
- console.log(e);
cancelled = true;
continue;
}
@@ -195,7 +212,7 @@
time: 300000
});
} catch (e) {
- success = false;
+ success = false
break;
}
if (component.customId === "yes") {
@@ -273,6 +290,46 @@
returnComponents = true;
continue;
}
+ } else if (this.modals.map((m) => m.customId).includes(component.customId)) {
+ const chosenModal = this.modals.find((component => m => m.customId === component.customId)(component));
+ await component.showModal(chosenModal!.modal);
+ await this.interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setTitle(this.title)
+ .setDescription("Modal opened. If you can't see it, click back and try again.")
+ .setStatus(this.color)
+ .setEmoji(this.emoji)
+ ],
+ components: [
+ new ActionRowBuilder<Discord.ButtonBuilder>().addComponents(
+ new ButtonBuilder()
+ .setLabel("Back")
+ .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
+ .setStyle(ButtonStyle.Primary)
+ .setCustomId("back")
+ )
+ ]
+ });
+ let out;
+ try {
+ out = (await modalInteractionCollector(
+ m,
+ this.interaction.user
+ )) as Discord.ModalSubmitInteraction | null;
+ } catch (e) {
+ console.log(e);
+ cancelled = true;
+ continue;
+ }
+ if (out === null || out.isButton()) {
+ continue;
+ }
+ if (out instanceof ModalSubmitInteraction) {
+ chosenModal!.value = out.fields.getTextInputValue("default");
+ }
+ returnComponents = true;
+ continue;
} else {
component.deferUpdate();
this.customButtons[component.customId]!.active = !this.customButtons[component.customId]!.active;
@@ -297,17 +354,19 @@
],
components: []
});
- return { success: false };
+ return { success: false, cancelled: returnValue.cancelled ?? false };
}
if (returnComponents || success !== undefined) returnValue.components = this.customButtons;
if (success !== undefined) returnValue.success = success;
if (newReason) returnValue.newReason = newReason;
+ returnValue.modals = this.modals;
+ const modals = this.modals;
const typedReturnValue = returnValue as
| { cancelled: true }
- | { success: boolean; components: Record<string, CustomBoolean<unknown>>; newReason?: string }
- | { newReason: string; components: Record<string, CustomBoolean<unknown>> }
- | { components: Record<string, CustomBoolean<unknown>> };
+ | { success: boolean; components: Record<string, CustomBoolean<unknown>>; modals: typeof modals; newReason?: string }
+ | { newReason: string; components: Record<string, CustomBoolean<unknown>>; modals: typeof modals }
+ | { components: Record<string, CustomBoolean<unknown>>; modals: typeof modals };
return typedReturnValue;
}
diff --git a/src/utils/database.ts b/src/utils/database.ts
index 75a79d9..62aee7c 100644
--- a/src/utils/database.ts
+++ b/src/utils/database.ts
@@ -14,14 +14,17 @@
import _ from "lodash";
import defaultData from "../config/default.js";
-const username = encodeURIComponent(config.mongoOptions.username);
-const password = encodeURIComponent(config.mongoOptions.password);
+let username, password;
+
+// @ts-expect-error
+if (Object.keys(config.mongoOptions).includes("username")) username = encodeURIComponent(config.mongoOptions.username);
+// @ts-expect-error
+if (Object.keys(config.mongoOptions).includes("password")) password = encodeURIComponent(config.mongoOptions.password);
const mongoClient = new MongoClient(
username
- ? `mongodb://${username}:${password}@${config.mongoOptions.host}?authMechanism=DEFAULT`
- : `mongodb://${config.mongoOptions.host}`,
- { authSource: config.mongoOptions.authSource }
+ ? `mongodb://${username}:${password}@${config.mongoOptions.host}?authMechanism=DEFAULT&authSource=${config.mongoOptions.authSource}`
+ : `mongodb://${config.mongoOptions.host}`
);
await mongoClient.connect();
const database = mongoClient.db();
@@ -221,7 +224,7 @@
interface findDocSchema {
channelID: string;
messageID: string;
- code: string;
+ transcript: string;
}
export class Transcript {
@@ -284,20 +287,16 @@
async deleteAll(guild: string) {
// console.log("Transcript delete")
const filteredDocs = await this.transcripts.find({ guild: guild }).toArray();
- const filteredDocs1 = await this.messageToTranscript.find({ guild: guild }).toArray();
for (const doc of filteredDocs) {
await this.transcripts.deleteOne({ code: doc.code });
}
- for (const doc of filteredDocs1) {
- await this.messageToTranscript.deleteOne({ code: doc.code });
- }
}
async readEncrypted(code: string) {
// console.log("Transcript read")
let doc: TranscriptSchema | null = await this.transcripts.findOne({ code: code });
let findDoc: findDocSchema | null = null;
- if (!doc) findDoc = await this.messageToTranscript.findOne({ code: code });
+ if (!doc) findDoc = await this.messageToTranscript.findOne({ transcript: code });
if (findDoc) {
const message = await (
client.channels.cache.get(findDoc.channelID) as Discord.TextBasedChannel | null
@@ -334,7 +333,7 @@
let doc: TranscriptSchema | null = await this.transcripts.findOne({ code: code });
let findDoc: findDocSchema | null = null;
console.log(doc);
- if (!doc) findDoc = await this.messageToTranscript.findOne({ code: code });
+ if (!doc) findDoc = await this.messageToTranscript.findOne({ transcript: code });
if (findDoc) {
const message = await (
client.channels.cache.get(findDoc.channelID) as Discord.TextBasedChannel | null
@@ -837,6 +836,10 @@
}
}
+export class Plugins {
+
+}
+
export interface GuildConfig {
id: string;
version: number;