Skip to content

Exclude code blocks when looking for !command triggers - Fixes #412 #450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 14, 2025

Conversation

achyu-dev
Copy link
Contributor

I have tried to fix the issue #412 that is text in code block as comments.

The code I have used to fix this is Attached below -


// Helper functions to handle commands inside codeblocks
export function removeCodeBlocksAndQuotes(text: string): string {
  if (!text) return '';
  let filtered = text.replace(/```[\s\S]*?```/g, '');
  filtered = filtered.replace(/`[^`]+`/g, '');
  filtered = filtered.replace(/^>.*$/gm, '');
  filtered = filtered.replace(/>>>[\s\S]*?(?=\n\n|$)/g, '');
  filtered = filtered.replace(/\n{3,}/g, '\n\n').trim();
  
  return filtered;
}

export function isInsideCodeBlock(text: string, position: number): boolean {
  // Count backticks before position
  const beforeText = text.slice(0, position);
  const singleBackticks = (beforeText.match(/`/g) || []).length;
  const tripleBackticks = (beforeText.match(/```/g) || []).length;
  
  // Inside inline code block if odd number of single backticks
  if (singleBackticks % 2 !== 0) return true;
  
  // Inside multi-line code block if odd number of triple backticks
  if (tripleBackticks % 2 !== 0) return true;
  
  return false;
}

Copy link

what-the-diff bot commented Mar 2, 2025

PR Summary

  • Updated script execution in package.json
    The 'dev' script execution now runs 'dev:bot' and 'dev:test' instead of employing the wildcard notation. This gives better control and clarity over the scripts being executed.

  • Upgraded vitest version
    Bumped the version of vitest in our package dependencies from 1.6.0 to ^1.6.1. The update brings improvements and bug fixes.

  • Changes to commands handling

    • Enhanced the commandsList data specification to be exportable, facilitating its use in other modules.
    • New helper functions permit better command processing, including the ability to strip out code blocks and quotes from text and check the positions of commands within text.
  • Introduced thread activity check
    Added a new function to check for activity in threads. This increases our ability to monitor thread interactions.

  • Improved error handling in message deletion
    Errors during message deletion will now be caught and handled gracefully, reducing potential disruptions to service.

  • Robust Emoji Reaction Handling
    The handling of emoji reactions has been enhanced for reliability, including robust error handling and fetching user permissions more effectively.

  • New Test Suite
    A new test suite has been added to validate command handling, ensuring that each command behaves as expected and increases the overall code reliability.

@vcarl vcarl marked this pull request as ready for review March 14, 2025 16:31
@vcarl vcarl changed the title commands issue fixed - Fixed Issue #412 Exclude code blocks when looking for !command triggers - Fixes #412 Mar 14, 2025
@vcarl vcarl merged commit 460a034 into reactiflux:main Mar 14, 2025
2 checks passed
vcarl added a commit that referenced this pull request Mar 14, 2025
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