made premium check faster. Added transcript endpoint, toHumanReadable function.
diff --git a/src/premium/attachmentLogs.ts b/src/premium/attachmentLogs.ts
index 3c583f2..b2c8391 100644
--- a/src/premium/attachmentLogs.ts
+++ b/src/premium/attachmentLogs.ts
@@ -8,6 +8,7 @@
import type { GuildTextBasedChannel, Message } from "discord.js";
export default async function logAttachment(message: Message): Promise<AttachmentLogSchema> {
+ if (message.guild) client.database.premium.hasPremium(message.guild.id).finally(() => {});
if (!message.guild) throw new Error("Tried to log an attachment in a non-guild message");
const { renderUser, renderChannel, renderDelta } = client.logger;
const attachments = [];
diff --git a/src/premium/createTranscript.ts b/src/premium/createTranscript.ts
index 20b790a..85e059f 100644
--- a/src/premium/createTranscript.ts
+++ b/src/premium/createTranscript.ts
@@ -8,83 +8,13 @@
TextChannel,
ButtonStyle,
User,
- ComponentType,
ThreadChannel
} from "discord.js";
import EmojiEmbed from "../utils/generateEmojiEmbed.js";
import getEmojiByName from "../utils/getEmojiByName.js";
-import { PasteClient, Publicity, ExpireDate } from "pastebin-api";
import client from "../utils/client.js";
import { messageException } from '../utils/createTemporaryStorage.js';
-const pbClient = new PasteClient(client.config.pastebinApiKey);
-
-interface TranscriptEmbed {
- title?: string;
- description?: string;
- fields?: {
- name: string;
- value: string;
- inline: boolean;
- }[];
- footer?: {
- text: string;
- iconURL?: string;
- };
-}
-
-interface TranscriptComponent {
- type: number;
- style?: ButtonStyle;
- label?: string;
- description?: string;
- placeholder?: string;
- emojiURL?: string;
-}
-
-interface TranscriptAuthor {
- username: string;
- discriminator: number;
- nickname?: string;
- id: string;
- iconURL?: string;
- topRole: {
- color: number;
- badgeURL?: string;
- }
-}
-
-interface TranscriptAttachment {
- url: string;
- filename: string;
- size: number;
- log?: string;
-}
-
-interface TranscriptMessage {
- id: string;
- author: TranscriptAuthor;
- content?: string;
- embeds?: TranscriptEmbed[];
- components?: TranscriptComponent[][];
- editedTimestamp?: number;
- createdTimestamp: number;
- flags?: string[];
- attachments?: TranscriptAttachment[];
- stickerURLs?: string[];
- referencedMessage?: string | [string, string, string];
-}
-
-interface Transcript {
- type: "ticket" | "purge"
- guild: string;
- channel: string;
- for: TranscriptAuthor
- messages: TranscriptMessage[];
- createdTimestamp: number;
- createdBy: TranscriptAuthor;
-}
-
const noTopic = new EmojiEmbed()
.setTitle("User not found")
.setDescription("There is no user associated with this ticket.")
@@ -114,175 +44,58 @@
)
));
- let out = "";
- messages.reverse().forEach((message) => {
- if (!message.author.bot) {
- const sentDate = new Date(message.createdTimestamp);
- out += `${message.author.username}#${message.author.discriminator} (${
- message.author.id
- }) [${sentDate.toUTCString()}]\n`;
- const lines = message.content.split("\n");
- lines.forEach((line) => {
- out += `> ${line}\n`;
- });
- out += "\n\n";
- }
- });
-
- const interactionMember = await interaction.guild?.members.fetch(interaction.user.id)
-
let topic
- let member: GuildMember | null = null;
+ let member: GuildMember = interaction.guild?.members.me!;
if (interaction.channel instanceof TextChannel) {
topic = interaction.channel.topic;
if (topic === null) return await interaction.reply({ embeds: [noTopic] });
- member = interaction.guild!.members.cache.get(topic.split(" ")[1]!) ?? null;
+ const mem = interaction.guild!.members.cache.get(topic.split(" ")[1]!);
+ if (mem) member = mem;
} else {
topic = interaction.channel.name;
const split = topic.split("-").map(p => p.trim()) as [string, string, string];
- member = interaction.guild!.members.cache.get(split[1]) ?? null;
- if (member === null) return await interaction.reply({ embeds: [noTopic] });
+ const mem = interaction.guild!.members.cache.get(split[1])
+ if (mem) member = mem;
}
-
- const newOut: Transcript = {
- type: "ticket",
- for: {
- username: member!.user.username,
- discriminator: parseInt(member!.user.discriminator),
- id: member!.user.id,
- topRole: {
- color: member!.roles.highest.color
- }
- },
- guild: interaction.guild!.id,
- channel: interaction.channel!.id,
- messages: [],
- createdTimestamp: Date.now(),
- createdBy: {
- username: interaction.user.username,
- discriminator: parseInt(interaction.user.discriminator),
- id: interaction.user.id,
- topRole: {
- color: interactionMember?.roles.highest.color ?? 0x000000
- }
- }
- }
- if(interactionMember?.roles.icon) newOut.createdBy.topRole.badgeURL = interactionMember.roles.icon.iconURL()!;
- messages.reverse().forEach((message) => {
- const msg: TranscriptMessage = {
- id: message.id,
- author: {
- username: message.author.username,
- discriminator: parseInt(message.author.discriminator),
- id: message.author.id,
- topRole: {
- color: message.member!.roles.highest.color
- }
- },
- createdTimestamp: message.createdTimestamp
- };
- if (message.member!.roles.icon) msg.author.topRole.badgeURL = message.member!.roles.icon.iconURL()!;
- if (message.content) msg.content = message.content;
- if (message.embeds.length > 0) msg.embeds = message.embeds.map(embed => {
- const obj: TranscriptEmbed = {};
- if (embed.title) obj.title = embed.title;
- if (embed.description) obj.description = embed.description;
- if (embed.fields.length > 0) obj.fields = embed.fields.map(field => {
- return {
- name: field.name,
- value: field.value,
- inline: field.inline ?? false
- }
- });
- if (embed.footer) obj.footer = {
- text: embed.footer.text,
- };
- if (embed.footer?.iconURL) obj.footer!.iconURL = embed.footer.iconURL;
- return obj;
- });
- if (message.components.length > 0) msg.components = message.components.map(component => component.components.map(child => {
- const obj: TranscriptComponent = {
- type: child.type
- }
- if (child.type === ComponentType.Button) {
- obj.style = child.style;
- obj.label = child.label ?? "";
- } else if (child.type > 2) {
- obj.placeholder = child.placeholder ?? "";
- }
- return obj
- }));
- if (message.editedTimestamp) msg.editedTimestamp = message.editedTimestamp;
- msg.flags = message.flags.toArray();
-
- if (message.stickers.size > 0) msg.stickerURLs = message.stickers.map(sticker => sticker.url);
- if (message.reference) msg.referencedMessage = [message.reference.guildId ?? "", message.reference.channelId, message.reference.messageId ?? ""];
- newOut.messages.push(msg);
- });
+ const newOut = await client.database.transcripts.createTranscript(messages, interaction, member);
const code = await client.database.transcripts.create(newOut);
- if(!code) return await interaction.reply({embeds: [new EmojiEmbed().setTitle("Error").setDescription("An error occurred while creating the transcript.").setStatus("Danger").setEmoji("CONTROL.BLOCKCROSS")]})
- let m: Message;
- if (out !== "") {
- const url = await pbClient.createPaste({
- code: out,
- expireDate: ExpireDate.Never,
- name:
- `Ticket Transcript ${
- member ? "for " + member.user.username + "#" + member.user.discriminator + " " : ""
- }` + `(Created at ${new Date(interaction.channel.createdTimestamp!).toDateString()})`,
- publicity: Publicity.Unlisted
- });
- const guildConfig = await client.database.guilds.read(interaction.guild!.id);
- m = (await interaction.reply({
- embeds: [
- new EmojiEmbed()
- .setTitle("Transcript")
- .setDescription(
- "You can view the transcript using the link below. You can save the link for later" +
- (guildConfig.logging.logs.channel
- ? ` or find it in <#${guildConfig.logging.logs.channel}> once you press delete below. After this the channel will be deleted.`
- : ".")
- )
- .setStatus("Success")
- .setEmoji("CONTROL.DOWNLOAD")
- ],
- components: [
- new ActionRowBuilder<ButtonBuilder>().addComponents([
- new ButtonBuilder().setLabel("View").setStyle(ButtonStyle.Link).setURL(url),
- new ButtonBuilder()
- .setLabel("Delete")
- .setStyle(ButtonStyle.Danger)
- .setCustomId("close")
- .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
- ])
- ],
- fetchReply: true
- })) as Message;
- } else {
- m = (await interaction.reply({
- embeds: [
- new EmojiEmbed()
- .setTitle("Transcript")
- .setDescription(
- "The transcript was empty, so no changes were made. To delete this ticket, press the delete button below."
- )
- .setStatus("Success")
- .setEmoji("CONTROL.DOWNLOAD")
- ],
- components: [
- new ActionRowBuilder<ButtonBuilder>().addComponents([
- new ButtonBuilder()
- .setLabel("Delete")
- .setStyle(ButtonStyle.Danger)
- .setCustomId("close")
- .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
- ])
- ],
- fetchReply: true
- })) as Message;
- }
+ if(!code) return await interaction.reply({
+ embeds: [
+ new EmojiEmbed()
+ .setTitle("Error")
+ .setDescription("An error occurred while creating the transcript.")
+ .setStatus("Danger")
+ .setEmoji("CONTROL.BLOCKCROSS")
+ ]
+ })
+ const guildConfig = await client.database.guilds.read(interaction.guild!.id);
+ const m: Message = (await interaction.reply({
+ embeds: [
+ new EmojiEmbed()
+ .setTitle("Transcript")
+ .setDescription(
+ "You can view the transcript using the link below. You can save the link for later" +
+ (guildConfig.logging.logs.channel
+ ? ` or find it in <#${guildConfig.logging.logs.channel}> once you press delete below. After this the channel will be deleted.`
+ : ".")
+ )
+ .setStatus("Success")
+ .setEmoji("CONTROL.DOWNLOAD")
+ ],
+ components: [
+ new ActionRowBuilder<ButtonBuilder>().addComponents([
+ new ButtonBuilder().setLabel("View").setStyle(ButtonStyle.Link).setURL(`https://clicks.codes/nucleus/transcript?code=${code}`),
+ new ButtonBuilder()
+ .setLabel("Delete")
+ .setStyle(ButtonStyle.Danger)
+ .setCustomId("close")
+ .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+ ])
+ ],
+ fetchReply: true
+ })) as Message;
let i;
try {
i = await m.awaitMessageComponent({
@@ -303,7 +116,7 @@
timestamp: Date.now()
},
list: {
- ticketFor: member ? entry(member.id, renderUser(member.user)) : entry(null, "*Unknown*"),
+ ticketFor: entry(member.id, renderUser(member.user)),
deletedBy: entry(interaction.member!.user.id, renderUser(interaction.member!.user as User)),
deleted: entry(Date.now().toString(), renderDelta(Date.now()))
},