Skip to content

Commit 2beb758

Browse files
Copilotbakerboy448
andcommitted
Improve removal reason handling with better fallback logic and user-friendly defaults
Co-authored-by: bakerboy448 <55419169+bakerboy448@users.noreply.github.com>
1 parent e929e69 commit 2beb758

1 file changed

Lines changed: 34 additions & 9 deletions

File tree

modlog_wiki_publisher.py

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -542,12 +542,27 @@ def _process_modlog_entry(self, entry) -> Optional[Dict]:
542542
else:
543543
p_mod_name = 'HumanModerator'
544544

545-
# Process details
546-
p_details = ''
547-
if entry.details:
548-
p_details = entry.details.strip()
549-
if action_type in ['addremovalreason']:
550-
p_details = parsed_mod_note.strip()
545+
# Process removal reason with improved fallback logic
546+
removal_reason = ''
547+
548+
# Special case for addremovalreason action - always prefer mod_note
549+
if action_type == 'addremovalreason':
550+
removal_reason = parsed_mod_note if parsed_mod_note else "No removal reason provided"
551+
# For other removal actions, try multiple sources for the reason
552+
elif action_type in self.REMOVAL_ACTIONS:
553+
# Try entry.details first (primary source for removal reasons)
554+
if hasattr(entry, 'details') and entry.details and entry.details.strip():
555+
removal_reason = entry.details.strip()
556+
# Fall back to mod_note/description if details is empty
557+
elif parsed_mod_note:
558+
removal_reason = parsed_mod_note
559+
# Default fallback for removal actions
560+
else:
561+
removal_reason = "No removal reason provided"
562+
else:
563+
# For non-removal actions, use details if available
564+
if hasattr(entry, 'details') and entry.details:
565+
removal_reason = entry.details.strip()
551566

552567
# Check if comment (improved detection)
553568
is_comment = bool(entry.target_permalink and '/comments/' in entry.target_permalink
@@ -577,7 +592,7 @@ def _process_modlog_entry(self, entry) -> Optional[Dict]:
577592
'action_type': action_type,
578593
'moderator': self.sanitize_for_table(p_mod_name),
579594
'target_author': self.sanitize_for_table(entry.target_author or '[deleted]'),
580-
'removal_reason': self.sanitize_for_table(p_details),
595+
'removal_reason': self.sanitize_for_table(removal_reason),
581596
'note': self.sanitize_for_table(parsed_mod_note),
582597
'title': self.sanitize_for_table(formatted_title),
583598
'url': formatted_link # URLs don't need sanitization
@@ -653,8 +668,18 @@ def _format_table_row(self, entry: Dict) -> str:
653668
else:
654669
title = f"{entry['title']}"
655670

656-
# Format removal reason
657-
reason = entry['removal_reason'] or entry['note'] or '-'
671+
# Format removal reason with improved handling
672+
reason = entry['removal_reason']
673+
if not reason or reason.strip() == '':
674+
# Check if this is a removal action that should have a reason
675+
if entry['action_type'] in ['removelink', 'removecomment', 'spamlink', 'spamcomment',
676+
'removepost', 'removecontent', 'addremovalreason']:
677+
reason = "No removal reason provided"
678+
else:
679+
# For non-removal actions, check note field or use dash
680+
reason = entry.get('note', '') or '-'
681+
elif reason == '-':
682+
reason = '-'
658683

659684
# Format inquire link
660685
if entry['modmail_url']:

0 commit comments

Comments
 (0)