Skip to content

Conversation

Copy link

Copilot AI commented Jul 18, 2025

This PR implements a new /duel slash command that allows users to challenge each other to fun duels with interactive Discord buttons.

Features

Core Functionality

  • /duel @user [type] - Challenge another user to a duel
  • Interactive buttons - Target user can Accept (⚔️) or Refuse (🛡️) the challenge
  • 60-second timeout - Challenges automatically expire if not accepted
  • Random winner selection - Fair 50/50 chance for either participant
  • Engaging flavor messages - 8 different victory messages for variety

Duel Types

  • Normal duels - Fun combat with flavor text only
  • Mute duels - Loser gets muted for 10 minutes (integrates with existing mute system)

Safety & Validation

  • Prevents self-dueling and bot dueling
  • Only the challenged user can interact with buttons
  • Prevents multiple active duels between same users
  • Silent dismissal when refused (message gets deleted)
  • Comprehensive error handling for edge cases

Example Usage

/duel @JohnDoe normal
# Creates interactive message with Accept/Refuse buttons

/duel @JaneSmith mute
# Same as above, but loser gets 10-minute mute

Technical Implementation

  • Added to UserSlashModule.cs following existing patterns
  • Uses Discord.NET's ComponentInteraction for button handling
  • Leverages existing muting infrastructure (UserService.MutedUsers)
  • Thread-safe operations with proper async cleanup
  • Zero modifications to existing code (238 lines added, 0 deleted)

