Skip to content

Commit

Permalink
feature: Remove /users/@me call for socket and rework sharded client …
Browse files Browse the repository at this point in the history
…a bit (#1860)

* Remove /users/@me call for socket and rework sharded client a bit

* Remove override for login
  • Loading branch information
SubZero0 committed May 28, 2021
1 parent de7f9b5 commit 384ad85
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Discord.Net.WebSocket/BaseSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public abstract partial class BaseSocketClient : BaseDiscordClient, IDiscordClie
/// <summary>
/// Gets the current logged-in user.
/// </summary>
public new SocketSelfUser CurrentUser { get => base.CurrentUser as SocketSelfUser; protected set => base.CurrentUser = value; }
public virtual new SocketSelfUser CurrentUser { get => base.CurrentUser as SocketSelfUser; protected set => base.CurrentUser = value; }
/// <summary>
/// Gets a collection of guilds that the user is currently in.
/// </summary>
Expand Down
12 changes: 3 additions & 9 deletions src/Discord.Net.WebSocket/DiscordShardedClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public partial class DiscordShardedClient : BaseSocketClient, IDiscordClient
/// <summary>
/// Provides access to a REST-only client with a shared state from this client.
/// </summary>
public override DiscordSocketRestClient Rest => _shards[0].Rest;
public override DiscordSocketRestClient Rest => _shards?[0].Rest;

public override SocketSelfUser CurrentUser { get => _shards?.FirstOrDefault(x => x.CurrentUser != null)?.CurrentUser; protected set => throw new InvalidOperationException(); }

/// <summary> Creates a new REST/WebSocket Discord client. </summary>
public DiscordShardedClient() : this(null, new DiscordSocketConfig()) { }
Expand Down Expand Up @@ -330,14 +332,6 @@ private void RegisterEvents(DiscordSocketClient client, bool isPrimary)
}
return Task.Delay(0);
};
if (isPrimary)
{
client.Ready += () =>
{
CurrentUser = client.CurrentUser;
return Task.Delay(0);
};
}

client.Connected += () => _shardConnectedEvent.InvokeAsync(client);
client.Disconnected += (exception) => _shardDisconnectedEvent.InvokeAsync(exception, client);
Expand Down
5 changes: 0 additions & 5 deletions src/Discord.Net.WebSocket/DiscordSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,6 @@ internal override void Dispose(bool disposing)
base.Dispose(disposing);
}

/// <inheritdoc />
internal override async Task OnLoginAsync(TokenType tokenType, string token)
{
await Rest.OnLoginAsync(tokenType, token);
}
/// <inheritdoc />
internal override async Task OnLogoutAsync()
{
Expand Down

0 comments on commit 384ad85

Please sign in to comment.