Skip to content

Conversation

@Simplyalex99
Copy link
Contributor

@Simplyalex99 Simplyalex99 commented Jun 15, 2025

description: This pull-request fixes #461 . The issue had to do with the addHandler function using mutated arrays or references rather than creating a new one resulting in an unexpected behaviour of the auto thread handler being added to new channels. In other words, adding a handler to one channel might affect other channels that share the same reference.

steps to reproduce

  1. Create a new channel in React Test Server and add it to channels constant ( using the testing-bug-thread channel)

const LOCAL_CHANNELS: Record<keyof typeof PRODUCTION_CHANNELS, string> = {
   newChannel: "1383553919950520450"
  helpReact: "926931785219207301",
helpJs:"950790460857794620"
 ...
};

const PRODUCTION_CHANNELS = {
  newChannel: "1383553919950520450"
  helpReact: "103696749012467712",
 helpJs:"950790460857794620"
  ...
};

  1. Create a new empty handler
import type { ChannelHandlers } from "../types/index.d.ts";
import { EmbedType } from "discord.js";
import { EMBED_COLOR } from "./commands.js";

export const messageScanner: ChannelHandlers = {
  handleMessage: async ({ msg }) => {
    if (msg.author.bot) return;

    const warningMsg = `Testing message`;
    await msg.reply({
      embeds: [
        {
          title: "Oops! Wrong Channel, Maybe?",
          type: EmbedType.Rich,
          description: warningMsg,
          color: EMBED_COLOR,
        },
      ],
    });


  },
};



  1. Add the new handler with the new channel ID and a shared channel auto thread ID like helpJs:
addHandler([CHANNELS.newChannel,CHANNELS.helpJs>], newHandler);

  1. Type in the testing-bug-thread channel , and a thread will be created:
thread-created

Actual Behaviour

New channels added will result in having shared handlers.

The expected behaviour

Any new channels added should not have other handlers added to them unless specified.

Solution

The solution now replaces .push and declaration with the spread operator.

// original
if (existingHandlers) {
      existingHandlers.push(...handlers);
    } else {
      channelHandlersById[channelId] = handlers;
    }
// solution
 if (existingHandlers) {
      // Create a new array to avoid mutating the existing one
      channelHandlersById[channelId] = [...existingHandlers, ...handlers];
    } else {
      channelHandlersById[channelId] = [...handlers];
    }

@kristersd kristersd merged commit e8f5d42 into reactiflux:main Jun 18, 2025
2 checks passed
Simplyalex99 added a commit to Simplyalex99/reactibot that referenced this pull request Jun 19, 2025
feat: added a job/introduction bot scanner

update: added more job keywords

update: removed job titles keywords and edge case

Removed job title keyword to prevent false positives, and to keep the bot solely for job posting related messages rather than intro and job postings. Removed unneeded edge case that could result in false negatives.

update: removed unneeded edge case

update: warning message

Added a more helpful feedback in case of job advice related posts using similar keywords such as full time or job opportunity.

update: added edge case for langs with dollar sign

Added an edge case for code blocks using dollar sign and refactored if statement.

fix: messages being deleted with partial job keywords rather than full.

fix: removed duplicate job keyword

feat(experimental): added a job/introduction bot detection (reactiflux#461)

* update: added more channels

* feat: added a job/introduction bot scanner

* update: added more job keywords

* update: removed job titles keywords and edge case

Removed job title keyword to prevent false positives, and to keep the bot solely for job posting related messages rather than intro and job postings. Removed unneeded edge case that could result in false negatives.

* update: removed unneeded edge case

* update: warning message

Added a more helpful feedback in case of job advice related posts using similar keywords such as full time or job opportunity.

* update: added edge case for langs with dollar sign

Added an edge case for code blocks using dollar sign and refactored if statement.

* fix: messages being deleted with partial job keywords rather than full.

* fix: removed duplicate job keyword

Revert "feat(experimental): added a job/introduction bot detection (reactiflux#461)"

This reverts commit f946770.

fix: Shared references causing auto thread to be added to new channels (reactiflux#464)

* fix: Shared references causing auto thread to be added to new channels

* fix: removed print statement

add: cross post command (reactiflux#465)

* add: cross post command

* update: description text

IS:00 fix: prettier lint issues (reactiflux#470)

update: organized channels , and removed introduction

refactor: renamed feature to job scanner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants