Skip to content

enh: Enhance message saving functionality and /channels command - #43

Merged
actionbrk merged 16 commits into
masterfrom
29-support-threads
Apr 22, 2025
Merged

actionbrk merged 16 commits into
masterfrom
29-support-threads

Conversation

@DonatienBaille

@DonatienBaille DonatienBaille commented Apr 14, 2025 •

Copy link
Copy Markdown
Collaborator
  • Refactor ChannelsCommand to improve text channel handling and pagination.
  • Introduce saveMessagesForGuild function for better message saving logic.
  • Add support for thread creation and deletion events.
  • Implement getAllTextChannels utility for fetching viewable text channels.
  • Update localization files for new responses.

This PR also:

  • Optimize channel deletion with batch delete
  • Improve error management when syncing guild messages on start
  • Enhance message saving and daily counters with atomic transactions

Closes #29
Closes #40

- Refactor ChannelsCommand to improve text channel handling and pagination.
- Introduce saveMessagesForGuild function for better message saving logic.
- Add support for thread creation and deletion events.
- Implement getAllTextChannels utility for fetching viewable text channels.
- Update localization files for new responses.
@DonatienBaille DonatienBaille added the enhancement New feature or request label Apr 14, 2025
@DonatienBaille DonatienBaille self-assigned this Apr 14, 2025
@DonatienBaille DonatienBaille linked an issue Apr 14, 2025 that may be closed by this pull request

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 9 out of 11 changed files in this pull request and generated no comments.

Files not reviewed (2)
  • src/locales/en-US.json: Language not supported
  • src/locales/fr.json: Language not supported
Comments suppressed due to low confidence (2)

src/commands/admin/savechannel.ts:37

  • Consider awaiting the saveMessagesForGuild call to properly handle errors and provide timely user feedback. If fire-and-forget is intentional, please document the rationale.
saveMessagesForGuild(interaction.guild!, undefined, interaction, channel.id);

src/commands/admin/save.ts:191

  • Ensure that using 'viewableChannels' (which may include non-text channels) to derive channel IDs for cleanup is the intended behavior, as it differs from the earlier use of the filtered text channels.
const channelsIds = viewableChannels.map((channel) => channel.id);

@DonatienBaille
DonatienBaille requested a review from Copilot April 14, 2025 23:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 11 out of 13 changed files in this pull request and generated no comments.

Files not reviewed (2)
  • src/locales/en-US.json: Language not supported
  • src/locales/fr.json: Language not supported
Comments suppressed due to low confidence (2)

src/database/bee-database.ts:16

  • Ensure that the immediate invocation of the transaction callback (using () after db.transaction) is fully supported by your database driver API and that error handling within the transaction is sufficient.
db.transaction(() => { ... })();

src/commands/admin/channels.ts:135

  • [nitpick] Consider adding a comment to explain the regex replacement for thread formatting to improve code clarity and maintainability.
.replace(/├ ([^\n]*)$/, "└ $1")

@DonatienBaille
DonatienBaille requested a review from Copilot April 15, 2025 00:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 11 out of 13 changed files in this pull request and generated 1 comment.

Files not reviewed (2)
  • src/locales/en-US.json: Language not supported
  • src/locales/fr.json: Language not supported

Comment thread src/commands/admin/channels.ts
@DonatienBaille
DonatienBaille requested a review from Copilot April 15, 2025 22:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 16 out of 19 changed files in this pull request and generated no comments.

Files not reviewed (3)
  • .dockerignore: Language not supported
  • src/locales/en-US.json: Language not supported
  • src/locales/fr.json: Language not supported
Comments suppressed due to low confidence (2)

src/database/bee-database.ts:16

  • Verify that the immediate invocation pattern (i.e. appending '()' after db.transaction) is supported by your DB library. If not, refactor to explicitly commit or rollback the transaction with proper error handling.
