feat: replace latex-to-unicode with @devhub-io/latex-to-unicode#35
Conversation
Summary by BeetleThis PR contains a series of maintenance and configuration updates to the Rael Discord bot project. The changes span five commits that collectively: (1) refine system prompts for clarity and accuracy, (2) add dev mode checks across message event handlers to restrict functionality during development, (3) optimize context clearing intervals, (4) downgrade and update dependencies for compatibility, and (5) replace a deprecated LaTeX-to-Unicode library with a maintained alternative. These are primarily housekeeping and stability improvements rather than feature additions. 📁 File Changes Summary (Consolidated across all commits):
Total Changes: 10 files changed, +56 additions, -40 deletions 🗺️ Walkthrough:graph TD
A["Message Event Received"] --> B{"Dev Mode Enabled?"}
B -->|Yes| C{"User is Dev?"}
C -->|No| D["Return Early"]
C -->|Yes| E["Process Message"]
B -->|No| E
E --> F{"Message Type?"}
F -->|AI Mode Prefix| G["Execute AI Mode"]
F -->|Bot Mention| H["Execute Mention Handler"]
F -->|Command| I["Execute Command"]
G --> J["Get/Clear Context"]
H --> J
I --> J
J --> K["Context Cleared Every 1 Hour"]
G --> L["Format with LaTeX-to-Unicode"]
H --> L
L --> M["Send Response"]
🎯 Key Changes:
📊 Impact Assessment:
⚙️ SettingsSeverity Threshold: 📖 User Guide
|
| if (!message || !message.guild || message.author.bot) return; | ||
| if ( | ||
| process.env.NODE_ENV?.toLowerCase() === "dev" && | ||
| !devs.includes(message.author.id) |
There was a problem hiding this comment.
The code calls devs.includes() without verifying that devs is actually an array. If the devs property is missing, undefined, or not an array in the config, this will throw a runtime error: TypeError: devs.includes is not a function.
Confidence: 4/5
Suggested Fix
| !devs.includes(message.author.id) | |
| Array.isArray(devs) && !devs.includes(message.author.id) | |
Add a type check to ensure devs is an array before calling .includes(). This prevents runtime errors if the config is malformed or missing the devs property.
Prompt for AI
Copy this prompt to your AI IDE to fix this issue locally:
In src/events/messageCreate/aiMode.ts around line 12, the code calls devs.includes()
without verifying that devs is an array; this will throw a runtime error if devs is
undefined or not an array. Add a type check using Array.isArray(devs) before calling
.includes() to safely handle cases where the config might be malformed or missing the
devs property.
|
|
||
| export default async (client: Client, message: Message) => { | ||
| if (!message || !message.guild || message.author?.bot) return; | ||
| if (!message || !message.guild || message.author.bot || !client.user) return; |
There was a problem hiding this comment.
Removing optional chaining from message.author?.bot to message.author.bot introduces a potential runtime error. If message.author is null or undefined, accessing the .bot property will throw TypeError: Cannot read property 'bot' of null/undefined. The optional chaining was there for defensive programming to safely handle edge cases in the Discord.js API.
Confidence: 4/5
Suggested Fix
| if (!message || !message.guild || message.author.bot || !client.user) return; | |
| if (!message || !message.guild || message.author?.bot || !client.user) return; | |
Restore the optional chaining operator (?.) on message.author?.bot to safely handle cases where message.author might be null or undefined, while keeping the new !client.user check.
Prompt for AI
Copy this prompt to your AI IDE to fix this issue locally:
In src/events/messageCreate/handleCommands.ts around line 17, the code removes optional
chaining from message.author?.bot to message.author.bot; this will throw a runtime error
if message.author is null or undefined. Restore the optional chaining operator (?.bot)
to safely handle edge cases where the author property might not exist, while keeping the
new !client.user check that was added.
|
|
||
| if ( | ||
| process.env.NODE_ENV?.toLowerCase() === "dev" && | ||
| !devs.includes(message.author.id) |
There was a problem hiding this comment.
The code calls devs.includes() without verifying that devs is actually an array. If the devs property is missing, undefined, or not an array in the config, this will throw a runtime error: TypeError: devs.includes is not a function.
Confidence: 4/5
Suggested Fix
| !devs.includes(message.author.id) | |
| Array.isArray(devs) && !devs.includes(message.author.id) | |
Add a type check to ensure devs is an array before calling .includes(). This prevents runtime errors if the config is malformed or missing the devs property.
Prompt for AI
Copy this prompt to your AI IDE to fix this issue locally:
In src/events/messageCreate/mention.ts around line 13, the code calls devs.includes()
without verifying that devs is an array; this will throw a runtime error if devs is
undefined or not an array. Add a type check using Array.isArray(devs) before calling
.includes() to safely handle cases where the config might be malformed or missing the
devs property.
| export default async (client: Client, message: Message) => { | ||
| if (message.author.bot) return; | ||
| if (!client.user) return; | ||
| if (!message || !message.guild || message.author.bot || !client.user) return; |
There was a problem hiding this comment.
The guard clause accesses message.author.bot without optional chaining. If message.author is null or undefined, this will throw TypeError: Cannot read property 'bot' of null/undefined. The condition should use optional chaining to safely handle edge cases where the author property might not exist.
Confidence: 4/5
Suggested Fix
| if (!message || !message.guild || message.author.bot || !client.user) return; | |
| if (!message || !message.guild || message.author?.bot || !client.user) return; | |
Use optional chaining (?.) on message.author?.bot to safely handle cases where message.author might be null or undefined.
Prompt for AI
Copy this prompt to your AI IDE to fix this issue locally:
In src/events/messageCreate/mention.ts around line 9, the code accesses message.author.bot
without optional chaining; this will throw a runtime error if message.author is null or
undefined. Add the optional chaining operator (?.bot) to safely handle edge cases where
the author property might not exist.
|
Note Linting checks passed successfully 🎉 All formatting and code quality checks are clean. You're good to merge 🚀 |
latex-to-unicodepackage with@devhub-io/latex-to-unicode(open-devhub/latex-to-unicode)messageCreateevent files