Skip to content

Commit

Permalink
feat: transcript feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlauer-Hax committed Jun 11, 2023
1 parent ae6db8c commit ee6c741
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,8 @@ export default class DB {
legacyUserAgent: userevent.source.legacyUserAgent,
}, String.fromCodePoint(...(location.country as string).toUpperCase().split('').map(char => 127397 + char.charCodeAt(0))) + " " + location.city + " (" + location.timezone + ")", location.timezone];
}

async saveTranscript(transcript: any) {
await this.db.collection("@bbn/bot/transcripts").insertOne(transcript);
}
}
26 changes: 23 additions & 3 deletions interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,29 @@ export async function handleInteraction(interaction: Interaction, db: DB) {
interaction.reply({
content: `> We're closing your ticket. Please be patient.`,
});
setTimeout(() => {
channel.setParent("1110636030824042638", { lockPermissions: true });
}, 5000);
const messages = await channel.messages.fetch();
const transcript: any = {
messages: [],
closed: "Ticket closed by " + interaction.user.tag
};
for (const message of messages.values()) {
const obj: any = {
author: message.author.tag,
authorid: message.author.id,
content: message.content,
timestamp: message.createdTimestamp,
id: message.id,
};
if (message.attachments.size > 0) {
obj.attachments = message.attachments.map((a) => a.url);
}
if (message.embeds.length > 0) {
obj.embed = message.embeds[0].toJSON();
}
transcript.messages.push(obj);
}
await db.saveTranscript(transcript)
await channel.delete();
break;
}
}
Expand Down

0 comments on commit ee6c741

Please sign in to comment.