Skip to content

Commit 7cb9f14

Browse files
committed
chore: update to latest discordjs and node.
also changed from ts-node to tsx
1 parent aec8779 commit 7cb9f14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+6490
-6009
lines changed

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"**/dist": true
1414
},
1515
"editor.codeActionsOnSave": {
16-
"source.fixAll.eslint": true
16+
"source.fixAll.eslint": "always"
1717
},
1818
"deno.enable": false
1919
}

package.json

+27-28
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"main": "index.js",
66
"type": "module",
77
"engines": {
8-
"node": "16.18.1"
8+
"node": "20.12.2"
99
},
1010
"scripts": {
11-
"dev": "cross-env TS_NODE_FILES=true TS_NODE_PROJECT=\"./tsconfig.json\" nodemon -r dotenv/config -x node --experimental-specifier-resolution=node --loader ts-node/esm ./src/index.ts",
11+
"dev": "tsx watch -r dotenv/config ./src/index.ts",
1212
"start": "node build/index.js",
1313
"build": "tsc",
1414
"lint": "eslint src && tsc --noEmit",
@@ -23,41 +23,40 @@
2323
"author": "",
2424
"license": "ISC",
2525
"dependencies": {
26-
"@mdn/browser-compat-data": "5.2.17",
27-
"@sentry/node": "7.20.0",
28-
"compare-versions": "4.1.3",
26+
"@mdn/browser-compat-data": "5.5.49",
27+
"@sentry/node": "8.27.0",
28+
"compare-versions": "6.1.1",
2929
"cross-env": "^7.0.3",
30-
"date-fns": "2.28.0",
31-
"discord.js": "13.8.1",
32-
"dom-parser": "0.1.6",
30+
"date-fns": "3.6.0",
31+
"discord.js": "14.15.3",
32+
"dom-parser": "1.1.5",
3333
"domyno": "1.0.1",
34-
"fuse.js": "6.6.2",
35-
"html-entities": "2.3.3",
34+
"fuse.js": "7.0.0",
35+
"html-entities": "2.5.2",
3636
"lodash-es": "4.17.21",
37-
"mongoose": "6.4.6",
37+
"mongoose": "8.5.4",
3838
"node-cache": "5.1.2",
39-
"node-fetch": "3.2.10",
40-
"node-html-parser": "5.3.3",
41-
"ts-node": "10.9.1",
42-
"typescript": "4.7.4"
39+
"node-fetch": "3.3.2",
40+
"node-html-parser": "6.1.13",
41+
"typescript": "5.5.4"
4342
},
4443
"devDependencies": {
45-
"@sentry/types": "7.20.0",
46-
"@types/dom-parser": "0.1.1",
44+
"@sentry/types": "8.27.0",
45+
"@types/dom-parser": "0.1.4",
4746
"@types/html-entities": "1.3.4",
48-
"@types/jest": "28.1.8",
47+
"@types/jest": "29.5.12",
4948
"@types/mongoose": "5.11.97",
50-
"@types/node": "18.0.0",
49+
"@types/node": "22.5.0",
5150
"@types/node-fetch": "3.0.3",
52-
"dotenv": "16.0.1",
53-
"eslint-config-galex": "4.3.2",
54-
"eslint": "8.28.0",
55-
"husky": "8.0.1",
56-
"jest": "28.1.3",
57-
"lint-staged": "13.0.3",
58-
"nodemon": "2.0.20",
59-
"prettier": "2.7.1",
60-
"ts-jest": "28.0.8"
51+
"dotenv": "16.4.5",
52+
"eslint": "8.57.0",
53+
"eslint-config-galex": "4.5.2",
54+
"husky": "9.1.5",
55+
"jest": "29.7.0",
56+
"lint-staged": "15.2.9",
57+
"prettier": "3.3.3",
58+
"ts-jest": "29.2.5",
59+
"tsx": "^4.19.0"
6160
},
6261
"husky": {
6362
"hooks": {

src/types.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import type {
22
ChatInputApplicationCommandData,
3+
ChatInputCommandInteraction,
34
Client,
45
CommandInteraction,
56
Guild,
67
} from 'discord.js';
78

89
export type CommandDataWithHandler = ChatInputApplicationCommandData & {
9-
handler: (client: Client, interaction: CommandInteraction) => Promise<void>;
10+
handler: (client: Client, interaction: ChatInputCommandInteraction) => Promise<void>;
1011
onAttach?: (client: Client) => void;
1112
guildValidate?: (guild: Guild) => boolean;
1213
};

src/v2/autorespond/code_parsing/hasVarInSource.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export function hasVarInSource(source: string): boolean {
88
ts.ScriptTarget.Latest,
99
true
1010
);
11+
console.group({ source })
1112
return !!sourceFile.forEachChild(visit);
1213
}
1314

src/v2/autorespond/code_parsing/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ const jsCodeBlocks = createCodeBlockCapturer([
1313
'typescript',
1414
]);
1515

16+
const tap = <T>(x: T): T => {
17+
console.log(x)
18+
return x
19+
}
1620
const getFirstVar = pipe([jsCodeBlocks, pluck('code'), some(hasVarInSource)]);
1721

1822
const messageFor = (userId: string) => `
@@ -24,6 +28,8 @@ export function detectVar(msg: Message): boolean {
2428
return;
2529
}
2630

31+
console.log(msg.content, msg.cleanContent)
32+
2733
const { content, channel, author } = msg;
2834

2935
if (getFirstVar(content)) {
+26-30
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
1-
import { MessageButton } from 'discord.js';
2-
import { MessageActionRow, MessageSelectMenu } from 'discord.js';
3-
import type { User, MessageOptions } from 'discord.js';
4-
import type { EmbedField, Collection } from 'discord.js';
1+
import { ButtonBuilder, MessageReplyOptions } from 'discord.js';
2+
import { ActionRowBuilder, UserSelectMenuBuilder } from 'discord.js';
3+
import { User, MessagePayload, ButtonStyle } from 'discord.js';
4+
import type { EmbedField, Collection, MessageActionRowComponentBuilder } from 'discord.js';
55

66
import { clampLength } from '../../utils/clampStr.js';
77
import { createEmbed } from '../../utils/discordTools.js';
88

99
export function createResponse(
1010
thankedUsers: Collection<string, User>,
1111
authorId: string
12-
): MessageOptions {
12+
): MessageReplyOptions {
1313
const title = `Point${thankedUsers.size === 1 ? '' : 's'} received!`;
1414

15-
const description = `<@!${authorId}> has given a point to ${
16-
thankedUsers.size === 1
17-
? `<@!${thankedUsers.first().id}>`
18-
: 'the users mentioned below'
19-
}!`;
15+
const description = `<@!${authorId}> has given a point to ${thankedUsers.size === 1
16+
? `<@!${thankedUsers.first().id}>`
17+
: 'the users mentioned below'
18+
}!`;
2019

2120
const fields: EmbedField[] =
2221
thankedUsers.size > 1
2322
? [...thankedUsers].map(([, u], i) => ({
24-
inline: false,
25-
name: `${(i + 1).toString()}.`,
26-
value: `<@!${u.id}>`,
27-
}))
23+
inline: false,
24+
name: `${(i + 1).toString()}.`,
25+
value: `<@!${u.id}>`,
26+
}))
2827
: [];
2928

3029
const output = createEmbed({
@@ -39,23 +38,20 @@ export function createResponse(
3938
return {
4039
embeds: [output],
4140
components: [
42-
new MessageActionRow().addComponents(
41+
new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(
4342
thankedUsers.size > 1
44-
? new MessageSelectMenu()
45-
.setCustomId(`thanks🤔${authorId}🤔select`)
46-
.setPlaceholder('Accidentally Thank someone? Un-thank them here!')
47-
.setMinValues(1)
48-
.setOptions(
49-
thankedUsers.map(user => ({
50-
label: clampLength(user.username, 25),
51-
value: user.id,
52-
}))
53-
)
54-
: new MessageButton()
55-
.setCustomId(`thanks🤔${authorId}🤔${thankedUsers.first().id}`)
56-
.setStyle('SECONDARY')
57-
.setLabel('This was an accident, UNDO!')
43+
? new UserSelectMenuBuilder()
44+
.setCustomId(`thanks🤔${authorId}🤔select`)
45+
.setPlaceholder('Accidentally Thank someone? Un-thank them here!')
46+
.setMinValues(1)
47+
.setDefaultUsers(
48+
...thankedUsers.keys()
49+
)
50+
: new ButtonBuilder()
51+
.setCustomId(`thanks🤔${authorId}🤔${thankedUsers.first().id}`)
52+
.setStyle(ButtonStyle.Secondary)
53+
.setLabel('This was an accident, UNDO!')
5854
),
5955
],
60-
};
56+
}
6157
}

src/v2/autorespond/thanks/db_model.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import type { Document } from 'mongoose';
2-
import mongoose from 'mongoose';
1+
import { Schema, model } from 'mongoose';
32

4-
const { model, Schema } = mongoose;
53

6-
const schema = new Schema(
4+
const schema = new Schema<ThanksInteractionType>(
75
{
86
guild: {
97
required: true,
@@ -34,7 +32,7 @@ export const ThanksInteraction = model<ThanksInteractionType>(
3432
'thanksMessageInteraction',
3533
schema
3634
);
37-
export type ThanksInteractionType = Document & {
35+
export type ThanksInteractionType = {
3836
guild: string;
3937
thanker: string;
4038
channel: string;

src/v2/autorespond/thanks/index.ts

+25-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { MessageActionRow, MessageSelectMenu } from 'discord.js';
2-
import type { Message, TextChannel } from 'discord.js';
1+
import { ActionRowBuilder, ChannelType, EmbedBuilder, MessageActionRowComponentBuilder, StringSelectMenuBuilder, } from 'discord.js';
2+
import { ComponentType, Message, TextChannel } from 'discord.js';
33
import type { Client } from 'discord.js';
44

55
import { POINT_LIMITER_IN_MINUTES } from '../../env.js';
@@ -41,7 +41,7 @@ const handleThanks = async (msg: Message): Promise<void> => {
4141
const reply = await getReply(msg);
4242
if (botId || (msg.mentions.users.size === 0 && !reply)) {
4343
if (
44-
['GUILD_PRIVATE_THREAD','GUILD_PUBLIC_THREAD'].includes(msg.channel.type)
44+
[ChannelType.PrivateThread, ChannelType.PublicThread].includes(msg.channel.type)
4545
) {
4646
await handleThreadThanks(msg);
4747
}
@@ -118,9 +118,8 @@ const handleThanks = async (msg: Message): Promise<void> => {
118118
value: `<@!${u.id}>\n${diff} minute${diff === 1 ? '' : 's'}.`,
119119
};
120120
}),
121-
footerText: `You can only give a point to a user every ${POINT_LIMITER_IN_MINUTES} minute${
122-
Number.parseInt(POINT_LIMITER_IN_MINUTES) === 1 ? '' : 's'
123-
}.`,
121+
footerText: `You can only give a point to a user every ${POINT_LIMITER_IN_MINUTES} minute${Number.parseInt(POINT_LIMITER_IN_MINUTES) === 1 ? '' : 's'
122+
}.`,
124123
provider: 'spam',
125124
title: 'Cooldown alert!',
126125
}).embed,
@@ -149,7 +148,7 @@ const handleThanks = async (msg: Message): Promise<void> => {
149148

150149
function attachUndoThanksListener(client: Client): void {
151150
client.on('interactionCreate', async interaction => {
152-
if (!(interaction.isButton() || interaction.isSelectMenu())) {
151+
if (!(interaction.isButton() || interaction.isStringSelectMenu())) {
153152
return;
154153
}
155154
const id = interaction.customId;
@@ -170,7 +169,7 @@ function attachUndoThanksListener(client: Client): void {
170169

171170
await interaction.deferReply({ ephemeral: true });
172171

173-
const thanksInteraction: ThanksInteractionType =
172+
const thanksInteraction =
174173
await ThanksInteraction.findOne({
175174
responseMsgId: msgId,
176175
});
@@ -209,23 +208,32 @@ function attachUndoThanksListener(client: Client): void {
209208
)) as TextChannel;
210209
if (thanksInteraction.thankees.length === 0) {
211210
textChannel.messages.delete(thanksInteraction.responseMsgId);
212-
thanksInteraction.delete();
211+
ThanksInteraction.deleteOne({ _id: thanksInteraction._id })
213212
} else {
214213
const oldMsg = await textChannel.messages.fetch(msgId);
215-
oldMsg.embeds[0].fields = oldMsg.embeds[0].fields
216-
.filter(item => !removeThankees.includes(item.value.slice(3, -1)))
217-
.map((item, x) => ({ ...item, name: `${x + 1}` }));
218-
219-
const oldSelect = oldMsg.components[0].components[0] as MessageSelectMenu;
214+
const updatedEmbeds = [
215+
new EmbedBuilder(
216+
oldMsg.embeds[0]
217+
).setFields(
218+
oldMsg.embeds[0].fields
219+
.filter(item => !removeThankees.includes(item.value.slice(3, -1)))
220+
.map((item, x) => ({ ...item, name: `${x + 1}` }))
221+
),
222+
...oldMsg.embeds.slice(1)
223+
]
224+
225+
226+
const oldSelect = oldMsg.components[0].components[0];
227+
if (oldSelect.type !== ComponentType.StringSelect) throw new Error()
220228
const nuOptions = oldSelect.options
221229
.filter(item => !removeThankees.includes(item.value))
222230
.map(({ label, value }) => ({ label, value }));
223231

224232
oldMsg.edit({
225-
embeds: oldMsg.embeds,
233+
embeds: updatedEmbeds,
226234
components: [
227-
new MessageActionRow().addComponents(
228-
new MessageSelectMenu(oldSelect)
235+
new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(
236+
new StringSelectMenuBuilder(oldSelect)
229237
.setOptions(nuOptions)
230238
.setMaxValues(nuOptions.length)
231239
),

0 commit comments

Comments
 (0)