* Remove template in favor of official samples * Fixed a variable name copy pasta mistake line 35 was _database.GetData() instead of DBService.GetData() * Experimental theme change * Change paragraph, code, heading fonts * Widen viewport * Update DocFX.Plugins.LastModified v1.2.3 * Exclude Discord.API in docs * Add remarks for SocketReaction properties * Add examples for BaseSocketClient.Events * Add additional clarification for some methods * Move IUser and IGuildChannel examples * Clarify several guides samples with notes - Reword TypeReader comment to avoid giving the idea that the sample itself is "obsolete" - Remove CommandException logging comment regarding C#7.0 as the version is now the standard across VS2017 and up - Remove suggestion about handling result in command handler since it is now advised to use CommandExecuted instead + Add additional comment to clarify ctor for DI setup * Add/migrate code examples * Incorporate material design theme License @ https://github.com/ovasquez * Update installation and nightly guide * Fix improper indentations made obvious by the widen viewport * Fix minor grammar issues + Add installation for nightly build using dotnet CLI * Fix nav level indentation * Revise "Your First Bot" article * Merge some paragraphs to avoid clutter while keeping readability * Reword the use of command framework + Add additional warning/note about environment variable * Add additional indent level * Fix indentation text warping * Remove connections sample * Update logging sample Remove redundant part of the sample * Remove mention of RPC * Remove misleading section about commands - Remove command sample from complete snippet * Revise "Your First Bot" command paragraphs * Change wording to hint devs that additional command parser packages may be available, as more and more begin to crop up * Update themes * Add XML docs contribution guidelines Update guidelines * Update CommandExecuted remarks * Fix precondition remarks typo no one saw that ok * Fix permission sample in docfx * Fix IMessageChannel samples * Update docs/_template/light-dark-theme/styles/docfx.vendor.minify.css Co-Authored-By: Still34 <341464@gmail.com> * Update docs/_template/light-dark-theme/styles/material.css Co-Authored-By: Still34 <341464@gmail.com> * Update docs/_template/light-dark-theme/styles/material.css Co-Authored-By: Still34 <341464@gmail.com>
111 lines
4.4 KiB
C#
111 lines
4.4 KiB
C#
using Model = Discord.API.Gateway.Reaction;
|
|
|
|
namespace Discord.WebSocket
|
|
{
|
|
/// <summary>
|
|
/// Represents a WebSocket-based reaction object.
|
|
/// </summary>
|
|
public class SocketReaction : IReaction
|
|
{
|
|
/// <summary>
|
|
/// Gets the ID of the user who added the reaction.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// This property retrieves the snowflake identifier of the user responsible for this reaction. This
|
|
/// property will always contain the user identifier in event that
|
|
/// <see cref="Discord.WebSocket.SocketReaction.User" /> cannot be retrieved.
|
|
/// </remarks>
|
|
/// <returns>
|
|
/// A user snowflake identifier associated with the user.
|
|
/// </returns>
|
|
public ulong UserId { get; }
|
|
/// <summary>
|
|
/// Gets the user who added the reaction if possible.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This property attempts to retrieve a WebSocket-cached user that is responsible for this reaction from
|
|
/// the client. In other words, when the user is not in the WebSocket cache, this property may not
|
|
/// contain a value, leaving the only identifiable information to be
|
|
/// <see cref="Discord.WebSocket.SocketReaction.UserId" />.
|
|
/// </para>
|
|
/// <para>
|
|
/// If you wish to obtain an identifiable user object, consider utilizing
|
|
/// <see cref="Discord.Rest.DiscordRestClient" /> which will attempt to retrieve the user from REST.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <returns>
|
|
/// A user object where possible; a value is not always returned.
|
|
/// </returns>
|
|
/// <seealso cref="Optional{T}"/>
|
|
public Optional<IUser> User { get; }
|
|
/// <summary>
|
|
/// Gets the ID of the message that has been reacted to.
|
|
/// </summary>
|
|
/// <returns>
|
|
/// A message snowflake identifier associated with the message.
|
|
/// </returns>
|
|
public ulong MessageId { get; }
|
|
/// <summary>
|
|
/// Gets the message that has been reacted to if possible.
|
|
/// </summary>
|
|
/// <returns>
|
|
/// A WebSocket-based message where possible; a value is not always returned.
|
|
/// </returns>
|
|
/// <seealso cref="Optional{T}"/>
|
|
public Optional<SocketUserMessage> Message { get; }
|
|
/// <summary>
|
|
/// Gets the channel where the reaction takes place in.
|
|
/// </summary>
|
|
/// <returns>
|
|
/// A WebSocket-based message channel.
|
|
/// </returns>
|
|
public ISocketMessageChannel Channel { get; }
|
|
/// <inheritdoc />
|
|
public IEmote Emote { get; }
|
|
|
|
internal SocketReaction(ISocketMessageChannel channel, ulong messageId, Optional<SocketUserMessage> message, ulong userId, Optional<IUser> user, IEmote emoji)
|
|
{
|
|
Channel = channel;
|
|
MessageId = messageId;
|
|
Message = message;
|
|
UserId = userId;
|
|
User = user;
|
|
Emote = emoji;
|
|
}
|
|
internal static SocketReaction Create(Model model, ISocketMessageChannel channel, Optional<SocketUserMessage> message, Optional<IUser> user)
|
|
{
|
|
IEmote emote;
|
|
if (model.Emoji.Id.HasValue)
|
|
emote = new Emote(model.Emoji.Id.Value, model.Emoji.Name, model.Emoji.Animated.GetValueOrDefault());
|
|
else
|
|
emote = new Emoji(model.Emoji.Name);
|
|
return new SocketReaction(channel, model.MessageId, message, model.UserId, user, emote);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override bool Equals(object other)
|
|
{
|
|
if (other == null) return false;
|
|
if (other == this) return true;
|
|
|
|
var otherReaction = other as SocketReaction;
|
|
if (otherReaction == null) return false;
|
|
|
|
return UserId == otherReaction.UserId && MessageId == otherReaction.MessageId && Emote.Equals(otherReaction.Emote);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override int GetHashCode()
|
|
{
|
|
unchecked
|
|
{
|
|
var hashCode = UserId.GetHashCode();
|
|
hashCode = (hashCode * 397) ^ MessageId.GetHashCode();
|
|
hashCode = (hashCode * 397) ^ Emote.GetHashCode();
|
|
return hashCode;
|
|
}
|
|
}
|
|
}
|
|
}
|