Fixes #333.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.myget.org
    • Triggering command: dotnet build (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@deepsource-io
Copy link

deepsource-io bot commented Jul 18, 2025

Here's the code health analysis summary for commits fa0bb86..7ca33eb. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource C# LogoC#❌ Failure
❗ 6 occurences introduced
View Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

@github-actions
Copy link

🚀 Deploy this PR to an environment

You can deploy this PR to either development or staging environment:

  • Comment /deploy_dev to deploy to the development environment

Alternatively, you can:

  1. Go to Actions tab
  2. Click on "Manual Deploy to Firebase" workflow
  3. Click the "Run workflow" button
  4. Select branch: copilot/fix-333
  5. Choose environment: DEV
  6. Enter a deployment message
  7. Click "Run workflow"

Co-authored-by: Pierre-Demessence <1756398+Pierre-Demessence@users.noreply.github.com>
Copilot AI changed the title [WIP] Duel command Implement /duel slash command with interactive buttons and mute functionality Jul 18, 2025
Copilot AI requested a review from Pierre-Demessence July 18, 2025 22:41
@Pierre-Demessence
Copy link
Member

/deploy_dev

@github-actions
Copy link

🚀 Starting deployment of Unity-Developer-Community/UDC-Bot:copilot/fix-333 to development...

@Pierre-Demessence
Copy link
Member

A few suggestions :

  • When refusing the duel, do like when it expires and edit the embed instead of deleting it.
  • For mute duel, don't use a muted role as result, instead use the Discord API to Timeout the user for 10 mins.
  • For duel results message, make it clear who is the winner every time. Maybe edit the embed to add a "Winner: <@user>"
  • For the type of duel, it would be good to use a Command Option Choice type, with autocomplete, so when typing /duel the user can see the different types.

…ice options

Co-authored-by: Pierre-Demessence <1756398+Pierre-Demessence@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jul 18, 2025

A few suggestions :

  • When refusing the duel, do like when it expires and edit the embed instead of deleting it.
  • For mute duel, don't use a muted role as result, instead use the Discord API to Tim...

All suggestions implemented in commit 1dbe87f:

Duel refusal: Now edits embed to show "🛡️ Duel challenge was refused" instead of deleting message
Mute duel: Replaced muted role system with Discord's native timeout API (SetTimeOutAsync) for 10 minutes
Winner clarity: Added "Winner: @user" field to result embed for clear identification
Command choices: Added Choice attributes for duel types with autocomplete dropdown (Normal/Mute)

Changes reduce code complexity while improving UX and leveraging Discord's built-in features.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.myget.org
    • Triggering command: dotnet build --no-restore (dns block)
    • Triggering command: dotnet restore (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Pierre-Demessence
Copy link
Member

/deploy_dev

@github-actions
Copy link

🚀 Starting deployment of Unity-Developer-Community/UDC-Bot:copilot/fix-333 to development...

@Pierre-Demessence
Copy link
Member

A few more changes:

  • When the duel expires, indicate who was challenged.
  • Add a "Cancel" button, only the challenger can click on it to cancel the duel.
  • There's a bug, sometimes the embed is not dismissed after 60s. I checked the code but can't really understand why. It seems to occur randomly ? I can't really reproduce the issue. Try to fix the issue but if you don't know what to fix, don't make unnecessary changes.

… timeout bug

Co-authored-by: Pierre-Demessence <1756398+Pierre-Demessence@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jul 19, 2025

A few more changes:

  • When the duel expires, indicate who was challenged.
  • Add a "Cancel" button, only the challenger can click on it to cancel the duel.
    ...

All requested changes implemented in commit c0c429b:

Timeout message: Now shows "⏰ Duel challenge to @user expired" with the challenged user mentioned
Cancel button: Added ❌ Cancel button that only the challenger can click to cancel active duels
Timeout bug fix: Replaced interaction context approach with stored message reference for more reliable timeout handling

The timeout mechanism now stores the original message reference and uses that for modifications, which should resolve the intermittent timeout dismissal issue.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.myget.org
    • Triggering command: dotnet build --no-restore (dns block)
    • Triggering command: dotnet restore --ignore-failed-sources (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Pierre-Demessence
Copy link
Member

/deploy_dev

@github-actions
Copy link

🚀 Starting deployment of Unity-Developer-Community/UDC-Bot:copilot/fix-333 to development...

@Pierre-Demessence
Copy link
Member

I think the PR is good. It should stop being a draft PR and become "Ready for review"

@Pierre-Demessence Pierre-Demessence marked this pull request as ready for review July 19, 2025 00:36
Copilot AI review requested due to automatic review settings July 19, 2025 00:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Implements a new /duel slash command system that allows users to challenge each other to interactive duels with Discord button controls. The feature includes both normal fun duels and mute duels where the loser receives a 10-minute timeout.

  • Interactive challenge system with Accept/Refuse/Cancel buttons and 60-second auto-timeout
  • Random winner selection with 8 different victory flavor messages for engagement
  • Mute duel integration using Discord's native timeout functionality

@Pierre-Demessence
Copy link
Member

Copilot reviewed the code and said:

The static Dictionary '_activeDuels' is not thread-safe and could cause race conditions when multiple users create/accept/refuse duels simultaneously. Consider using ConcurrentDictionary<string, (ulong challengerId, ulong opponentId)> instead.

I think it's a good idea, make the change @copilot

…l system

Co-authored-by: Pierre-Demessence <1756398+Pierre-Demessence@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jul 19, 2025

Copilot reviewed the code and said:

The static Dictionary '_activeDuels' is not thread-safe and could cause race conditions when multiple users create/accept/refuse duels simultaneously. Consider...

Changed to ConcurrentDictionary for thread-safe duel operations in commit c2248e0. This prevents race conditions when multiple users interact with duels simultaneously.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.myget.org
    • Triggering command: dotnet build --no-restore (dns block)
    • Triggering command: dotnet restore --ignore-failed-sources (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Pierre-Demessence
Copy link
Member

/deploy_dev

@github-actions
Copy link

🚀 Starting deployment of Unity-Developer-Community/UDC-Bot:copilot/fix-333 to development...

@Pierre-Demessence
Copy link
Member

There are errors now:

Error: /home/runner/work/UDC-Bot/UDC-Bot/DiscordBot/Modules/UserSlashModule.cs(335,30): error CS7036: There is no argument given that corresponds to the required formal parameter 'value' of 'CollectionExtensions.Remove<TKey, TValue>(IDictionary<TKey, TValue>, TKey, out TValue)' [/home/runner/work/UDC-Bot/UDC-Bot/DiscordBot/DiscordBot.csproj]
Error: /home/runner/work/UDC-Bot/UDC-Bot/DiscordBot/Modules/UserSlashModule.cs(390,22): error CS7036: There is no argument given that corresponds to the required formal parameter 'value' of 'CollectionExtensions.Remove<TKey, TValue>(IDictionary<TKey, TValue>, TKey, out TValue)' [/home/runner/work/UDC-Bot/UDC-Bot/DiscordBot/DiscordBot.csproj]
Error: /home/runner/work/UDC-Bot/UDC-Bot/DiscordBot/Modules/UserSlashModule.cs(473,22): error CS7036: There is no argument given that corresponds to the required formal parameter 'value' of 'CollectionExtensions.Remove<TKey, TValue>(IDictionary<TKey, TValue>, TKey, out TValue)' [/home/runner/work/UDC-Bot/UDC-Bot/DiscordBot/DiscordBot.csproj]
Error: /home/runner/work/UDC-Bot/UDC-Bot/DiscordBot/Modules/UserSlashModule.cs(514,22): error CS7036: There is no argument given that corresponds to the required formal parameter 'value' of 'CollectionExtensions.Remove<TKey, TValue>(IDictionary<TKey, TValue>, TKey, out TValue)' [/home/runner/work/UDC-Bot/UDC-Bot/DiscordBot/DiscordBot.csproj]

Co-authored-by: Pierre-Demessence <1756398+Pierre-Demessence@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jul 19, 2025

There are errors now:

Error: /home/runner/work/UDC-Bot/UDC-Bot/DiscordBot/Modules/UserSlashModule.cs(335,30): error CS7036: There is no argument given that corresponds to the required formal parame...

Fixed the ConcurrentDictionary compilation errors by replacing Remove() calls with TryRemove(key, out _) in commit 7ca33eb. The build now succeeds without errors.

@Pierre-Demessence
Copy link
Member

/deploy_dev

@github-actions
Copy link

🚀 Starting deployment of Unity-Developer-Community/UDC-Bot:copilot/fix-333 to development...

@Pierre-Demessence Pierre-Demessence merged commit 91f4448 into master Jul 19, 2025
8 of 9 checks passed
@Pierre-Demessence Pierre-Demessence deleted the copilot/fix-333 branch July 19, 2025 01:25
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.

Duel command

2 participants