Fix memory leak (#47)

* a

* vulnerability?

* removeundici
This commit is contained in:
Jacob Nguyen
2024-09-06 23:24:22 -05:00
committed by GitHub
parent 5bb910dd3c
commit 41323c49ae
14 changed files with 46 additions and 106 deletions

View File

@@ -37,7 +37,6 @@
"string-similarity": "4.0.4",
"tesseract.js": "^5.0.4",
"trie-search": "1.4.1",
"undici": "5.22.0",
"winston": "3.8.2"
},
"devDependencies": {

View File

@@ -10,7 +10,6 @@ import {
Snowflake,
TextChannel,
} from "discord.js";
import { fetch } from "undici";
import { cooldown, publish } from "#plugins";
import { Resolver, slashCommand } from "#utils";

View File

@@ -19,7 +19,7 @@ export default commandModule({
}
const { channel, guild, client, user, member, message: msg } = ctx;
if (
["TOKEN", "process..env", "token"].some((e) => code.includes(e)) &&
["TOKEN", "process.env", "token"].some((e) => code.includes(e)) &&
ctx.user.id !== "697795666373640213"
)
return ctx.message.react("❌");

View File

@@ -1,5 +1,5 @@
import { commandModule, CommandType, scheduledTask } from "@sern/handler";
import { publish } from "#plugins";
import { ownerOnly, publish } from "#plugins";
import { ApplicationCommandOptionType, EmbedBuilder } from "discord.js";
import { db } from "../utils/db.js";
import { add, addDays, addHours, addMinutes, addSeconds } from "date-fns"
@@ -8,13 +8,13 @@ import { Timestamp } from "#utils";
export default commandModule({
type: CommandType.Slash,
description: "Start a giveaway involving users who react to the embed",
plugins: [publish()],
plugins: [publish(), ownerOnly()],
options: [
{
name: "item",
description: "The item that will be given away",
type: ApplicationCommandOptionType.String,
required: true
name: "item",
description: "The item that will be given away",
type: ApplicationCommandOptionType.String,
required: true
},
{
name: "time",
@@ -25,7 +25,7 @@ export default commandModule({
],
execute: async (ctx, { deps }) => {
const item = ctx.options.getString("item")
const timeLeftString = ctx.options.getString("time")
const timeLeftString = ctx.options.getString("time", true)
let timeUnit1
let timeLeft1
@@ -117,7 +117,8 @@ export default commandModule({
}).then(embedMessage => {
embedMessage.react("🎉")
setInterval(() => {
//checks if author reacted to itself
const selfReactionInterval = setInterval(() => {
const userReactions = embedMessage.reactions.cache.filter(reaction => reaction.users.cache.has(ctx.userId));
for (const reaction of userReactions.values()) {
@@ -157,9 +158,10 @@ export default commandModule({
embedMessage.edit({embeds: [embed]})
}
clearInterval(selfReactionInterval)
}, intervalTime)
})
db.prepare(`DELETE FROM entrees`).run()
}
})
})

View File

@@ -6,12 +6,10 @@ import {
TextInputStyle,
} from "discord.js";
import { existsSync, writeFileSync } from "fs";
import { createRequire } from "module";
import { Evo, Seren, TagList } from "#constants";
import { ownerOnly, publish } from "#plugins";
import type { TagData } from "typings";
import { slashCommand } from "#utils";
const require = createRequire(import.meta.url);
import { slashCommand, require } from "#utils";
export default slashCommand({
description: "Edit tags",

View File

@@ -1,6 +1,5 @@
import { ApplicationCommandOptionType, GuildMember } from "discord.js";
import { publish } from "#plugins";
import { fetch } from "undici";
import { readFileSync } from "fs";
import { slashCommand } from "#utils";

View File

@@ -1,10 +1,9 @@
import { eventModule, EventType } from "@sern/handler";
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, Message } from "discord.js";
import { createRequire } from "module";
import { FuzzyMatcher } from "../utils/FuzzyMatcher.js";
import type { TagData, TagMessage } from "typings";
import { TagList } from "#constants";
const require = createRequire(import.meta.url);
import { require } from '#utils'
const file: TagData[] = require(TagList);
export default eventModule({

View File

@@ -1,5 +1,4 @@
import "dotenv/config";
import * as config from './config.js'
import { Client, GatewayIntentBits, Partials } from "discord.js";
import { Sern, makeDependencies, Service } from "@sern/handler";
import { SernLogger } from "#utils";

View File

@@ -1,21 +0,0 @@
import { fetch } from "undici";
export async function upload(code: string, name?: string) {
const response = await fetch("https://sourceb.in/api/bins", {
body: JSON.stringify({
title: "Code",
description: "Because I am lazy",
files: [{ name, content: code, languageId: 378 }],
}),
method: "POST",
headers: {
"Content-Type": "application/json",
},
});
const data = (await response.json()) as PostData;
return `<https://sourceb.in/${data.key}>`;
}
interface PostData {
key: string;
}

View File

@@ -1,6 +0,0 @@
export function cutText(text: string) {
if (text.length > 100) {
return text.slice(0, 97) + "...";
}
return text;
}

View File

@@ -1,13 +1,40 @@
import { createRequire } from "node:module";
export * from "./FuzzyMatcher.js";
export * from "./Paginator.js";
export * from "./Resolver.js";
export * from "./TicTacToe.js";
export * from "./Timestamp.js";
export * from "./pagination.js";
export * from "./randomStatus.js";
export * from "./codeUpload.js";
export * from "./Logger.js";
export * from "./composable/slashCommand.js";
export * from "./require.js";
export * from "./cutText.js";
//export * from './SyncCommands.js';
export const require = createRequire(import.meta.url);
export function cutText(text: string) {
if (text.length > 100) {
return text.slice(0, 97) + "...";
}
return text;
}
export async function upload(code: string, name?: string) {
const response = await fetch("https://sourceb.in/api/bins", {
body: JSON.stringify({
title: "Code",
description: "Because I am lazy",
files: [{ name, content: code, languageId: 378 }],
}),
method: "POST",
headers: {
"Content-Type": "application/json",
},
});
const data = (await response.json()) as PostData;
return `<https://sourceb.in/${data.key}>`;
}
interface PostData {
key: string;
}

View File

@@ -1,27 +0,0 @@
import { ActivityType, Client, ClientPresenceStatus } from "discord.js";
const statues: [Exclude<ActivityType, ActivityType.Custom>, string, ClientPresenceStatus][] = [
[ActivityType.Watching, "the sern community", "online"],
[ActivityType.Listening, "Evo", "dnd"],
[ActivityType.Playing, "with @sern/cli", "idle"],
[ActivityType.Watching, "sern bots", "dnd"],
[ActivityType.Watching, "github stars go brrr", "online"],
[ActivityType.Listening, "Spotify", "dnd"],
[ActivityType.Listening, "what's bofa", "idle"],
];
export function randomStatus(client: Client) {
setInterval(() => {
const shuffledStatuses = shuffleArray(statues);
const [type, name, status] = [...shuffledStatuses].shift()!;
client.user!.setPresence({ activities: [{ name, type }], status });
}, 60_000);
}
function shuffleArray<T>(array: T[]) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return [...array];
}

View File

@@ -1,2 +0,0 @@
import { createRequire } from "module";
export const require = createRequire(import.meta.url);

View File

@@ -767,15 +767,6 @@ __metadata:
languageName: node
linkType: hard
"busboy@npm:^1.6.0":
version: 1.6.0
resolution: "busboy@npm:1.6.0"
dependencies:
streamsearch: ^1.1.0
checksum: 32801e2c0164e12106bf236291a00795c3c4e4b709ae02132883fe8478ba2ae23743b11c5735a0aae8afe65ac4b6ca4568b91f0d9fed1fdbc32ede824a73746e
languageName: node
linkType: hard
"cac@npm:^6.7.12":
version: 6.7.12
resolution: "cac@npm:6.7.12"
@@ -2409,7 +2400,6 @@ __metadata:
trie-search: 1.4.1
tsup: 6.7.0
typescript: 5.0.4
undici: 5.22.0
winston: 3.8.2
languageName: unknown
linkType: soft
@@ -2531,13 +2521,6 @@ __metadata:
languageName: node
linkType: hard
"streamsearch@npm:^1.1.0":
version: 1.1.0
resolution: "streamsearch@npm:1.1.0"
checksum: 1cce16cea8405d7a233d32ca5e00a00169cc0e19fbc02aa839959985f267335d435c07f96e5e0edd0eadc6d39c98d5435fb5bbbdefc62c41834eadc5622ad942
languageName: node
linkType: hard
"string-similarity@npm:4.0.4":
version: 4.0.4
resolution: "string-similarity@npm:4.0.4"
@@ -2844,15 +2827,6 @@ __metadata:
languageName: node
linkType: hard
"undici@npm:5.22.0":
version: 5.22.0
resolution: "undici@npm:5.22.0"
dependencies:
busboy: ^1.6.0
checksum: 8dc55240a60ae7680798df344e8f46ad0f872ed0fa434fb94cc4fd2b5b2f8053bdf11994d15902999d3880f9bf7cd875a2e90883d2702bf0f366dacd9cbf3fc6
languageName: node
linkType: hard
"undici@npm:5.27.2":
version: 5.27.2
resolution: "undici@npm:5.27.2"