Skip to content

Commit 217b249

Browse files
RizhongLinclaude
andcommitted
🔧 Add celebration style to confirmation messages and backups
## Changes - Add star sign and celebration style to birthday confirmation blocks - Centralise CELEBRATION_STYLE_EMOJIS constant for consistent emoji usage - Pass user_id through backup chain for accurate preferences lookup - Update DM and slash command confirmation messages with enhanced details ## Files Modified - handlers/modal_handlers.py, services/dispatcher.py, storage/birthdays.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 9bc5ead commit 217b249

File tree

3 files changed

+79
-46
lines changed

3 files changed

+79
-46
lines changed

handlers/modal_handlers.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ def handle_birthday_modal_submission(ack, body, client, view):
135135
# Save birthday with preferences using existing function
136136
updated = save_birthday(date_ddmm, user_id, birth_year, username, preferences)
137137

138-
# Send external backup
139-
trigger_external_backup(updated, username, app)
138+
# Send external backup with user_id for preferences lookup
139+
trigger_external_backup(updated, username, app, user_id=user_id)
140140

141141
# Check if birthday is today
142142
if check_if_birthday_today(date_ddmm):
@@ -175,7 +175,11 @@ def handle_open_modal_button(ack, body, client):
175175

176176
def _send_modal_confirmation(client, user_id, date_ddmm, birth_year, updated):
177177
"""Send confirmation after modal submission."""
178-
from storage.birthdays import CELEBRATION_STYLES, get_user_preferences
178+
from storage.birthdays import (
179+
CELEBRATION_STYLE_EMOJIS,
180+
CELEBRATION_STYLES,
181+
get_user_preferences,
182+
)
179183
from utils.date import calculate_age, date_to_words, get_star_sign
180184

181185
date_words = date_to_words(date_ddmm, birth_year)
@@ -186,9 +190,7 @@ def _send_modal_confirmation(client, user_id, date_ddmm, birth_year, updated):
186190
prefs = get_user_preferences(user_id) or {}
187191
celebration_style = prefs.get("celebration_style", "standard")
188192
style_description = CELEBRATION_STYLES.get(celebration_style, "Standard celebration")
189-
190-
# Style emoji mapping
191-
style_emoji = {"quiet": "🤫", "standard": "🎊", "epic": "🚀"}.get(celebration_style, "🎊")
193+
style_emoji = CELEBRATION_STYLE_EMOJIS.get(celebration_style, "🎊")
192194

193195
action = "updated" if updated else "saved"
194196

services/dispatcher.py

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
is_admin,
3030
)
3131
from storage.birthdays import (
32+
CELEBRATION_STYLE_EMOJIS,
33+
CELEBRATION_STYLES,
34+
get_user_preferences,
3235
remove_birthday,
3336
save_birthday,
3437
)
@@ -38,6 +41,7 @@
3841
check_if_birthday_today,
3942
date_to_words,
4043
extract_date,
44+
get_star_sign,
4145
)
4246

4347
# Confirmation timeout from centralized config
@@ -332,19 +336,28 @@ def handle_dm_date(say, user, result, app):
332336
try:
333337
from slack.blocks import build_confirmation_blocks
334338

339+
# Get star sign and celebration style for confirmation
340+
star_sign = get_star_sign(date)
341+
prefs = get_user_preferences(user) or {}
342+
celebration_style = prefs.get("celebration_style", "standard")
343+
style_emoji = CELEBRATION_STYLE_EMOJIS.get(celebration_style, "🎊")
344+
style_desc = CELEBRATION_STYLES.get(celebration_style, "Standard celebration")
345+
346+
# Build details dict
347+
details = {
348+
"📅 Birthday": date_words,
349+
"⭐ Star Sign": star_sign,
350+
}
351+
if age_text:
352+
details["🎈 Age"] = age_text.replace(" (Age: ", "").replace(")", "")
353+
details[f"{style_emoji} Style"] = f"{celebration_style.title()} - {style_desc}"
354+
335355
if updated:
336356
blocks, fallback = build_confirmation_blocks(
337357
title="Birthday Updated!",
338358
message="Your birthday has been updated successfully.\n\nIf this is incorrect, please send the correct date.",
339359
action_type="success",
340-
details={
341-
"Birthday": date_words,
342-
"Age": (
343-
age_text.replace(" (Age: ", "").replace(")", "")
344-
if age_text
345-
else "Not specified"
346-
),
347-
},
360+
details=details,
348361
)
349362
say(blocks=blocks, text=fallback)
350363
logger.info(
@@ -355,14 +368,7 @@ def handle_dm_date(say, user, result, app):
355368
title="Birthday Saved!",
356369
message="Your birthday has been saved successfully!\n\nIf this is incorrect, please send the correct date.",
357370
action_type="success",
358-
details={
359-
"Birthday": date_words,
360-
"Age": (
361-
age_text.replace(" (Age: ", "").replace(")", "")
362-
if age_text
363-
else "Not specified"
364-
),
365-
},
371+
details=details,
366372
)
367373
say(blocks=blocks, text=fallback)
368374
logger.info(
@@ -391,10 +397,10 @@ def handle_dm_date(say, user, result, app):
391397
)
392398

