Skip to content

Feat discord#2785

Open
zjdaniels1985 wants to merge 4 commits into
pyfa-org:masterfrom
zjdaniels1985:feat-discord
Open

Feat discord#2785
zjdaniels1985 wants to merge 4 commits into
pyfa-org:masterfrom
zjdaniels1985:feat-discord

Conversation

@zjdaniels1985

Copy link
Copy Markdown

Closes: #2782

Summary

This change adds Discord webhook fit sharing to pyfa.

Users can now:

  • Enable or disable Discord integration in Preferences.
  • Configure a Discord webhook URL in Preferences.
  • Get inline webhook URL format validation feedback in Preferences.
  • Test Discord webhook connectivity directly from Preferences.
  • Optionally require a confirmation prompt (with fit name/ship preview) before sending.
  • Share the active fit to Discord from the Fit menu.

What Was Added

  • New Discord preferences panel with:

    • Enable Discord Integration toggle
    • Webhook URL input
    • Webhook URL format validation feedback
    • Test Webhook button for connectivity verification
    • Optional "Confirm before sending fit to Discord" toggle
    • Webhook controls disabled when integration is off
  • New Discord sharing service that:

    • Reads Discord settings
    • Validates webhook URL format before attempting send
    • Supports explicit webhook test-message send
    • Exports active fit in pyfa EFT format
    • Sends fit to configured Discord webhook
    • Returns user-friendly error messages
  • New Fit menu action:

    • Share Fit to Discord
    • Visible only when Discord integration is enabled and webhook URL is valid
    • Visibility refreshed after Preferences closes and whenever the Fit menu opens
  • Added targeted unit tests for:

    • Discord webhook URL validation
    • Discord settings redaction/flags
    • Discord share menu visibility sync behavior
  • Error reporting hardening:

    • Redacts Discord webhook URL patterns from exception text before logging and displaying
  • Localization hardening:

    • Wrapped new Discord user-facing strings for translation

Files Changed

  • gui/builtinPreferenceViews/init.py
    • Registered Discord preferences module.
  • gui/builtinPreferenceViews/pyfaDiscordPreferences.py
    • Added Discord preferences UI, URL validation, confirm-before-send option, and Test Webhook action.
  • gui/mainFrame.py
    • Added Share Fit to Discord action handler.
    • Added menu binding for share action.
    • Refreshes Discord menu visibility after Preferences closes and on Fit menu open.
  • gui/mainMenuBar.py
    • Added Share Fit to Discord menu item id.
    • Added dynamic visibility logic for Discord menu entry with valid webhook gating.
  • gui/menu_utils.py
    • Added lightweight menu visibility sync helper for Discord share action.
  • gui/preferenceView.py
    • Added import for Discord preferences view.
  • imgs/gui/prefs_discord.png
    • Added Discord preferences icon.
  • service/discord.py
    • Added Discord webhook service for fit export/sending, URL validation, test-message send, and localized user-facing messages.
  • service/settings.py
    • Added Discord settings defaults and persistence.
    • Includes enableDiscord, webhookUrl, and confirmBeforeSend keys.
  • gui/errorDialog.py
    • Added Discord webhook URL redaction in exception log/dialog output.
  • tests/test_modules/test_service/test_discord.py
    • Added tests for URL validation and redacted Discord settings output.
  • tests/test_modules/test_gui/test_mainMenuBar_discord.py
    • Added tests for Discord share menu visibility behavior.

Discord Integration Screenshots

Discord Default Prefereneces

pyfa_discord_settings_default

Discord Settings Enabled

pyfa_discord_settings_enabled

Discord Webhook URL Test

pyfa_discord_settings_webhook_test

Discord Confirm Before Send Option

pyfa_discord_settings_confirm_option

Discord Confirm Before Send Dialogue Window

pyfa_discord_confirm_send

Discord Share Fit Menu Option in Pyfa

pyfa_discord_share_fit_menu_option

Pyfa send fit to Discord Confirmation Dialogue Window

pyfa_discord_send_fit_confirmation

Discord Screenshots

Webhook URL Test Message Received in Discord Channel

pyfa_discord_test_message_sent

Fit Message Received in Discord Channel

pyfa_discord_sent_message

Validation Notes

Implemented and validated with targeted tests plus manual checks:

  • Open Preferences and verify Discord panel appears.
  • Toggle Enable Discord Integration and confirm webhook field enables/disables.
  • Enter an invalid webhook URL and verify validation message appears.
  • Enter webhook URL and restart pyfa to confirm persistence.
  • Click "Test Webhook" and verify a test message is posted successfully.
  • Enable "Confirm before sending fit to Discord" and verify confirmation dialog shows fit preview.
  • Verify Share Fit to Discord appears only when integration is enabled.
  • Verify Share Fit to Discord stays hidden when webhook URL format is invalid.
  • Share a fit and confirm message arrives in target Discord channel.
  • Run tests:
    • .\pyfaEnv\Scripts\python.exe -m pytest tests/test_modules/test_service/test_discord.py tests/test_modules/test_gui/test_mainMenuBar_discord.py -q
    • Expected: 5 passed

Risks and Mitigations Implemented

  • Risk: Invalid webhook URL causes send failures.
    • Mitigation: URL format validation in Preferences, pre-send validation in service, and menu visibility gated on valid webhook URL.
  • Risk: Menu item visibility can become stale.
    • Mitigation: Visibility refreshed after Preferences dialog closes and on Fit menu open.
  • Risk: Sensitive webhook URL leaks in logs/debug output.
    • Mitigation: Generic send-failure logging/messages, redacted settings helper, and exception-text webhook redaction in error dialog/log path.

Follow-up Ideas

  • Add tests for Test Webhook button UX flow (button enablement + success/failure dialogs).
  • Add localization coverage checks to ensure new msgids are extracted and translated.

@Skybladev2

Copy link
Copy Markdown
Contributor

Why not use Ctrl+C, Ctrl+V?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request - Add Feature to share fittings to a Discord Guild

2 participants