Browse Source

Merge branch 'dev' of https://github.com/discord-net/Discord.Net into dev

pull/1958/head
quin lynch 4 years ago
parent
commit
ba8b9aee8a
12 changed files with 30 additions and 38 deletions
  1. +0
    -1
      azure-pipelines.yml
  2. +1
    -1
      src/Discord.Net.Core/Entities/Messages/IMessage.cs
  3. +1
    -1
      src/Discord.Net.Rest/DiscordRestClient.cs
  4. +4
    -2
      src/Discord.Net.Rest/Entities/Messages/RestMessage.cs
  5. +0
    -5
      src/Discord.Net.Rest/Entities/Messages/RestSystemMessage.cs
  6. +1
    -15
      src/Discord.Net.WebSocket/ConnectionManager.cs
  7. +2
    -2
      src/Discord.Net.WebSocket/DiscordSocketApiClient.cs
  8. +1
    -0
      src/Discord.Net.WebSocket/DiscordSocketClient.cs
  9. +5
    -2
      src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs
  10. +0
    -5
      src/Discord.Net.WebSocket/Entities/Messages/SocketSystemMessage.cs
  11. +4
    -0
      src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs
  12. +11
    -4
      src/Discord.Net.WebSocket/Net/DefaultWebSocketClient.cs

+ 0
- 1
azure-pipelines.yml View File

@@ -39,4 +39,3 @@ jobs:
steps:
- template: azure/build.yml
- template: azure/deploy.yml
- template: azure/docs.yml

+ 1
- 1
src/Discord.Net.Core/Entities/Messages/IMessage.cs View File

@@ -10,7 +10,7 @@ namespace Discord
public interface IMessage : ISnowflakeEntity, IDeletable
{
/// <summary>
/// Gets the type of this system message.
/// Gets the type of this message.
/// </summary>
MessageType Type { get; }
/// <summary>


+ 1
- 1
src/Discord.Net.Rest/DiscordRestClient.cs View File

@@ -16,7 +16,7 @@ namespace Discord.Rest
/// <summary>
/// Gets the logged-in user.
/// </summary>
public new RestSelfUser CurrentUser => base.CurrentUser as RestSelfUser;
public new RestSelfUser CurrentUser { get => base.CurrentUser as RestSelfUser; internal set => base.CurrentUser = value; }

/// <inheritdoc />
public DiscordRestClient() : this(new DiscordRestConfig()) { }


+ 4
- 2
src/Discord.Net.Rest/Entities/Messages/RestMessage.cs View File

@@ -71,6 +71,8 @@ namespace Discord.Rest
public MessageReference Reference { get; private set; }
/// <inheritdoc />
public MessageFlags? Flags { get; private set; }
/// <inheritdoc/>
public MessageType Type { get; private set; }

internal RestMessage(BaseDiscordClient discord, ulong id, IMessageChannel channel, IUser author, MessageSource source)
: base(discord, id)
@@ -88,6 +90,8 @@ namespace Discord.Rest
}
internal virtual void Update(Model model)
{
Type = model.Type;

if (model.Timestamp.IsSpecified)
_timestampTicks = model.Timestamp.Value.UtcTicks;

@@ -166,8 +170,6 @@ namespace Discord.Rest
/// </returns>
public override string ToString() => Content;

/// <inheritdoc />
MessageType IMessage.Type => MessageType.Default;
IUser IMessage.Author => Author;
/// <inheritdoc />
IReadOnlyCollection<IAttachment> IMessage.Attachments => Attachments;


+ 0
- 5
src/Discord.Net.Rest/Entities/Messages/RestSystemMessage.cs View File

@@ -9,9 +9,6 @@ namespace Discord.Rest
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class RestSystemMessage : RestMessage, ISystemMessage
{
/// <inheritdoc />
public MessageType Type { get; private set; }

internal RestSystemMessage(BaseDiscordClient discord, ulong id, IMessageChannel channel, IUser author)
: base(discord, id, channel, author, MessageSource.System)
{
@@ -25,8 +22,6 @@ namespace Discord.Rest
internal override void Update(Model model)
{
base.Update(model);

Type = model.Type;
}

private string DebuggerDisplay => $"{Author}: {Content} ({Id}, {Type})";


+ 1
- 15
src/Discord.Net.WebSocket/ConnectionManager.cs View File

@@ -75,11 +75,6 @@ namespace Discord
nextReconnectDelay = 1000; //Reset delay
await _connectionPromise.Task.ConfigureAwait(false);
}
catch (OperationCanceledException ex)
{
Cancel(); //In case this exception didn't come from another Error call
await DisconnectAsync(ex, !reconnectCancelToken.IsCancellationRequested).ConfigureAwait(false);
}
catch (Exception ex)
{
Error(ex); //In case this exception didn't come from another Error call
@@ -143,16 +138,7 @@ namespace Discord
catch (OperationCanceledException) { }
});

try
{
await _onConnecting().ConfigureAwait(false);
}
catch (TaskCanceledException ex)
{
Exception innerEx = ex.InnerException ?? new OperationCanceledException("Failed to connect.");
Error(innerEx);
throw innerEx;
}
await _onConnecting().ConfigureAwait(false);

await _logger.InfoAsync("Connected").ConfigureAwait(false);
State = ConnectionState.Connected;


+ 2
- 2
src/Discord.Net.WebSocket/DiscordSocketApiClient.cs View File

@@ -188,9 +188,9 @@ namespace Discord.API
catch { }

if (ex is GatewayReconnectException)
await WebSocketClient.DisconnectAsync(4000);
await WebSocketClient.DisconnectAsync(4000).ConfigureAwait(false);
else
await WebSocketClient.DisconnectAsync().ConfigureAwait(false);
await WebSocketClient.DisconnectAsync().ConfigureAwait(false);

ConnectionState = ConnectionState.Disconnected;
}


