|
|
|
@ -186,11 +186,20 @@ interface TranscriptSchema {
|
|
|
|
createdBy: TranscriptAuthor;
|
|
|
|
createdBy: TranscriptAuthor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface findDocSchema { channelID:string, messageID: string; transcript: string }
|
|
|
|
|
|
|
|
|
|
|
|
export class Transcript {
|
|
|
|
export class Transcript {
|
|
|
|
transcripts: Collection<TranscriptSchema>;
|
|
|
|
transcripts: Collection<TranscriptSchema>;
|
|
|
|
|
|
|
|
messageToTranscript: Collection<findDocSchema>;
|
|
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
constructor() {
|
|
|
|
this.transcripts = database.collection<TranscriptSchema>("transcripts");
|
|
|
|
this.transcripts = database.collection<TranscriptSchema>("transcripts");
|
|
|
|
|
|
|
|
this.messageToTranscript = database.collection<findDocSchema>("messageToTranscript");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async upload(data: findDocSchema) {
|
|
|
|
|
|
|
|
// console.log("Transcript upload")
|
|
|
|
|
|
|
|
await this.messageToTranscript.insertOne(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async create(transcript: Omit<TranscriptSchema, "code">) {
|
|
|
|
async create(transcript: Omit<TranscriptSchema, "code">) {
|
|
|
|
@ -209,13 +218,84 @@ export class Transcript {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const doc = await this.transcripts.insertOne(Object.assign(transcript, { code: code }), collectionOptions);
|
|
|
|
const doc = await this.transcripts.insertOne(Object.assign(transcript, { code: code }), collectionOptions);
|
|
|
|
if(doc.acknowledged) return [code, key, iv];
|
|
|
|
if(doc.acknowledged) {
|
|
|
|
|
|
|
|
client.database.eventScheduler.schedule("deleteTranscript", (Date.now() + 1000 * 60 * 60 * 24 * 7).toString(), { guild: transcript.guild, code: code, iv: iv, key: key });
|
|
|
|
|
|
|
|
return [code, key, iv];
|
|
|
|
|
|
|
|
}
|
|
|
|
else return [null, null, null];
|
|
|
|
else return [null, null, null];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async delete(code: string) {
|
|
|
|
|
|
|
|
// console.log("Transcript delete")
|
|
|
|
|
|
|
|
await this.transcripts.deleteOne({ code: code });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async deleteAll(guild: string) {
|
|
|
|
|
|
|
|
// console.log("Transcript delete")
|
|
|
|
|
|
|
|
const filteredDocs = await this.transcripts.find({ guild: guild }).toArray();
|
|
|
|
|
|
|
|
for (const doc of filteredDocs) {
|
|
|
|
|
|
|
|
await this.transcripts.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({ transcript: code }));
|
|
|
|
|
|
|
|
if(findDoc) {
|
|
|
|
|
|
|
|
const message = await ((client.channels.cache.get(findDoc.channelID)) as Discord.TextBasedChannel | null)?.messages.fetch(findDoc.messageID);
|
|
|
|
|
|
|
|
if(!message) return null;
|
|
|
|
|
|
|
|
const attachment = message.attachments.first();
|
|
|
|
|
|
|
|
if(!attachment) return null;
|
|
|
|
|
|
|
|
const transcript = (await fetch(attachment.url)).body;
|
|
|
|
|
|
|
|
if(!transcript) return null;
|
|
|
|
|
|
|
|
const reader = transcript.getReader();
|
|
|
|
|
|
|
|
let data: Uint8Array | null = null;
|
|
|
|
|
|
|
|
let allPacketsReceived = false;
|
|
|
|
|
|
|
|
while (!allPacketsReceived) {
|
|
|
|
|
|
|
|
const { value, done } = await reader.read();
|
|
|
|
|
|
|
|
if (done) {allPacketsReceived = true; continue;}
|
|
|
|
|
|
|
|
if(!data) {
|
|
|
|
|
|
|
|
data = value;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
data = new Uint8Array(Buffer.concat([data, value]));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!data) return null;
|
|
|
|
|
|
|
|
doc = JSON.parse(Buffer.from(data).toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!doc) return null;
|
|
|
|
|
|
|
|
return doc;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async read(code: string, key: string, iv: string) {
|
|
|
|
async read(code: string, key: string, iv: string) {
|
|
|
|
// console.log("Transcript read")
|
|
|
|
// console.log("Transcript read")
|
|
|
|
const doc = await this.transcripts.findOne({ code: code });
|
|
|
|
let doc: TranscriptSchema | null = await this.transcripts.findOne({ code: code });
|
|
|
|
|
|
|
|
let findDoc: findDocSchema | null = null;
|
|
|
|
|
|
|
|
if(!doc) findDoc = (await this.messageToTranscript.findOne({ transcript: code }));
|
|
|
|
|
|
|
|
if(findDoc) {
|
|
|
|
|
|
|
|
const message = await ((client.channels.cache.get(findDoc.channelID)) as Discord.TextBasedChannel | null)?.messages.fetch(findDoc.messageID);
|
|
|
|
|
|
|
|
if(!message) return null;
|
|
|
|
|
|
|
|
const attachment = message.attachments.first();
|
|
|
|
|
|
|
|
if(!attachment) return null;
|
|
|
|
|
|
|
|
const transcript = (await fetch(attachment.url)).body;
|
|
|
|
|
|
|
|
if(!transcript) return null;
|
|
|
|
|
|
|
|
const reader = transcript.getReader();
|
|
|
|
|
|
|
|
let data: Uint8Array | null = null;
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, no-constant-condition
|
|
|
|
|
|
|
|
while(true) {
|
|
|
|
|
|
|
|
const { value, done } = await reader.read();
|
|
|
|
|
|
|
|
if (done) break;
|
|
|
|
|
|
|
|
if(!data) {
|
|
|
|
|
|
|
|
data = value;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
data = new Uint8Array(Buffer.concat([data, value]));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!data) return null;
|
|
|
|
|
|
|
|
doc = JSON.parse(Buffer.from(data).toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
if(!doc) return null;
|
|
|
|
if(!doc) return null;
|
|
|
|
for(const message of doc.messages) {
|
|
|
|
for(const message of doc.messages) {
|
|
|
|
if(message.content) {
|
|
|
|
if(message.content) {
|
|
|
|
@ -226,14 +306,6 @@ export class Transcript {
|
|
|
|
return doc;
|
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async deleteAll(guild: string) {
|
|
|
|
|
|
|
|
// console.log("Transcript delete")
|
|
|
|
|
|
|
|
const filteredDocs = await this.transcripts.find({ guild: guild }).toArray();
|
|
|
|
|
|
|
|
for (const doc of filteredDocs) {
|
|
|
|
|
|
|
|
await this.transcripts.deleteOne({ code: doc.code });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async createTranscript(messages: Message[], interaction: MessageComponentInteraction | CommandInteraction, member: GuildMember) {
|
|
|
|
async createTranscript(messages: Message[], interaction: MessageComponentInteraction | CommandInteraction, member: GuildMember) {
|
|
|
|
const interactionMember = await interaction.guild?.members.fetch(interaction.user.id)
|
|
|
|
const interactionMember = await interaction.guild?.members.fetch(interaction.user.id)
|
|
|
|
const newOut: Omit<TranscriptSchema, "code"> = {
|
|
|
|
const newOut: Omit<TranscriptSchema, "code"> = {
|
|
|
|
|