Wycademy/src/Wycademy/Commands/Services/DamageCalculatorService.cs
/// <summary>
/// Process reactions added to a message.
/// </summary>
/// <param name="id">The id of the message that the reaction was added to.</param>
/// <param name="userMessage">The message object itself.</param>
/// <param name="reaction">The reaction added.</param>
Process reactions added to a message.
Process reactions added to a message .
private async Task OnReactionAdded(Cacheable<IUserMessage, ulong> cacheable, ISocketMessageChannel channel, SocketReaction reaction)
        {
            var message = await cacheable.GetOrDownloadAsync();
            if (!reaction.User.IsSpecified) return;
            DamageCalculatorMessage calcMessage;
            if (_messages.TryGetValue(cacheable.Id, out calcMessage))
            {
                if (_client.CurrentUser.Id == reaction.UserId) return;
                if (calcMessage.User.Id != reaction.UserId) return;
                switch (reaction.Emote.Name)
                {
                    case FOUR:
                        if (calcMessage.Weapon == WeaponType.Prowler)
                        {
                            await message.ModifyAsync(x => x.Content = "Nice try, but Prowlers aren't in 4U.");
                            _messages.Remove(cacheable.Id);
                        }
                        else
                        {
                            await message.ModifyAsync(x => x.Content = GetResponseMessage4U(calcMessage));
                            _messages.Remove(cacheable.Id);
                        }
                        break;
                    case G:
                        await message.ModifyAsync(x => x.Content = GetResponseMessageGen(calcMessage));
                        _messages.Remove(cacheable.Id);
                        break;
                    default:
                        break;
                }
            }
        }
private async Task OnReactionAdded ( Cacheable < IUserMessage , ulong > cacheable , ISocketMessageChannel channel , SocketReaction reaction ) { var message = await cacheable . GetOrDownloadAsync ( ) ; if ( ! reaction . User . IsSpecified ) return ; DamageCalculatorMessage calcMessage ; if ( _messages . TryGetValue ( cacheable . Id , out calcMessage ) ) { if ( _client . CurrentUser . Id == reaction . UserId ) return ; if ( calcMessage . User . Id != reaction . UserId ) return ; switch ( reaction . Emote . Name ) { case FOUR : if ( calcMessage . Weapon == WeaponType . Prowler ) { await message . ModifyAsync ( x => x . Content = " " ) ; _messages . Remove ( cacheable . Id ) ; } else { await message . ModifyAsync ( x => x . Content = GetResponseMessage4U ( calcMessage ) ) ; _messages . Remove ( cacheable . Id ) ; } break ; case G : await message . ModifyAsync ( x => x . Content = GetResponseMessageGen ( calcMessage ) ) ; _messages . Remove ( cacheable . Id ) ; break ; default : break ; } } }
Process reactions added to a message.
Process reactions added to a message .
// If the reaction doesn't have a user associated with it assume it's the incorrect user. // Make sure the reaction is added to a DamageCalculatorMessage and not something else. // Don't trigger anything when the bot is originally adding the reactions. // Ignore the reaction if it isn't by the user who added the command.  // Check whether the user chose 4U or Gen and edit the message accordingly. // If a different reaction was added, then just ignore it.
cacheable
Cacheable<IUserMessage, ulong>
channel
ISocketMessageChannel
reaction
SocketReaction
The reaction added.
The reaction added .
id
The id of the message that the reaction was added to.
The id of the message that the reaction was added to .
userMessage
The message object itself.
The message object itself .