+ 1
- 0
src/Discord.Net.WebSocket/DiscordSocketClient.cs View File

@@ -618,6 +618,7 @@ namespace Discord.WebSocket
var activities = _activity.IsSpecified ? ImmutableList.Create(_activity.Value) : null;
currentUser.Presence = new SocketPresence(Status, null, activities);
ApiClient.CurrentUserId = currentUser.Id;
Rest.CurrentUser = RestSelfUser.Create(this, data.User);
int unavailableGuilds = 0;
for (int i = 0; i < data.Guilds.Length; i++)
{


+ 5
- 2
src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs View File

@@ -61,6 +61,9 @@ namespace Discord.WebSocket
/// <inheritdoc />
public MessageFlags? Flags { get; private set; }

/// <inheritdoc/>
public MessageType Type { get; private set; }

/// <summary>
/// Returns all attachments included in this message.
/// </summary>
@@ -122,6 +125,8 @@ namespace Discord.WebSocket
}
internal virtual void Update(ClientState state, Model model)
{
Type = model.Type;

if (model.Timestamp.IsSpecified)
_timestampTicks = model.Timestamp.Value.UtcTicks;

@@ -185,8 +190,6 @@ namespace Discord.WebSocket
/// <inheritdoc />
IMessageChannel IMessage.Channel => Channel;
/// <inheritdoc />
MessageType IMessage.Type => MessageType.Default;
/// <inheritdoc />
IReadOnlyCollection<IAttachment> IMessage.Attachments => Attachments;
/// <inheritdoc />
IReadOnlyCollection<IEmbed> IMessage.Embeds => Embeds;


+ 0
- 5
src/Discord.Net.WebSocket/Entities/Messages/SocketSystemMessage.cs View File

@@ -9,9 +9,6 @@ namespace Discord.WebSocket
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class SocketSystemMessage : SocketMessage, ISystemMessage
{
/// <inheritdoc />
public MessageType Type { get; private set; }

internal SocketSystemMessage(DiscordSocketClient discord, ulong id, ISocketMessageChannel channel, SocketUser author)
: base(discord, id, channel, author, MessageSource.System)
{
@@ -25,8 +22,6 @@ namespace Discord.WebSocket
internal override void Update(ClientState state, Model model)
{
base.Update(state, model);

Type = model.Type;
}
private string DebuggerDisplay => $"{Author}: {Content} ({Id}, {Type})";


+ 4
- 0
src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs View File

@@ -125,12 +125,16 @@ namespace Discord.WebSocket
{
var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model.User));
entity.Update(state, model);
if (!model.Roles.IsSpecified)
entity.UpdateRoles(new ulong[0]);
return entity;
}
internal static SocketGuildUser Create(SocketGuild guild, ClientState state, PresenceModel model)
{
var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model.User));
entity.Update(state, model, false);
if (!model.Roles.IsSpecified)
entity.UpdateRoles(new ulong[0]);
return entity;
}
internal void Update(ClientState state, MemberModel model)


+ 11
- 4
src/Discord.Net.WebSocket/Net/DefaultWebSocketClient.cs View File

@@ -108,11 +108,11 @@ namespace Discord.Net.WebSockets
}
private async Task DisconnectInternalAsync(int closeCode = 1000, bool isDisposing = false)
{
_isDisconnecting = true;

try { _disconnectTokenSource.Cancel(false); }
catch { }

_isDisconnecting = true;

if (_client != null)
{
if (!isDisposing)
@@ -166,7 +166,14 @@ namespace Discord.Net.WebSockets

public async Task SendAsync(byte[] data, int index, int count, bool isText)
{
await _lock.WaitAsync().ConfigureAwait(false);
try
{
await _lock.WaitAsync(_cancelToken).ConfigureAwait(false);
}
catch (TaskCanceledException)
{
return;
}
try
{
if (_client == null) return;
@@ -201,7 +208,7 @@ namespace Discord.Net.WebSockets
{
while (!cancelToken.IsCancellationRequested)
{
WebSocketReceiveResult socketResult = await _client.ReceiveAsync(buffer, CancellationToken.None).ConfigureAwait(false);
WebSocketReceiveResult socketResult = await _client.ReceiveAsync(buffer, cancelToken).ConfigureAwait(false);
byte[] result;
int resultCount;



Loading…
Cancel
Save