Skip to content

Commit

Permalink
memory leak go brrrrr
Browse files Browse the repository at this point in the history
  • Loading branch information
dispherical committed Oct 20, 2024
1 parent 1532bc8 commit cfb3169
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
23 changes: 20 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const app = new App({
Array.prototype.random = function () {
return this[Math.floor(Math.random() * this.length)];
};
var activeConnections = [];

(async () => {
const client = await createClient({
Expand Down Expand Up @@ -79,13 +80,29 @@ Array.prototype.random = function () {
await require("./commands/setaffinity")({ app, client, prisma });




wss.on('connection', function connection(ws) {
activeConnections.push(ws);

ws.on('close', () => {
const index = activeConnections.indexOf(ws);
if (index > -1) {
activeConnections.splice(index, 1);
}
});
});
function broadcastMessage(message) {
activeConnections.forEach((ws) => {
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify(message));
}
});
}
// This deletes and sends a new message to bypass the 10 day editing limit and to show up on the user's unread channel list
// This runs the same thing on startup
await require("./utils/redo")({ app, client, prisma });
// app.message functions go here
await require("./interactions/message")({ app, client, prisma, wss });

await require("./interactions/message")({ app, client, prisma, broadcastMessage });


setInterval(async function () {
Expand Down
6 changes: 2 additions & 4 deletions interactions/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const utils = require("../utils");
/**
* @param {{app: import('@slack/bolt').App, client: import('redis').RedisClientType}} param1
*/
module.exports = ({ app, client, wss }) => {
module.exports = ({ app, client, broadcastMessage }) => {
app.message(/.*/gim, async ({ message, say, body }) => {
if (message.channel == process.env.SLACK_CHANNEL)
await app.client.chat.delete({
Expand All @@ -12,9 +12,7 @@ module.exports = ({ app, client, wss }) => {
token: process.env.SLACK_BOT_TOKEN,
});
if (utils.blockedChannels.includes(message.channel)) return;
wss.on('connection', function connection(ws) {
ws.send(JSON.stringify(message));
});
broadcastMessage(message)
message.sort_ts = +new Date() / 1000.0;
client.lPush(
`${process.env.INSTANCE_ID || "production"}.messageCache`,
Expand Down

0 comments on commit cfb3169

Please sign in to comment.