Refactor discord bot for maintainability #3

Open
florianbeisel wants to merge 9 commits from cursor/refactor-discord-bot-for-maintainability-64ab into main
florianbeisel commented 2025-07-23 13:18:02 +02:00 (Migrated from github.com)

Modularize Discord bot for improved maintainability and TypeScript readiness, ensuring full backward compatibility.


Open in WebOpen in Cursor

Modularize Discord bot for improved maintainability and TypeScript readiness, ensuring full backward compatibility. --- [Open in Web](https://www.cursor.com/agents?id=bc-10220733-2fa7-4306-b2f2-be6d24c64aa3) • [Open in Cursor](https://cursor.com/background-agent?bcId=bc-10220733-2fa7-4306-b2f2-be6d24c64aa3)
cursor[bot] (Migrated from github.com) reviewed 2025-07-23 13:25:19 +02:00
cursor[bot] (Migrated from github.com) left a comment

Bug: Improper Error Handling Causes Infinite Reconnection

The client.on("error") handler attempts to reconnect by calling client.login() on an already logged-in client. This will fail as Discord.js clients cannot be re-logged in. The logic also lacks error type checking (e.g., for invalid tokens) and rate limiting, which can lead to infinite reconnection loops and Discord API rate limits.

discord/index.js#L33-L42

github.com/florianbeisel/foundry-hosting@0153427074/discord/index.js (L33-L42)

Fix in CursorFix in Web


Bug: Bot Startup Clears Unused Map Instead of Active Monitors

The bot uses two separate statusMonitors Maps: one in monitoring.js for managing active instance monitors, and an unused client.statusMonitors property. On startup, client.statusMonitors.clear() is called, which incorrectly attempts to clear the unused map instead of stopping the active monitors managed by monitoring.js. This leads to inconsistent state management and potential memory leaks, as active monitors are not properly cleared on bot restarts. The stopAllMonitoring() function from monitoring.js should be used for proper cleanup.

discord/services/monitoring.js#L5-L6

github.com/florianbeisel/foundry-hosting@0153427074/discord/services/monitoring.js (L5-L6)

discord/events/ready.js#L25-L26

github.com/florianbeisel/foundry-hosting@0153427074/discord/events/ready.js (L25-L26)

Fix in CursorFix in Web


Bugbot free trial expires on August 6, 2025
Learn more in the Cursor dashboard.

Was this report helpful? Give feedback by reacting with 👍 or 👎

<details open> <summary><h3>Bug: Improper Error Handling Causes Infinite Reconnection</h3></summary> The `client.on("error")` handler attempts to reconnect by calling `client.login()` on an already logged-in client. This will fail as Discord.js clients cannot be re-logged in. The logic also lacks error type checking (e.g., for invalid tokens) and rate limiting, which can lead to infinite reconnection loops and Discord API rate limits. <p></p> <details> <summary><code>discord/index.js#L33-L42</code></summary> https://github.com/florianbeisel/foundry-hosting/blob/0153427074fa95c8439b32b6e5015fe33276b0a3/discord/index.js#L33-L42 </details> <a href="https://cursor.com/open?data=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImJ1Z2JvdC12MSJ9.eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90Ojk2ZWI4NjJmLTFkNWYtNGJiMy05ZTE1LTRiYTkwZjNmNDQwMSIsImVuY3J5cHRpb25LZXkiOiI5RF9vVi1DVTVZZG9MOTNEWUg5VEtvY1FGQ0NyUW0zSWJEenpkSU5DbTZrIiwiYnJhbmNoIjoiY3Vyc29yL3JlZmFjdG9yLWRpc2NvcmQtYm90LWZvci1tYWludGFpbmFiaWxpdHktNjRhYiJ9LCJpYXQiOjE3NTMyNjk5MTksImV4cCI6MTc1Mzg3NDcxOX0.DrajpJjFQ2XecKDyq0io2tOxW7CRzoD1qgUx-DA1GVaT6dBIZNvnox4zW3MViBP86G6ZuIBoDF2Z_dcJYOx3kHq3Wgyw2MFx_4r_hBpeHX2pLGgzwGwg2jjWtNI4YC4NGyTSnC5DlZ_e_lN5WkTotbKDN9yxZUHtSei_rocoDeq91Z_13gzLHXuKku-bwceTlh0r0fjp3oKXHdg585FJZEbsjc1ROqdRygBK9aYwMbBpYX7SPIrhPIYJbhTC07GhRjK-heZuB0N3G-XmUW_E45E3gXFWvogofsYnSFTn_2ZvC5If7xOSvHwi_FYrjVaeDSNUmHAG2QoNTtH-g1DuMg">Fix in Cursor</a> • <a href="https://cursor.com/agents?data=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImJ1Z2JvdC12MSJ9.eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90Ojk2ZWI4NjJmLTFkNWYtNGJiMy05ZTE1LTRiYTkwZjNmNDQwMSIsImVuY3J5cHRpb25LZXkiOiI5RF9vVi1DVTVZZG9MOTNEWUg5VEtvY1FGQ0NyUW0zSWJEenpkSU5DbTZrIiwiYnJhbmNoIjoiY3Vyc29yL3JlZmFjdG9yLWRpc2NvcmQtYm90LWZvci1tYWludGFpbmFiaWxpdHktNjRhYiIsInJlcG9Pd25lciI6ImZsb3JpYW5iZWlzZWwiLCJyZXBvTmFtZSI6ImZvdW5kcnktaG9zdGluZyIsInByTnVtYmVyIjozLCJjb21taXRTaGEiOiIwMTUzNDI3MDc0ZmE5NWM4NDM5YjMyYjZlNTAxNWZlMzMyNzZiMGEzIn0sImlhdCI6MTc1MzI2OTkxOSwiZXhwIjoxNzUzODc0NzE5fQ.eSuKmmOVm82tgylrDX1qpgmrzHyn8Cmr7deKCdklGHV__sAcE0XjiuJWKrIxphTrwBeo0dd8_iqO35PaMcNWbML3WI5raQS5bjy9WF0Cmu-P6ohIc9wj9-E7WT30kz4e7CcTPB5989MsSW-1TsupAUCPmdkHQLWL3Qa7aSDJ6nh_waPyAhZsYs8MUDZ5CtUlvVR-yzMF41EuFmdPHWQ6KciNDYjbUiEWs3lu7estYTQXXisZBo-SrhTjyu7VWMVA0uf89-9QyhO-r3KGCZNpblSC0TyCh7cA1J3mfUZ3OFZmVJXElyGIjkWmiFMjxvBclHo_zvnYAlXWLa7Gl-pf9A">Fix in Web</a> </details> --- <details open> <summary><h3>Bug: Bot Startup Clears Unused Map Instead of Active Monitors</h3></summary> The bot uses two separate `statusMonitors` Maps: one in `monitoring.js` for managing active instance monitors, and an unused `client.statusMonitors` property. On startup, `client.statusMonitors.clear()` is called, which incorrectly attempts to clear the unused map instead of stopping the active monitors managed by `monitoring.js`. This leads to inconsistent state management and potential memory leaks, as active monitors are not properly cleared on bot restarts. The `stopAllMonitoring()` function from `monitoring.js` should be used for proper cleanup. <p></p> <details> <summary><code>discord/services/monitoring.js#L5-L6</code></summary> https://github.com/florianbeisel/foundry-hosting/blob/0153427074fa95c8439b32b6e5015fe33276b0a3/discord/services/monitoring.js#L5-L6 </details> <details> <summary><code>discord/events/ready.js#L25-L26</code></summary> https://github.com/florianbeisel/foundry-hosting/blob/0153427074fa95c8439b32b6e5015fe33276b0a3/discord/events/ready.js#L25-L26 </details> <a href="https://cursor.com/open?data=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImJ1Z2JvdC12MSJ9.eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjBlNzE3YzE2LWZiM2ItNDEyYS05Y2I5LTVhN2JiY2RiYmQ3NCIsImVuY3J5cHRpb25LZXkiOiJiR05RSW5ZR0UyQXVfbnhScVBZNDhGZ1JmLXpsZ1BuR2xGeFE1ekF3TXhjIiwiYnJhbmNoIjoiY3Vyc29yL3JlZmFjdG9yLWRpc2NvcmQtYm90LWZvci1tYWludGFpbmFiaWxpdHktNjRhYiJ9LCJpYXQiOjE3NTMyNjk5MTksImV4cCI6MTc1Mzg3NDcxOX0.aeCfJC5T_5VC7WsNkmTpOv3S9c0Gjdo1-ZGsAUWd_S8u-4Jfim1Nav6ZSOxnF08gSRsMiljImLoeFQGKgzYxawLZTtNoQd7CAme0cW4ygUGUN0dkv3-DSKYXOZf0N9bG9DO2Wr3JSiH8EDB3ye950a9VsmDqdKZImA_9dxZcuFTSLHlJaGCOr65harX_VL2jVonRRFoqQDIP06Z8zCMsUx0_IKpDtS8gbNdO6rkNVeGiQ8g5DUrgx9HvzjLvOpCH-APae8uE8wYojyAIhp4wqjDdhhjV6HgQZAlTRcoRhSqnEMqscj7KMiyV1VDswYc4sMRv3quBtEY9BvFXES9yfA">Fix in Cursor</a> • <a href="https://cursor.com/agents?data=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImJ1Z2JvdC12MSJ9.eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjBlNzE3YzE2LWZiM2ItNDEyYS05Y2I5LTVhN2JiY2RiYmQ3NCIsImVuY3J5cHRpb25LZXkiOiJiR05RSW5ZR0UyQXVfbnhScVBZNDhGZ1JmLXpsZ1BuR2xGeFE1ekF3TXhjIiwiYnJhbmNoIjoiY3Vyc29yL3JlZmFjdG9yLWRpc2NvcmQtYm90LWZvci1tYWludGFpbmFiaWxpdHktNjRhYiIsInJlcG9Pd25lciI6ImZsb3JpYW5iZWlzZWwiLCJyZXBvTmFtZSI6ImZvdW5kcnktaG9zdGluZyIsInByTnVtYmVyIjozLCJjb21taXRTaGEiOiIwMTUzNDI3MDc0ZmE5NWM4NDM5YjMyYjZlNTAxNWZlMzMyNzZiMGEzIn0sImlhdCI6MTc1MzI2OTkxOSwiZXhwIjoxNzUzODc0NzE5fQ.UE2lRQGlp7GRt83Zy8XdriILMVtb8mPUs3n90RUqou6P2XXiPm3K5FzV4eqVC1qy_JPAwTQ-uGRmjMWOdW40JY9kBqrWCWt6ZE0_bZ3QGoDFw1DtTbX8O5XdRvZ58HYtXN_jhZcO2_y1sRPSk5lymrCddImZe9H-ldN_-sGNrQ0XY6_3eAjvL-27FXbke3XXoO3p01xKKF94MLwicpOUvCoNi3sEyR8LbUMXJAiAMiuxfmEOzY6OnKVTGOwmYWsCF7ufL_Y70KJSkxmOHKCNh9sg5VT3Sp8eUmXqOGhs2oDF6r-zHCu7DUrEYdd8ozJWMAfDZ5n8R3E9l4TMTEdT5A">Fix in Web</a> </details> --- **Bugbot free trial expires on August 6, 2025** Learn more in the [Cursor dashboard](https://cursor.com/dashboard?tab=bugbot). _Was this report helpful? Give feedback by reacting with 👍 or 👎_
This pull request has changes conflicting with the target branch.
  • discord/index.js
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin cursor/refactor-discord-bot-for-maintainability-64ab:cursor/refactor-discord-bot-for-maintainability-64ab
git switch cursor/refactor-discord-bot-for-maintainability-64ab

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff cursor/refactor-discord-bot-for-maintainability-64ab
git switch cursor/refactor-discord-bot-for-maintainability-64ab
git rebase main
git switch main
git merge --ff-only cursor/refactor-discord-bot-for-maintainability-64ab
git switch cursor/refactor-discord-bot-for-maintainability-64ab
git rebase main
git switch main
git merge --no-ff cursor/refactor-discord-bot-for-maintainability-64ab
git switch main
git merge --squash cursor/refactor-discord-bot-for-maintainability-64ab
git switch main
git merge --ff-only cursor/refactor-discord-bot-for-maintainability-64ab
git switch main
git merge cursor/refactor-discord-bot-for-maintainability-64ab
git push origin main
Sign in to join this conversation.
No description provided.