db.transaction(() => {

src/events/threads/thread-create.ts:8

  • [nitpick] Consider renaming the parameter 'newlyCreate' to 'isNewlyCreated' to enhance code readability and clarity.
async execute(thread: AnyThreadChannel, newlyCreate: boolean) {

@DonatienBaille
DonatienBaille requested a review from Copilot April 15, 2025 23:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances Abeille’s message saving functionality and channel management by refactoring command logic, improving database transactions, and adding support for thread events. Key changes include:

  • Refactored ChannelsCommand to support pagination and detailed channel/thread statistics.
  • Updated message saving flows with atomic transactions and improved filtering.
  • Added new event handlers for thread creation and deletion, along with documentation improvements.

Reviewed Changes

Copilot reviewed 19 out of 23 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/loaders.ts Added informative logging for locale loading
src/events/threads/thread-delete.ts Introduced thread deletion handling with message cleanup
src/events/threads/thread-create.ts Added thread creation event with asynchronous join logic
src/events/messages/message-create.ts Updated message saving logic using improved filtering
src/events/client-ready.ts Refactored guild message sync using Promise.all
src/database/bee-database.ts Wrapped inserts and updates in atomic transactions with counter updates
src/commands/admin/savechannel.ts Simplified channel save command by delegating to saveMessagesForGuild
src/commands/admin/save.ts Extended save functionality to filter messages by channel ID
src/commands/admin/channels.ts Implemented pagination and enhanced grouping of channel statistics
src/commands/activity/* Replaced deferred reply variable with direct await for clarity
docs/* and README.md Updated documentation to reflect new features and guidelines
CONTRIBUTING.md Added contributing guidelines and style conventions
Files not reviewed (4)
  • .dockerignore: Language not supported
  • .env.template: Language not supported
  • src/locales/en-US.json: Language not supported
  • src/locales/fr.json: Language not supported
Comments suppressed due to low confidence (1)

src/commands/admin/channels.ts:240

  • [nitpick] While updating button states for pagination, ensure that edge cases (such as dynamic changes to the number of pages) are handled to avoid potential UI inconsistencies.
row.components[0]!.setDisabled(currentPage === 0).setLabel("◀");

// Atomic update with check to prevent negative counter
const updateStatement = db.query(`
UPDATE messageday
SET count = MAX(0, count ${isDelete ? "-" : "+"} 1)

Copilot AI Apr 15, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The inline arithmetic operation in the SQL query may be misinterpreted due to tight formatting; consider adding explicit spacing or parentheses to improve clarity and maintainability.

Suggested change
SET count = MAX(0, count ${isDelete ? "-" : "+"} 1)
SET count = MAX(0, (count ${isDelete ? " - " : " + "} 1))

Copilot uses AI. Check for mistakes.
threadManager: ThreadManager,
textChannels: Collection<string, GuildBasedChannel & TextBasedChannel>
): Promise<void> {
const activeChannelThreads = await threadManager.fetchActive(true);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a "Missing access" error when running fetchActive and fetchArchived for every text channels in my test server :(

I don't know why (yet), but it does stop the saving process. Could you add something to catch the error?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the message saving functionality and improves channel management commands. Key changes include:

  • Refactoring message saving logic (including handling threads) and optimizing database transactions.
  • Adding events for thread creation and deletion.
  • Improving the /channels command with pagination and enhanced channel statistics formatting.
  • Updating documentation to reflect new features, architecture, and security best practices.

Reviewed Changes

Copilot reviewed 19 out of 23 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/loaders.ts Added logging for locale loading progress.
src/events/threads/thread-delete.ts New event to handle thread deletion and cleanup messages.
src/events/threads/thread-create.ts New event to handle thread creation and joining new threads.
src/events/messages/message-create.ts Updated message filtering logic with improved filtering function.
src/events/client-ready.ts Refactored guild message syncing logic using Promise.all.
src/database/bee-database.ts Refactored message saving transactions and daily counter updates.
src/commands/admin/savechannel.ts Simplified channel saving by calling saveMessagesForGuild.
src/commands/admin/save.ts Improved message fetching and thread handling in save flow.
src/commands/admin/channels.ts Enhanced channel statistics command with embed pagination.
src/commands/activity/* Removed redundant reply deferral in activity commands.
docs/*, README.md, CONTRIBUTING.md Updated and added documentation regarding architecture and security.
Files not reviewed (4)
  • .dockerignore: Language not supported
  • .env.template: Language not supported
  • src/locales/en-US.json: Language not supported
  • src/locales/fr.json: Language not supported
Comments suppressed due to low confidence (2)

src/events/threads/thread-create.ts:8

  • [nitpick] Consider renaming the 'newlyCreate' parameter to 'newlyCreated' for improved clarity and consistency.
async execute(thread: AnyThreadChannel, newlyCreate: boolean) {

src/database/bee-database.ts:42

  • The immediately invoked transaction function pattern may be unconventional. Verify that the db.transaction API supports this usage pattern without introducing side effects.
})();

@actionbrk
actionbrk merged commit 578ae8b into master Apr 22, 2025
@DonatienBaille
DonatienBaille deleted the 29-support-threads branch April 23, 2025 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Forum channels Support threads

3 participants