393399
# Send external backup after user confirmation to avoid API conflicts
394-
_send_external_backup_if_enabled(updated, username, app)
400+
_send_external_backup_if_enabled(updated, username, app, user_id=user)
395401

396402

397-
def _send_external_backup_if_enabled(updated, username, app, change_type=None):
403+
def _send_external_backup_if_enabled(updated, username, app, change_type=None, user_id=None):
398404
"""
399405
Send external backup after birthday changes if enabled.
400406
@@ -403,10 +409,11 @@ def _send_external_backup_if_enabled(updated, username, app, change_type=None):
403409
username: Username of the person whose birthday changed
404410
app: Slack app instance for sending backup
405411
change_type: Optional override for change type ("add", "update", "remove")
412+
user_id: User ID of the person whose birthday changed (for preferences lookup)
406413
"""
407414
from storage.birthdays import trigger_external_backup
408415

409-
trigger_external_backup(updated, username, app, change_type)
416+
trigger_external_backup(updated, username, app, change_type, user_id)
410417

411418

412419
def handle_command(text, user_id, say, app):
@@ -564,19 +571,28 @@ def _handle_add_command(parts, user_id, username, say, app):
564571
try:
565572
from slack.blocks import build_confirmation_blocks
566573

574+
# Get star sign and celebration style for confirmation
575+
star_sign = get_star_sign(date)
576+
prefs = get_user_preferences(user_id) or {}
577+
celebration_style = prefs.get("celebration_style", "standard")
578+
style_emoji = CELEBRATION_STYLE_EMOJIS.get(celebration_style, "🎊")
579+
style_desc = CELEBRATION_STYLES.get(celebration_style, "Standard celebration")
580+
581+
# Build details dict
582+
details = {
583+
"📅 Birthday": date_words,
584+
"⭐ Star Sign": star_sign,
585+
}
586+
if age_text:
587+
details["🎈 Age"] = age_text.replace(" (Age: ", "").replace(")", "")
588+
details[f"{style_emoji} Style"] = f"{celebration_style.title()} - {style_desc}"
589+
567590
if updated:
568591
blocks, fallback = build_confirmation_blocks(
569592
title="Birthday Updated!",
570593
message="Your birthday has been updated successfully.",
571594
action_type="success",
572-
details={
573-
"Birthday": date_words,
574-
"Age": (
575-
age_text.replace(" (Age: ", "").replace(")", "")
576-
if age_text
577-
else "Not specified"
578-
),
579-
},
595+
details=details,
580596
)
581597
say(blocks=blocks, text=fallback)
582598
logger.info(
@@ -587,14 +603,7 @@ def _handle_add_command(parts, user_id, username, say, app):
587603
title="Birthday Saved!",
588604
message="Your birthday has been saved successfully!",
589605
action_type="success",
590-
details={
591-
"Birthday": date_words,
592-
"Age": (
593-
age_text.replace(" (Age: ", "").replace(")", "")
594-
if age_text
595-
else "Not specified"
596-
),
597-
},
606+
details=details,
598607
)
599608
say(blocks=blocks, text=fallback)
600609
logger.info(
@@ -619,7 +628,7 @@ def _handle_add_command(parts, user_id, username, say, app):
619628
)
620629

