Conversation
Handle timestamp parsing errors and implement a safe range for large timestamps.
Add _ as alias for * to create italic text
There was a problem hiding this comment.
Pull request overview
This pull request enhances Discord chat export functionality by adding support for additional markdown syntaxes and implementing overflow-safe timestamp handling. The changes enable parsing of single underscore italics and Discord's small text syntax, while also preventing crashes when processing extremely large Unix timestamps through a 400-year cycle projection algorithm.
- Added support for single underscore italics (
_text_) and small text markdown (-# text) - Implemented exception handling for timestamp overflow errors using 400-year Gregorian calendar cycle arithmetic
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| chat_exporter/parse/markdown.py | Added two new markdown patterns: single underscore for italics and -# prefix for small text rendering |
| chat_exporter/parse/mention.py | Wrapped timestamp parsing in try-except block with fallback logic that projects large timestamps into safe 400-year cycles to prevent overflow errors |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| tooltip_time = tooltip_time.replace(str(datetime_stamp.year), str(time_stamp[0])) | ||
| except (OSError, OverflowError, ValueError): | ||
| # overflow error occurs when timestamp is too large, manual parsing | ||
| CYCLE_SECONDS = 12_622_780_800 # Exactly 400 years in seconds |
There was a problem hiding this comment.
The constant CYCLE_SECONDS is defined inside the exception handler, which means it will be redefined every time an overflow occurs. Consider moving this constant to the class level (e.g., as a class variable in ParseMention) or module level for better performance and code organization. For example, add CYCLE_SECONDS = 12_622_780_800 near the top of the class definition alongside other constants like REGEX_TIME_HOLDER.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Looks good to me |
This pull request introduces improvements to both markdown parsing and time mention handling. The markdown parser now supports additional markdown syntaxes, and the time mention logic is enhanced to robustly handle extremely large timestamps that could previously cause errors.
Markdown parsing enhancements:
_text_) and rendering them as<em>tags.-# Heading) and rendering it as<small>tags.Time mention handling improvements:
OverflowErrororOSErrorand ensuring correct year calculation in the rendered output.