diff --git a/src/Discord.Net.WebSocket/DiscordShardedClient.cs b/src/Discord.Net.WebSocket/DiscordShardedClient.cs index 06f83c8dc..cb1f32fab 100644 --- a/src/Discord.Net.WebSocket/DiscordShardedClient.cs +++ b/src/Discord.Net.WebSocket/DiscordShardedClient.cs @@ -297,7 +297,7 @@ namespace Discord.WebSocket client.UserBanned += (user, guild) => _userBannedEvent.InvokeAsync(user, guild); client.UserUnbanned += (user, guild) => _userUnbannedEvent.InvokeAsync(user, guild); client.UserUpdated += (oldUser, newUser) => _userUpdatedEvent.InvokeAsync(oldUser, newUser); - client.UserPresenceUpdated += (guild, user, oldPresence, newPresence) => _userPresenceUpdatedEvent.InvokeAsync(guild, user, oldPresence, newPresence); + client.GuildMemberUpdated += (oldUser, newUser) => _guildMemberUpdatedEvent.InvokeAsync(oldUser, newUser); client.UserVoiceStateUpdated += (user, oldVoiceState, newVoiceState) => _userVoiceStateUpdatedEvent.InvokeAsync(user, oldVoiceState, newVoiceState); client.CurrentUserUpdated += (oldUser, newUser) => _selfUpdatedEvent.InvokeAsync(oldUser, newUser); client.UserIsTyping += (oldUser, newUser) => _userIsTypingEvent.InvokeAsync(oldUser, newUser); diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.Events.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.Events.cs index 313e661f3..fb155e535 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.Events.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.Events.cs @@ -185,12 +185,6 @@ namespace Discord.WebSocket remove { _guildMemberUpdatedEvent.Remove(value); } } private readonly AsyncEvent> _guildMemberUpdatedEvent = new AsyncEvent>(); - public event Func, SocketUser, SocketPresence, SocketPresence, Task> UserPresenceUpdated - { - add { _userPresenceUpdatedEvent.Add(value); } - remove { _userPresenceUpdatedEvent.Remove(value); } - } - private readonly AsyncEvent, SocketUser, SocketPresence, SocketPresence, Task>> _userPresenceUpdatedEvent = new AsyncEvent, SocketUser, SocketPresence, SocketPresence, Task>>(); public event Func UserVoiceStateUpdated { add { _userVoiceStateUpdatedEvent.Add(value); } diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index 1dcf7dd5b..71ba813d5 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -1318,46 +1318,16 @@ namespace Discord.WebSocket return; } - SocketPresence beforePresence; - SocketGlobalUser beforeGlobal; var user = guild.GetUser(data.User.Id); - if (user != null) - { - beforePresence = user.Presence.Clone(); - beforeGlobal = user.GlobalUser.Clone(); - user.Update(State, data); - } - else - { - beforePresence = new SocketPresence(UserStatus.Offline, null); - user = guild.AddOrUpdateUser(data); - beforeGlobal = user.GlobalUser.Clone(); - } - - if (data.User.Username.IsSpecified || data.User.Avatar.IsSpecified) - { - await _userUpdatedEvent.InvokeAsync(beforeGlobal, user).ConfigureAwait(false); - return; - } - await _userPresenceUpdatedEvent.InvokeAsync(guild, user, beforePresence, user.Presence).ConfigureAwait(false); + if (user == null) + guild.AddOrUpdateUser(data); } - else - { - var channel = State.GetChannel(data.User.Id); - if (channel != null) - { - var user = channel.GetUser(data.User.Id); - var beforePresence = user.Presence.Clone(); - var before = user.GlobalUser.Clone(); - user.Update(State, data); - await _userPresenceUpdatedEvent.InvokeAsync(Optional.Create(), user, beforePresence, user.Presence).ConfigureAwait(false); - if (data.User.Username.IsSpecified || data.User.Avatar.IsSpecified) - { - await _userUpdatedEvent.InvokeAsync(before, user).ConfigureAwait(false); - } - } - } + var globalUser = State.GetUser(data.User.Id); + var before = globalUser.Clone(); + globalUser.Update(State, data); + + await _userUpdatedEvent.InvokeAsync(before, globalUser).ConfigureAwait(false); } break; case "TYPING_START":