621630
# Send external backup after user confirmation
622-
_send_external_backup_if_enabled(updated, username, app)
631+
_send_external_backup_if_enabled(updated, username, app, user_id=user_id)
623632

624633

625634
def _handle_remove_command(user_id, username, say, app):

storage/birthdays.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@
7171
"epic": "Over-the-top message, AI image, and celebratory reactions",
7272
}
7373

74+
# Celebration style emojis for display
75+
CELEBRATION_STYLE_EMOJIS = {
76+
"quiet": "🤫",
77+
"standard": "🎊",
78+
"epic": "🚀",
79+
}
80+
7481

7582
def create_backup():
7683
"""
@@ -123,7 +130,9 @@ def rotate_backups():
123130
logger.error(f"BACKUP_ERROR: Failed to rotate backups: {e}")
124131

125132

126-
def send_external_backup(backup_file_path, change_type="update", username=None, app=None):
133+
def send_external_backup(
134+
backup_file_path, change_type="update", username=None, app=None, user_id=None
135+
):
127136
"""
128137
Send backup file to admin users via DM and optionally to backup channel.
129138
@@ -132,6 +141,7 @@ def send_external_backup(backup_file_path, change_type="update", username=None,
132141
change_type: Type of change that triggered backup ("add", "update", "remove", "manual")
133142
username: Username of person whose birthday changed (for context)
134143
app: Slack app instance (required for sending messages)
144+
user_id: User ID of person whose birthday changed (for preferences lookup)
135145
"""
136146
logger.info(f"BACKUP: send_external_backup called - type: {change_type}, user: {username}")
137147

@@ -158,9 +168,20 @@ def send_external_backup(backup_file_path, change_type="update", username=None,
158168
"manual": "Manual backup created",
159169
}.get(change_type, "Data changed")
160170

171+
# Get user's preferences for context if available
172+
prefs_text = ""
173+
if user_id and change_type in ("add", "update"):
174+
user_data = birthdays.get(user_id, {})
175+
prefs = user_data.get("preferences", {})
176+
style = prefs.get("celebration_style", "standard")
177+
if style != "standard":
178+
style_emoji = CELEBRATION_STYLE_EMOJIS.get(style, "🎊")
179+
style_desc = CELEBRATION_STYLES.get(style, "")
180+
prefs_text = f"\n{style_emoji} *Style:* {style.title()} - {style_desc}"
181+
161182
message = f"""🗂️ *Birthday Data Backup* - {timestamp}
162183
163-
📊 *Changes:* {change_text}
184+
📊 *Changes:* {change_text}{prefs_text}
164185
📁 *File:* {os.path.basename(backup_file_path)} ({file_size_kb} KB)
165186
👥 *Total Birthdays:* {total_birthdays} people
166187
🔄 *Auto-backup after data changes*
@@ -206,7 +227,7 @@ def send_external_backup(backup_file_path, change_type="update", username=None,
206227
logger.error(f"BACKUP: Failed to send external backup: {e}")
207228

208229

209-
def trigger_external_backup(updated, username, app, change_type=None):
230+
def trigger_external_backup(updated, username, app, change_type=None, user_id=None):
210231
"""
211232
Trigger external backup after birthday changes if enabled.
212233
@@ -217,6 +238,7 @@ def trigger_external_backup(updated, username, app, change_type=None):
217238
username: Username of the person whose birthday changed
218239
app: Slack app instance for sending backup
219240
change_type: Optional override for change type ("add", "update", "remove")
241+
user_id: User ID of the person whose birthday changed (for preferences lookup)
220242
"""
221243
from config import BACKUP_ON_EVERY_CHANGE
222244

@@ -233,7 +255,7 @@ def trigger_external_backup(updated, username, app, change_type=None):
233255
latest_backup = max(backup_files, key=lambda x: os.path.getmtime(x))
234256
if change_type is None:
235257
change_type = "update" if updated else "add"
236-
send_external_backup(latest_backup, change_type, username, app)
258+
send_external_backup(latest_backup, change_type, username, app, user_id)
237259
except Exception as e:
238260
logger.error(f"BACKUP: Failed to trigger external backup: {e}")
239261

0 commit comments

Comments
 (0)