Bug fixes and ~~performance~~ typing improvements
diff --git a/src/premium/attachmentLogs.ts b/src/premium/attachmentLogs.ts
index 899cd25..0c491b7 100644
--- a/src/premium/attachmentLogs.ts
+++ b/src/premium/attachmentLogs.ts
@@ -6,11 +6,8 @@
import addPlural from "../utils/plurals.js";
import type { Message } from "discord.js";
-export default async function logAttachment(
- message: Message
-): Promise<AttachmentLogSchema> {
- if (!message.guild)
- throw new Error("Tried to log an attachment in a non-guild message");
+export default async function logAttachment(message: Message): Promise<AttachmentLogSchema> {
+ if (!message.guild) throw new Error("Tried to log an attachment in a non-guild message");
const { renderUser, renderChannel, renderDelta } = client.logger;
const attachments = [];
for (const attachment of message.attachments.values()) {
@@ -24,11 +21,7 @@
}
const links = message.content.match(/https?:\/\/\S+/gi) ?? [];
for (const link of links) {
- if (
- link
- .toLowerCase()
- .match(/\.(jpg|jpeg|png|gif|gifv|webm|webp|mp4|wav|mp3|ogg)$/gi)
- ) {
+ if (link.toLowerCase().match(/\.(jpg|jpeg|png|gif|gifv|webm|webp|mp4|wav|mp3|ogg)$/gi)) {
attachments.push({
local: await saveAttachment(link),
url: link,
@@ -39,8 +32,7 @@
}
if (attachments.length === 0) return { files: [] };
if (client.database.premium.hasPremium(message.guild.id)) {
- const channel = (await client.database.guilds.read(message.guild.id))
- .logging.attachments.channel;
+ const channel = (await client.database.guilds.read(message.guild.id)).logging.attachments.channel;
if (!channel) {
singleNotify(
"noAttachmentLogChannel",
@@ -63,17 +55,13 @@
const m = await channelObj.send({
embeds: [
new EmojiEmbed()
- .setTitle(
- `${addPlural(attachments.length, "Attachment")} Sent`
- )
+ .setTitle(`${addPlural(attachments.length, "Attachment")} Sent`)
.setDescription(
keyValueList({
messageId: `\`${message.id}\``,
sentBy: renderUser(message.author),
sentIn: renderChannel(message.channel),
- sent: renderDelta(
- new Date(message.createdTimestamp)
- )
+ sent: renderDelta(new Date(message.createdTimestamp))
}) + `\n[[Jump to message]](${message.url})`
)
.setEmoji("ICONS.ATTACHMENT")
@@ -83,8 +71,7 @@
});
// await client.database.guilds.write(interaction.guild.id, {[`tags.${name}`]: value});
client.database.guilds.write(message.guild.id, {
- [`logging.attachments.saved.${message.channel.id}${message.id}`]:
- m.url
+ [`logging.attachments.saved.${message.channel.id}${message.id}`]: m.url
});
return { files: attachments, jump: m.url };
} else {
diff --git a/src/premium/createTranscript.ts b/src/premium/createTranscript.ts
index 3d7f4c6..5fbb8ad 100644
--- a/src/premium/createTranscript.ts
+++ b/src/premium/createTranscript.ts
@@ -1,4 +1,12 @@
-import { MessageActionRow, MessageButton, TextChannel } from "discord.js";
+import {
+ CommandInteraction,
+ DMChannel,
+ Message,
+ MessageActionRow,
+ MessageButton,
+ PartialGroupDMChannel,
+ TextChannel
+} from "discord.js";
import EmojiEmbed from "../utils/generateEmojiEmbed.js";
import getEmojiByName from "../utils/getEmojiByName.js";
import { PasteClient, Publicity, ExpireDate } from "pastebin-api";
@@ -7,35 +15,28 @@
const pbClient = new PasteClient(config.pastebinApiKey);
-export default async function (interaction) {
- const { log, NucleusColors, entry, renderUser, renderDelta } =
- client.logger;
+export default async function (interaction: CommandInteraction) {
+ if (interaction.channel === null) return;
+ if (interaction.channel instanceof DMChannel) return;
+ const { log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
- let messages = [];
- let deleted = 100;
+ let messages: Message[] = [];
+ let deletedCount: number;
- while (deleted === 100) {
- let fetched;
- await (interaction.channel as TextChannel).messages
- .fetch({ limit: 100 })
- .then(async (ms) => {
- fetched = await (interaction.channel as TextChannel).bulkDelete(
- ms,
- true
- );
- });
- deleted = fetched.size;
- if (fetched) {
- messages = messages.concat(fetched.map((m) => m));
- }
- }
+ do {
+ const fetched = await (interaction.channel as TextChannel).messages.fetch({ limit: 100 });
+ const deleted = await (interaction.channel as TextChannel).bulkDelete(fetched, true);
+ deletedCount = deleted.size;
+ messages = messages.concat(Array.from(deleted.values()));
+ } while (deletedCount === 100);
+
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`;
+ 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`;
@@ -43,24 +44,18 @@
out += "\n\n";
}
});
- const member = interaction.channel.guild.members.cache.get(
- interaction.channel.topic.split(" ")[0]
- );
+ const member = interaction.channel.guild.members.cache.get(interaction.channel.topic.split(" ")[0]);
let m;
if (out !== "") {
const url = await pbClient.createPaste({
code: out,
expireDate: ExpireDate.Never,
- name: `Ticket Transcript for ${member.user.username}#${
- member.user.discriminator
- } (Created at ${new Date(
+ name: `Ticket Transcript 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
- );
+ const guildConfig = await client.database.guilds.read(interaction.guild.id);
m = await interaction.reply({
embeds: [
new EmojiEmbed()
@@ -76,10 +71,7 @@
],
components: [
new MessageActionRow().addComponents([
- new MessageButton()
- .setLabel("View")
- .setStyle("LINK")
- .setURL(url),
+ new MessageButton().setLabel("View").setStyle("LINK").setURL(url),
new MessageButton()
.setLabel("Delete")
.setStyle("DANGER")
@@ -131,22 +123,10 @@
list: {
ticketFor: entry(
interaction.channel.topic.split(" ")[0],
- renderUser(
- (
- await interaction.guild.members.fetch(
- interaction.channel.topic.split(" ")[0]
- )
- ).user
- )
+ renderUser((await interaction.guild.members.fetch(interaction.channel.topic.split(" ")[0])).user)
),
- deletedBy: entry(
- interaction.member.user.id,
- renderUser(interaction.member.user)
- ),
- deleted: entry(
- new Date().getTime(),
- renderDelta(new Date().getTime())
- )
+ deletedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
+ deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
},
hidden: {
guild: interaction.guild.id