Restructure and replace emojis with a new emote system (#619)
This commit is contained in:
committed by
RogueException
parent
ba1982a3f9
commit
576a52cdc6
@@ -30,7 +30,7 @@ namespace Discord.WebSocket
|
||||
private ConcurrentDictionary<ulong, SocketGuildUser> _members;
|
||||
private ConcurrentDictionary<ulong, SocketRole> _roles;
|
||||
private ConcurrentDictionary<ulong, SocketVoiceState> _voiceStates;
|
||||
private ImmutableArray<GuildEmoji> _emojis;
|
||||
private ImmutableArray<GuildEmote> _emotes;
|
||||
private ImmutableArray<string> _features;
|
||||
private AudioClient _audioClient;
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace Discord.WebSocket
|
||||
return channels.Select(x => state.GetChannel(x) as SocketGuildChannel).Where(x => x != null).ToReadOnlyCollection(channels);
|
||||
}
|
||||
}
|
||||
public IReadOnlyCollection<GuildEmoji> Emojis => _emojis;
|
||||
public IReadOnlyCollection<GuildEmote> Emotes => _emotes;
|
||||
public IReadOnlyCollection<string> Features => _features;
|
||||
public IReadOnlyCollection<SocketGuildUser> Users => _members.ToReadOnlyCollection();
|
||||
public IReadOnlyCollection<SocketRole> Roles => _roles.ToReadOnlyCollection();
|
||||
@@ -102,7 +102,7 @@ namespace Discord.WebSocket
|
||||
: base(client, id)
|
||||
{
|
||||
_audioLock = new SemaphoreSlim(1, 1);
|
||||
_emojis = ImmutableArray.Create<GuildEmoji>();
|
||||
_emotes = ImmutableArray.Create<GuildEmote>();
|
||||
_features = ImmutableArray.Create<string>();
|
||||
}
|
||||
internal static SocketGuild Create(DiscordSocketClient discord, ClientState state, ExtendedModel model)
|
||||
@@ -201,13 +201,13 @@ namespace Discord.WebSocket
|
||||
|
||||
if (model.Emojis != null)
|
||||
{
|
||||
var emojis = ImmutableArray.CreateBuilder<GuildEmoji>(model.Emojis.Length);
|
||||
var emojis = ImmutableArray.CreateBuilder<GuildEmote>(model.Emojis.Length);
|
||||
for (int i = 0; i < model.Emojis.Length; i++)
|
||||
emojis.Add(model.Emojis[i].ToEntity());
|
||||
_emojis = emojis.ToImmutable();
|
||||
_emotes = emojis.ToImmutable();
|
||||
}
|
||||
else
|
||||
_emojis = ImmutableArray.Create<GuildEmoji>();
|
||||
_emotes = ImmutableArray.Create<GuildEmote>();
|
||||
|
||||
if (model.Features != null)
|
||||
_features = model.Features.ToImmutableArray();
|
||||
@@ -253,10 +253,10 @@ namespace Discord.WebSocket
|
||||
|
||||
internal void Update(ClientState state, EmojiUpdateModel model)
|
||||
{
|
||||
var emojis = ImmutableArray.CreateBuilder<GuildEmoji>(model.Emojis.Length);
|
||||
var emotes = ImmutableArray.CreateBuilder<GuildEmote>(model.Emojis.Length);
|
||||
for (int i = 0; i < model.Emojis.Length; i++)
|
||||
emojis.Add(model.Emojis[i].ToEntity());
|
||||
_emojis = emojis.ToImmutable();
|
||||
emotes.Add(model.Emojis[i].ToEntity());
|
||||
_emotes = emotes.ToImmutable();
|
||||
}
|
||||
|
||||
//General
|
||||
|
||||
@@ -9,20 +9,25 @@ namespace Discord.WebSocket
|
||||
public ulong MessageId { get; }
|
||||
public Optional<SocketUserMessage> Message { get; }
|
||||
public ISocketMessageChannel Channel { get; }
|
||||
public Emoji Emoji { get; }
|
||||
public IEmote Emote { get; }
|
||||
|
||||
internal SocketReaction(ISocketMessageChannel channel, ulong messageId, Optional<SocketUserMessage> message, ulong userId, Optional<IUser> user, Emoji emoji)
|
||||
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;
|
||||
Emoji = emoji;
|
||||
Emote = emoji;
|
||||
}
|
||||
internal static SocketReaction Create(Model model, ISocketMessageChannel channel, Optional<SocketUserMessage> message, Optional<IUser> user)
|
||||
{
|
||||
return new SocketReaction(channel, model.MessageId, message, model.UserId, user, new Emoji(model.Emoji.Id, model.Emoji.Name));
|
||||
IEmote emote;
|
||||
if (model.Emoji.Id.HasValue)
|
||||
emote = new Emote(model.Emoji.Id.Value, model.Emoji.Name);
|
||||
else
|
||||
emote = new Emoji(model.Emoji.Name);
|
||||
return new SocketReaction(channel, model.MessageId, message, model.UserId, user, emote);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Discord.WebSocket
|
||||
public override IReadOnlyCollection<SocketGuildChannel> MentionedChannels => MessageHelper.FilterTagsByValue<SocketGuildChannel>(TagType.ChannelMention, _tags);
|
||||
public override IReadOnlyCollection<SocketRole> MentionedRoles => MessageHelper.FilterTagsByValue<SocketRole>(TagType.RoleMention, _tags);
|
||||
public override IReadOnlyCollection<SocketUser> MentionedUsers => MessageHelper.FilterTagsByValue<SocketUser>(TagType.UserMention, _tags);
|
||||
public IReadOnlyDictionary<Emoji, ReactionMetadata> Reactions => _reactions.GroupBy(r => r.Emoji).ToDictionary(x => x.Key, x => new ReactionMetadata { ReactionCount = x.Count(), IsMe = x.Any(y => y.UserId == Discord.CurrentUser.Id) });
|
||||
public IReadOnlyDictionary<IEmote, ReactionMetadata> Reactions => _reactions.GroupBy(r => r.Emote).ToDictionary(x => x.Key, x => new ReactionMetadata { ReactionCount = x.Count(), IsMe = x.Any(y => y.UserId == Discord.CurrentUser.Id) });
|
||||
|
||||
internal SocketUserMessage(DiscordSocketClient discord, ulong id, ISocketMessageChannel channel, SocketUser author, MessageSource source)
|
||||
: base(discord, id, channel, author, source)
|
||||
@@ -124,16 +124,10 @@ namespace Discord.WebSocket
|
||||
public Task ModifyAsync(Action<MessageProperties> func, RequestOptions options = null)
|
||||
=> MessageHelper.ModifyAsync(this, Discord, func, options);
|
||||
|
||||
public Task AddReactionAsync(Emoji emoji, RequestOptions options = null)
|
||||
=> MessageHelper.AddReactionAsync(this, emoji, Discord, options);
|
||||
public Task AddReactionAsync(string emoji, RequestOptions options = null)
|
||||
=> MessageHelper.AddReactionAsync(this, emoji, Discord, options);
|
||||
|
||||
public Task RemoveReactionAsync(Emoji emoji, IUser user, RequestOptions options = null)
|
||||
=> MessageHelper.RemoveReactionAsync(this, user, emoji, Discord, options);
|
||||
public Task RemoveReactionAsync(string emoji, IUser user, RequestOptions options = null)
|
||||
=> MessageHelper.RemoveReactionAsync(this, user, emoji, Discord, options);
|
||||
|
||||
public Task AddReactionAsync(IEmote emote, RequestOptions options = null)
|
||||
=> MessageHelper.AddReactionAsync(this, emote, Discord, options);
|
||||
public Task RemoveReactionAsync(IEmote emote, IUser user, RequestOptions options = null)
|
||||
=> MessageHelper.RemoveReactionAsync(this, user, emote, Discord, options);
|
||||
public Task RemoveAllReactionsAsync(RequestOptions options = null)
|
||||
=> MessageHelper.RemoveAllReactionsAsync(this, Discord, options);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user