[Refactor] Remove some unnecessary async/await (#2739)
* Remove some unnecessary async/await * More not-so-async stuff * More not-so-async stuff * Fix merge issue
This commit is contained in:
@@ -95,13 +95,13 @@ namespace Discord.Audio
|
||||
UdpLatencyUpdated += async (old, val) => await _audioLogger.DebugAsync($"UDP Latency = {val} ms").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
internal async Task StartAsync(string url, ulong userId, string sessionId, string token)
|
||||
internal Task StartAsync(string url, ulong userId, string sessionId, string token)
|
||||
{
|
||||
_url = url;
|
||||
_userId = userId;
|
||||
_sessionId = sessionId;
|
||||
_token = token;
|
||||
await _connection.StartAsync().ConfigureAwait(false);
|
||||
return _connection.StartAsync();
|
||||
}
|
||||
|
||||
public IReadOnlyDictionary<ulong, AudioInStream> GetStreams()
|
||||
@@ -109,10 +109,8 @@ namespace Discord.Audio
|
||||
return _streams.ToDictionary(pair => pair.Key, pair => pair.Value.Reader);
|
||||
}
|
||||
|
||||
public async Task StopAsync()
|
||||
{
|
||||
await _connection.StopAsync().ConfigureAwait(false);
|
||||
}
|
||||
public Task StopAsync()
|
||||
=> _connection.StopAsync();
|
||||
|
||||
private async Task OnConnectingAsync()
|
||||
{
|
||||
|
||||
@@ -47,14 +47,11 @@ namespace Discord.Audio.Streams
|
||||
return _next.WriteAsync(_buffer, 0, count, cancelToken);
|
||||
}
|
||||
|
||||
public override async Task FlushAsync(CancellationToken cancelToken)
|
||||
{
|
||||
await _next.FlushAsync(cancelToken).ConfigureAwait(false);
|
||||
}
|
||||
public override async Task ClearAsync(CancellationToken cancelToken)
|
||||
{
|
||||
await _next.ClearAsync(cancelToken).ConfigureAwait(false);
|
||||
}
|
||||
public override Task FlushAsync(CancellationToken cancelToken)
|
||||
=> _next.FlushAsync(cancelToken);
|
||||
|
||||
public override Task ClearAsync(CancellationToken cancelToken)
|
||||
=> _next.ClearAsync(cancelToken);
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
|
||||
@@ -103,14 +103,11 @@ namespace Discord.Audio.Streams
|
||||
await base.FlushAsync(cancelToken).ConfigureAwait(false);
|
||||
}*/
|
||||
|
||||
public override async Task FlushAsync(CancellationToken cancelToken)
|
||||
{
|
||||
await _next.FlushAsync(cancelToken).ConfigureAwait(false);
|
||||
}
|
||||
public override async Task ClearAsync(CancellationToken cancelToken)
|
||||
{
|
||||
await _next.ClearAsync(cancelToken).ConfigureAwait(false);
|
||||
}
|
||||
public override Task FlushAsync(CancellationToken cancelToken)
|
||||
=> _next.FlushAsync(cancelToken);
|
||||
|
||||
public override Task ClearAsync(CancellationToken cancelToken)
|
||||
=> _next.ClearAsync(cancelToken);
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
|
||||
@@ -15,10 +15,10 @@ namespace Discord.Audio.Streams
|
||||
}
|
||||
|
||||
public override void WriteHeader(ushort seq, uint timestamp, bool missed) { } //Ignore
|
||||
public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken)
|
||||
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken)
|
||||
{
|
||||
cancelToken.ThrowIfCancellationRequested();
|
||||
await _client.SendAsync(buffer, offset, count).ConfigureAwait(false);
|
||||
return _client.SendAsync(buffer, offset, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Discord.Audio.Streams
|
||||
|
||||
/// <exception cref="OperationCanceledException">The token has had cancellation requested.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The associated <see cref="T:System.Threading.CancellationTokenSource" /> has been disposed.</exception>
|
||||
public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken)
|
||||
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken)
|
||||
{
|
||||
cancelToken.ThrowIfCancellationRequested();
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Discord.Audio.Streams
|
||||
(buffer[offset + 7] << 0));
|
||||
|
||||
_next.WriteHeader(seq, timestamp, false);
|
||||
await _next.WriteAsync(buffer, offset + headerSize, count - headerSize, cancelToken).ConfigureAwait(false);
|
||||
return _next.WriteAsync(buffer, offset + headerSize, count - headerSize, cancelToken);
|
||||
}
|
||||
|
||||
public static bool TryReadSsrc(byte[] buffer, int offset, out uint ssrc)
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Discord.Audio.Streams
|
||||
_nextSeq = seq;
|
||||
_nextTimestamp = timestamp;
|
||||
}
|
||||
public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken)
|
||||
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken)
|
||||
{
|
||||
cancelToken.ThrowIfCancellationRequested();
|
||||
if (!_hasHeader)
|
||||
@@ -58,17 +58,14 @@ namespace Discord.Audio.Streams
|
||||
Buffer.BlockCopy(buffer, offset, _buffer, 12, count);
|
||||
|
||||
_next.WriteHeader(_nextSeq, _nextTimestamp, false);
|
||||
await _next.WriteAsync(_buffer, 0, count + 12).ConfigureAwait(false);
|
||||
return _next.WriteAsync(_buffer, 0, count + 12);
|
||||
}
|
||||
|
||||
public override async Task FlushAsync(CancellationToken cancelToken)
|
||||
{
|
||||
await _next.FlushAsync(cancelToken).ConfigureAwait(false);
|
||||
}
|
||||
public override async Task ClearAsync(CancellationToken cancelToken)
|
||||
{
|
||||
await _next.ClearAsync(cancelToken).ConfigureAwait(false);
|
||||
}
|
||||
public override Task FlushAsync(CancellationToken cancelToken)
|
||||
=> _next.FlushAsync(cancelToken);
|
||||
|
||||
public override Task ClearAsync(CancellationToken cancelToken)
|
||||
=> _next.ClearAsync(cancelToken);
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
|
||||
@@ -24,26 +24,23 @@ namespace Discord.Audio.Streams
|
||||
_nonce = new byte[24];
|
||||
}
|
||||
|
||||
public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken)
|
||||
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken)
|
||||
{
|
||||
cancelToken.ThrowIfCancellationRequested();
|
||||
|
||||
if (_client.SecretKey == null)
|
||||
return;
|
||||
return Task.CompletedTask;
|
||||
|
||||
Buffer.BlockCopy(buffer, 0, _nonce, 0, 12); //Copy RTP header to nonce
|
||||
count = SecretBox.Decrypt(buffer, offset + 12, count - 12, buffer, offset + 12, _nonce, _client.SecretKey);
|
||||
await _next.WriteAsync(buffer, 0, count + 12, cancelToken).ConfigureAwait(false);
|
||||
return _next.WriteAsync(buffer, 0, count + 12, cancelToken);
|
||||
}
|
||||
|
||||
public override async Task FlushAsync(CancellationToken cancelToken)
|
||||
{
|
||||
await _next.FlushAsync(cancelToken).ConfigureAwait(false);
|
||||
}
|
||||
public override async Task ClearAsync(CancellationToken cancelToken)
|
||||
{
|
||||
await _next.ClearAsync(cancelToken).ConfigureAwait(false);
|
||||
}
|
||||
public override Task FlushAsync(CancellationToken cancelToken)
|
||||
=> _next.FlushAsync(cancelToken);
|
||||
|
||||
public override Task ClearAsync(CancellationToken cancelToken)
|
||||
=> _next.ClearAsync(cancelToken);
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
|
||||
@@ -52,14 +52,11 @@ namespace Discord.Audio.Streams
|
||||
await _next.WriteAsync(buffer, 0, count + 12, cancelToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public override async Task FlushAsync(CancellationToken cancelToken)
|
||||
{
|
||||
await _next.FlushAsync(cancelToken).ConfigureAwait(false);
|
||||
}
|
||||
public override async Task ClearAsync(CancellationToken cancelToken)
|
||||
{
|
||||
await _next.ClearAsync(cancelToken).ConfigureAwait(false);
|
||||
}
|
||||
public override Task FlushAsync(CancellationToken cancelToken)
|
||||
=> _next.FlushAsync(cancelToken);
|
||||
|
||||
public override Task ClearAsync(CancellationToken cancelToken)
|
||||
=> _next.ClearAsync(cancelToken);
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
|
||||
@@ -177,14 +177,11 @@ namespace Discord
|
||||
await _logger.InfoAsync("Disconnected").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task CompleteAsync()
|
||||
{
|
||||
await _readyPromise.TrySetResultAsync(true).ConfigureAwait(false);
|
||||
}
|
||||
public async Task WaitAsync()
|
||||
{
|
||||
await _readyPromise.Task.ConfigureAwait(false);
|
||||
}
|
||||
public Task CompleteAsync()
|
||||
=> _readyPromise.TrySetResultAsync(true);
|
||||
|
||||
public Task WaitAsync()
|
||||
=> _readyPromise.Task;
|
||||
|
||||
public void Cancel()
|
||||
{
|
||||
|
||||
@@ -110,10 +110,10 @@ namespace Discord.WebSocket
|
||||
=> new DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent, config.GatewayHost,
|
||||
useSystemClock: config.UseSystemClock, defaultRatelimitCallback: config.DefaultRatelimitCallback);
|
||||
|
||||
internal async Task AcquireIdentifyLockAsync(int shardId, CancellationToken token)
|
||||
internal Task AcquireIdentifyLockAsync(int shardId, CancellationToken token)
|
||||
{
|
||||
int semaphoreIdx = shardId % _baseConfig.IdentifyMaxConcurrency;
|
||||
await _identifySemaphores[semaphoreIdx].WaitAsync(token).ConfigureAwait(false);
|
||||
return _identifySemaphores[semaphoreIdx].WaitAsync(token);
|
||||
}
|
||||
|
||||
internal void ReleaseIdentifyLock()
|
||||
@@ -198,11 +198,12 @@ namespace Discord.WebSocket
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task StartAsync()
|
||||
=> await Task.WhenAll(_shards.Select(x => x.StartAsync())).ConfigureAwait(false);
|
||||
public override Task StartAsync()
|
||||
=> Task.WhenAll(_shards.Select(x => x.StartAsync()));
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task StopAsync()
|
||||
=> await Task.WhenAll(_shards.Select(x => x.StopAsync())).ConfigureAwait(false);
|
||||
public override Task StopAsync()
|
||||
=> Task.WhenAll(_shards.Select(x => x.StopAsync()));
|
||||
|
||||
public DiscordSocketClient GetShard(int id)
|
||||
{
|
||||
@@ -220,8 +221,8 @@ namespace Discord.WebSocket
|
||||
=> GetShardFor(guild?.Id ?? 0);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task<RestApplication> GetApplicationInfoAsync(RequestOptions options = null)
|
||||
=> await _shards[0].GetApplicationInfoAsync(options).ConfigureAwait(false);
|
||||
public override Task<RestApplication> GetApplicationInfoAsync(RequestOptions options = null)
|
||||
=> _shards[0].GetApplicationInfoAsync(options);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SocketGuild GetGuild(ulong id)
|
||||
@@ -355,16 +356,12 @@ namespace Discord.WebSocket
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async ValueTask<IReadOnlyCollection<RestVoiceRegion>> GetVoiceRegionsAsync(RequestOptions options = null)
|
||||
{
|
||||
return await _shards[0].GetVoiceRegionsAsync().ConfigureAwait(false);
|
||||
}
|
||||
public override ValueTask<IReadOnlyCollection<RestVoiceRegion>> GetVoiceRegionsAsync(RequestOptions options = null)
|
||||
=> _shards[0].GetVoiceRegionsAsync();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async ValueTask<RestVoiceRegion> GetVoiceRegionAsync(string id, RequestOptions options = null)
|
||||
{
|
||||
return await _shards[0].GetVoiceRegionAsync(id, options).ConfigureAwait(false);
|
||||
}
|
||||
public override ValueTask<RestVoiceRegion> GetVoiceRegionAsync(string id, RequestOptions options = null)
|
||||
=> _shards[0].GetVoiceRegionAsync(id, options);
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <exception cref="ArgumentNullException"><paramref name="guilds"/> is <see langword="null"/></exception>
|
||||
@@ -396,14 +393,14 @@ namespace Discord.WebSocket
|
||||
await _shards[i].SetStatusAsync(status).ConfigureAwait(false);
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public override async Task SetGameAsync(string name, string streamUrl = null, ActivityType type = ActivityType.Playing)
|
||||
public override Task SetGameAsync(string name, string streamUrl = null, ActivityType type = ActivityType.Playing)
|
||||
{
|
||||
IActivity activity = null;
|
||||
if (!string.IsNullOrEmpty(streamUrl))
|
||||
activity = new StreamingGame(name, streamUrl);
|
||||
else if (!string.IsNullOrEmpty(name))
|
||||
activity = new Game(name, type);
|
||||
await SetActivityAsync(activity).ConfigureAwait(false);
|
||||
return SetActivityAsync(activity);
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public override async Task SetActivityAsync(IActivity activity)
|
||||
|
||||
@@ -317,7 +317,7 @@ namespace Discord.API
|
||||
#endif
|
||||
}
|
||||
|
||||
public async Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, int totalShards = 1, GatewayIntents gatewayIntents = GatewayIntents.AllUnprivileged, (UserStatus, bool, long?, GameModel)? presence = null, RequestOptions options = null)
|
||||
public Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, int totalShards = 1, GatewayIntents gatewayIntents = GatewayIntents.AllUnprivileged, (UserStatus, bool, long?, GameModel)? presence = null, RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
var props = new Dictionary<string, string>
|
||||
@@ -350,9 +350,10 @@ namespace Discord.API
|
||||
};
|
||||
}
|
||||
|
||||
await SendGatewayAsync(GatewayOpCode.Identify, msg, options: options).ConfigureAwait(false);
|
||||
return SendGatewayAsync(GatewayOpCode.Identify, msg, options: options);
|
||||
}
|
||||
public async Task SendResumeAsync(string sessionId, int lastSeq, RequestOptions options = null)
|
||||
|
||||
public Task SendResumeAsync(string sessionId, int lastSeq, RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
var msg = new ResumeParams()
|
||||
@@ -361,14 +362,16 @@ namespace Discord.API
|
||||
SessionId = sessionId,
|
||||
Sequence = lastSeq
|
||||
};
|
||||
await SendGatewayAsync(GatewayOpCode.Resume, msg, options: options).ConfigureAwait(false);
|
||||
return SendGatewayAsync(GatewayOpCode.Resume, msg, options: options);
|
||||
}
|
||||
public async Task SendHeartbeatAsync(int lastSeq, RequestOptions options = null)
|
||||
|
||||
public Task SendHeartbeatAsync(int lastSeq, RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
await SendGatewayAsync(GatewayOpCode.Heartbeat, lastSeq, options: options).ConfigureAwait(false);
|
||||
return SendGatewayAsync(GatewayOpCode.Heartbeat, lastSeq, options: options);
|
||||
}
|
||||
public async Task SendPresenceUpdateAsync(UserStatus status, bool isAFK, long? since, GameModel game, RequestOptions options = null)
|
||||
|
||||
public Task SendPresenceUpdateAsync(UserStatus status, bool isAFK, long? since, GameModel game, RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
var args = new PresenceUpdateParams
|
||||
@@ -379,14 +382,16 @@ namespace Discord.API
|
||||
Activities = new object[] { game }
|
||||
};
|
||||
options.BucketId = GatewayBucket.Get(GatewayBucketType.PresenceUpdate).Id;
|
||||
await SendGatewayAsync(GatewayOpCode.PresenceUpdate, args, options: options).ConfigureAwait(false);
|
||||
return SendGatewayAsync(GatewayOpCode.PresenceUpdate, args, options: options);
|
||||
}
|
||||
public async Task SendRequestMembersAsync(IEnumerable<ulong> guildIds, RequestOptions options = null)
|
||||
|
||||
public Task SendRequestMembersAsync(IEnumerable<ulong> guildIds, RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
await SendGatewayAsync(GatewayOpCode.RequestGuildMembers, new RequestMembersParams { GuildIds = guildIds, Query = "", Limit = 0 }, options: options).ConfigureAwait(false);
|
||||
return SendGatewayAsync(GatewayOpCode.RequestGuildMembers, new RequestMembersParams { GuildIds = guildIds, Query = "", Limit = 0 }, options: options);
|
||||
}
|
||||
public async Task SendVoiceStateUpdateAsync(ulong guildId, ulong? channelId, bool selfDeaf, bool selfMute, RequestOptions options = null)
|
||||
|
||||
public Task SendVoiceStateUpdateAsync(ulong guildId, ulong? channelId, bool selfDeaf, bool selfMute, RequestOptions options = null)
|
||||
{
|
||||
var payload = new VoiceStateUpdateParams
|
||||
{
|
||||
@@ -396,17 +401,19 @@ namespace Discord.API
|
||||
SelfMute = selfMute
|
||||
};
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
await SendGatewayAsync(GatewayOpCode.VoiceStateUpdate, payload, options: options).ConfigureAwait(false);
|
||||
return SendGatewayAsync(GatewayOpCode.VoiceStateUpdate, payload, options: options);
|
||||
}
|
||||
public async Task SendVoiceStateUpdateAsync(VoiceStateUpdateParams payload, RequestOptions options = null)
|
||||
|
||||
public Task SendVoiceStateUpdateAsync(VoiceStateUpdateParams payload, RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
await SendGatewayAsync(GatewayOpCode.VoiceStateUpdate, payload, options: options).ConfigureAwait(false);
|
||||
return SendGatewayAsync(GatewayOpCode.VoiceStateUpdate, payload, options: options);
|
||||
}
|
||||
public async Task SendGuildSyncAsync(IEnumerable<ulong> guildIds, RequestOptions options = null)
|
||||
|
||||
public Task SendGuildSyncAsync(IEnumerable<ulong> guildIds, RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
await SendGatewayAsync(GatewayOpCode.GuildSync, guildIds, options: options).ConfigureAwait(false);
|
||||
return SendGatewayAsync(GatewayOpCode.GuildSync, guildIds, options: options);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -284,11 +284,12 @@ namespace Discord.WebSocket
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task StartAsync()
|
||||
=> await _connection.StartAsync().ConfigureAwait(false);
|
||||
public override Task StartAsync()
|
||||
=> _connection.StartAsync();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task StopAsync()
|
||||
=> await _connection.StopAsync().ConfigureAwait(false);
|
||||
public override Task StopAsync()
|
||||
=> _connection.StopAsync();
|
||||
|
||||
private async Task OnConnectingAsync()
|
||||
{
|
||||
@@ -642,16 +643,18 @@ namespace Discord.WebSocket
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task DownloadUsersAsync(IEnumerable<IGuild> guilds)
|
||||
public override Task DownloadUsersAsync(IEnumerable<IGuild> guilds)
|
||||
{
|
||||
if (ConnectionState == ConnectionState.Connected)
|
||||
{
|
||||
EnsureGatewayIntent(GatewayIntents.GuildMembers);
|
||||
|
||||
//Race condition leads to guilds being requested twice, probably okay
|
||||
await ProcessUserDownloadsAsync(guilds.Select(x => GetGuild(x.Id)).Where(x => x != null)).ConfigureAwait(false);
|
||||
return ProcessUserDownloadsAsync(guilds.Select(x => GetGuild(x.Id)).Where(x => x != null));
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task ProcessUserDownloadsAsync(IEnumerable<SocketGuild> guilds)
|
||||
{
|
||||
var cachedGuilds = guilds.ToImmutableArray();
|
||||
@@ -689,15 +692,16 @@ namespace Discord.WebSocket
|
||||
/// await client.SetStatusAsync(UserStatus.DoNotDisturb);
|
||||
/// </code>
|
||||
/// </example>
|
||||
public override async Task SetStatusAsync(UserStatus status)
|
||||
public override Task SetStatusAsync(UserStatus status)
|
||||
{
|
||||
Status = status;
|
||||
if (status == UserStatus.AFK)
|
||||
_statusSince = DateTimeOffset.UtcNow;
|
||||
else
|
||||
_statusSince = null;
|
||||
await SendStatusAsync().ConfigureAwait(false);
|
||||
return SendStatusAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <example>
|
||||
/// <para>
|
||||
@@ -713,7 +717,7 @@ namespace Discord.WebSocket
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// </example>
|
||||
public override async Task SetGameAsync(string name, string streamUrl = null, ActivityType type = ActivityType.Playing)
|
||||
public override Task SetGameAsync(string name, string streamUrl = null, ActivityType type = ActivityType.Playing)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(streamUrl))
|
||||
Activity = new StreamingGame(name, streamUrl);
|
||||
@@ -721,27 +725,27 @@ namespace Discord.WebSocket
|
||||
Activity = new Game(name, type);
|
||||
else
|
||||
Activity = null;
|
||||
await SendStatusAsync().ConfigureAwait(false);
|
||||
return SendStatusAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task SetActivityAsync(IActivity activity)
|
||||
public override Task SetActivityAsync(IActivity activity)
|
||||
{
|
||||
Activity = activity;
|
||||
await SendStatusAsync().ConfigureAwait(false);
|
||||
return SendStatusAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task SetCustomStatusAsync(string status)
|
||||
public override Task SetCustomStatusAsync(string status)
|
||||
{
|
||||
var statusGame = new CustomStatusGame(status);
|
||||
await SetActivityAsync(statusGame);
|
||||
return SetActivityAsync(statusGame);
|
||||
}
|
||||
|
||||
private async Task SendStatusAsync()
|
||||
private Task SendStatusAsync()
|
||||
{
|
||||
if (CurrentUser == null)
|
||||
return;
|
||||
return Task.CompletedTask;
|
||||
var activities = _activity.IsSpecified
|
||||
? ImmutableList.Create(_activity.Value)
|
||||
: null;
|
||||
@@ -749,11 +753,11 @@ namespace Discord.WebSocket
|
||||
|
||||
var presence = BuildCurrentStatus() ?? (UserStatus.Online, false, null, null);
|
||||
|
||||
await ApiClient.SendPresenceUpdateAsync(
|
||||
return ApiClient.SendPresenceUpdateAsync(
|
||||
status: presence.Item1,
|
||||
isAFK: presence.Item2,
|
||||
since: presence.Item3,
|
||||
game: presence.Item4).ConfigureAwait(false);
|
||||
game: presence.Item4);
|
||||
}
|
||||
|
||||
private (UserStatus, bool, long?, GameModel)? BuildCurrentStatus()
|
||||
@@ -3268,11 +3272,14 @@ namespace Discord.WebSocket
|
||||
await logger.ErrorAsync("GuildDownloader Errored", ex).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
private async Task SyncGuildsAsync()
|
||||
|
||||
private Task SyncGuildsAsync()
|
||||
{
|
||||
var guildIds = Guilds.Where(x => !x.IsSynced).Select(x => x.Id).ToImmutableArray();
|
||||
if (guildIds.Length > 0)
|
||||
await ApiClient.SendGuildSyncAsync(guildIds).ConfigureAwait(false);
|
||||
return ApiClient.SendGuildSyncAsync(guildIds);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
internal SocketGuild AddGuild(ExtendedGuild model, ClientState state)
|
||||
@@ -3334,83 +3341,106 @@ namespace Discord.WebSocket
|
||||
internal bool HasGatewayIntent(GatewayIntents intents)
|
||||
=> _gatewayIntents.HasFlag(intents);
|
||||
|
||||
private async Task GuildAvailableAsync(SocketGuild guild)
|
||||
private Task GuildAvailableAsync(SocketGuild guild)
|
||||
{
|
||||
if (!guild.IsConnected)
|
||||
{
|
||||
guild.IsConnected = true;
|
||||
await TimedInvokeAsync(_guildAvailableEvent, nameof(GuildAvailable), guild).ConfigureAwait(false);
|
||||
return TimedInvokeAsync(_guildAvailableEvent, nameof(GuildAvailable), guild);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
private async Task GuildUnavailableAsync(SocketGuild guild)
|
||||
|
||||
private Task GuildUnavailableAsync(SocketGuild guild)
|
||||
{
|
||||
if (guild.IsConnected)
|
||||
{
|
||||
guild.IsConnected = false;
|
||||
await TimedInvokeAsync(_guildUnavailableEvent, nameof(GuildUnavailable), guild).ConfigureAwait(false);
|
||||
return TimedInvokeAsync(_guildUnavailableEvent, nameof(GuildUnavailable), guild);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task TimedInvokeAsync(AsyncEvent<Func<Task>> eventHandler, string name)
|
||||
private Task TimedInvokeAsync(AsyncEvent<Func<Task>> eventHandler, string name)
|
||||
{
|
||||
if (eventHandler.HasSubscribers)
|
||||
{
|
||||
if (HandlerTimeout.HasValue)
|
||||
await TimeoutWrap(name, eventHandler.InvokeAsync).ConfigureAwait(false);
|
||||
return TimeoutWrap(name, eventHandler.InvokeAsync);
|
||||
else
|
||||
await eventHandler.InvokeAsync().ConfigureAwait(false);
|
||||
return eventHandler.InvokeAsync();
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
private async Task TimedInvokeAsync<T>(AsyncEvent<Func<T, Task>> eventHandler, string name, T arg)
|
||||
|
||||
private Task TimedInvokeAsync<T>(AsyncEvent<Func<T, Task>> eventHandler, string name, T arg)
|
||||
{
|
||||
if (eventHandler.HasSubscribers)
|
||||
{
|
||||
if (HandlerTimeout.HasValue)
|
||||
await TimeoutWrap(name, () => eventHandler.InvokeAsync(arg)).ConfigureAwait(false);
|
||||
return TimeoutWrap(name, () => eventHandler.InvokeAsync(arg));
|
||||
else
|
||||
await eventHandler.InvokeAsync(arg).ConfigureAwait(false);
|
||||
return eventHandler.InvokeAsync(arg);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
private async Task TimedInvokeAsync<T1, T2>(AsyncEvent<Func<T1, T2, Task>> eventHandler, string name, T1 arg1, T2 arg2)
|
||||
|
||||
private Task TimedInvokeAsync<T1, T2>(AsyncEvent<Func<T1, T2, Task>> eventHandler, string name, T1 arg1, T2 arg2)
|
||||
{
|
||||
if (eventHandler.HasSubscribers)
|
||||
{
|
||||
if (HandlerTimeout.HasValue)
|
||||
await TimeoutWrap(name, () => eventHandler.InvokeAsync(arg1, arg2)).ConfigureAwait(false);
|
||||
return TimeoutWrap(name, () => eventHandler.InvokeAsync(arg1, arg2));
|
||||
else
|
||||
await eventHandler.InvokeAsync(arg1, arg2).ConfigureAwait(false);
|
||||
return eventHandler.InvokeAsync(arg1, arg2);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
private async Task TimedInvokeAsync<T1, T2, T3>(AsyncEvent<Func<T1, T2, T3, Task>> eventHandler, string name, T1 arg1, T2 arg2, T3 arg3)
|
||||
|
||||
private Task TimedInvokeAsync<T1, T2, T3>(AsyncEvent<Func<T1, T2, T3, Task>> eventHandler, string name, T1 arg1, T2 arg2, T3 arg3)
|
||||
{
|
||||
if (eventHandler.HasSubscribers)
|
||||
{
|
||||
if (HandlerTimeout.HasValue)
|
||||
await TimeoutWrap(name, () => eventHandler.InvokeAsync(arg1, arg2, arg3)).ConfigureAwait(false);
|
||||
return TimeoutWrap(name, () => eventHandler.InvokeAsync(arg1, arg2, arg3));
|
||||
else
|
||||
await eventHandler.InvokeAsync(arg1, arg2, arg3).ConfigureAwait(false);
|
||||
return eventHandler.InvokeAsync(arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
private async Task TimedInvokeAsync<T1, T2, T3, T4>(AsyncEvent<Func<T1, T2, T3, T4, Task>> eventHandler, string name, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
|
||||
|
||||
private Task TimedInvokeAsync<T1, T2, T3, T4>(AsyncEvent<Func<T1, T2, T3, T4, Task>> eventHandler, string name, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
|
||||
{
|
||||
if (eventHandler.HasSubscribers)
|
||||
{
|
||||
if (HandlerTimeout.HasValue)
|
||||
await TimeoutWrap(name, () => eventHandler.InvokeAsync(arg1, arg2, arg3, arg4)).ConfigureAwait(false);
|
||||
return TimeoutWrap(name, () => eventHandler.InvokeAsync(arg1, arg2, arg3, arg4));
|
||||
else
|
||||
await eventHandler.InvokeAsync(arg1, arg2, arg3, arg4).ConfigureAwait(false);
|
||||
return eventHandler.InvokeAsync(arg1, arg2, arg3, arg4);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
private async Task TimedInvokeAsync<T1, T2, T3, T4, T5>(AsyncEvent<Func<T1, T2, T3, T4, T5, Task>> eventHandler, string name, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
|
||||
|
||||
private Task TimedInvokeAsync<T1, T2, T3, T4, T5>(AsyncEvent<Func<T1, T2, T3, T4, T5, Task>> eventHandler, string name, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
|
||||
{
|
||||
if (eventHandler.HasSubscribers)
|
||||
{
|
||||
if (HandlerTimeout.HasValue)
|
||||
await TimeoutWrap(name, () => eventHandler.InvokeAsync(arg1, arg2, arg3, arg4, arg5)).ConfigureAwait(false);
|
||||
return TimeoutWrap(name, () => eventHandler.InvokeAsync(arg1, arg2, arg3, arg4, arg5));
|
||||
else
|
||||
await eventHandler.InvokeAsync(arg1, arg2, arg3, arg4, arg5).ConfigureAwait(false);
|
||||
return eventHandler.InvokeAsync(arg1, arg2, arg3, arg4, arg5);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task TimeoutWrap(string name, Func<Task> action)
|
||||
{
|
||||
try
|
||||
@@ -3429,61 +3459,68 @@ namespace Discord.WebSocket
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UnknownGlobalUserAsync(string evnt, ulong userId)
|
||||
private Task UnknownGlobalUserAsync(string evnt, ulong userId)
|
||||
{
|
||||
string details = $"{evnt} User={userId}";
|
||||
await _gatewayLogger.WarningAsync($"Unknown User ({details}).").ConfigureAwait(false);
|
||||
return _gatewayLogger.WarningAsync($"Unknown User ({details}).");
|
||||
}
|
||||
private async Task UnknownChannelUserAsync(string evnt, ulong userId, ulong channelId)
|
||||
|
||||
private Task UnknownChannelUserAsync(string evnt, ulong userId, ulong channelId)
|
||||
{
|
||||
string details = $"{evnt} User={userId} Channel={channelId}";
|
||||
await _gatewayLogger.WarningAsync($"Unknown User ({details}).").ConfigureAwait(false);
|
||||
return _gatewayLogger.WarningAsync($"Unknown User ({details}).");
|
||||
}
|
||||
private async Task UnknownGuildUserAsync(string evnt, ulong userId, ulong guildId)
|
||||
|
||||
private Task UnknownGuildUserAsync(string evnt, ulong userId, ulong guildId)
|
||||
{
|
||||
string details = $"{evnt} User={userId} Guild={guildId}";
|
||||
await _gatewayLogger.WarningAsync($"Unknown User ({details}).").ConfigureAwait(false);
|
||||
return _gatewayLogger.WarningAsync($"Unknown User ({details}).");
|
||||
}
|
||||
private async Task IncompleteGuildUserAsync(string evnt, ulong userId, ulong guildId)
|
||||
|
||||
private Task IncompleteGuildUserAsync(string evnt, ulong userId, ulong guildId)
|
||||
{
|
||||
string details = $"{evnt} User={userId} Guild={guildId}";
|
||||
await _gatewayLogger.DebugAsync($"User has not been downloaded ({details}).").ConfigureAwait(false);
|
||||
return _gatewayLogger.DebugAsync($"User has not been downloaded ({details}).");
|
||||
}
|
||||
private async Task UnknownChannelAsync(string evnt, ulong channelId)
|
||||
|
||||
private Task UnknownChannelAsync(string evnt, ulong channelId)
|
||||
{
|
||||
string details = $"{evnt} Channel={channelId}";
|
||||
await _gatewayLogger.WarningAsync($"Unknown Channel ({details}).").ConfigureAwait(false);
|
||||
return _gatewayLogger.WarningAsync($"Unknown Channel ({details}).");
|
||||
}
|
||||
private async Task UnknownChannelAsync(string evnt, ulong channelId, ulong guildId)
|
||||
|
||||
private Task UnknownChannelAsync(string evnt, ulong channelId, ulong guildId)
|
||||
{
|
||||
if (guildId == 0)
|
||||
{
|
||||
await UnknownChannelAsync(evnt, channelId).ConfigureAwait(false);
|
||||
return;
|
||||
return UnknownChannelAsync(evnt, channelId);
|
||||
}
|
||||
string details = $"{evnt} Channel={channelId} Guild={guildId}";
|
||||
await _gatewayLogger.WarningAsync($"Unknown Channel ({details}).").ConfigureAwait(false);
|
||||
}
|
||||
private async Task UnknownRoleAsync(string evnt, ulong roleId, ulong guildId)
|
||||
{
|
||||
string details = $"{evnt} Role={roleId} Guild={guildId}";
|
||||
await _gatewayLogger.WarningAsync($"Unknown Role ({details}).").ConfigureAwait(false);
|
||||
}
|
||||
private async Task UnknownGuildAsync(string evnt, ulong guildId)
|
||||
{
|
||||
string details = $"{evnt} Guild={guildId}";
|
||||
await _gatewayLogger.WarningAsync($"Unknown Guild ({details}).").ConfigureAwait(false);
|
||||
return _gatewayLogger.WarningAsync($"Unknown Channel ({details}).");
|
||||
}
|
||||
|
||||
private async Task UnknownGuildEventAsync(string evnt, ulong eventId, ulong guildId)
|
||||
private Task UnknownRoleAsync(string evnt, ulong roleId, ulong guildId)
|
||||
{
|
||||
string details = $"{evnt} Event={eventId} Guild={guildId}";
|
||||
await _gatewayLogger.WarningAsync($"Unknown Guild Event ({details}).").ConfigureAwait(false);
|
||||
string details = $"{evnt} Role={roleId} Guild={guildId}";
|
||||
return _gatewayLogger.WarningAsync($"Unknown Role ({details}).");
|
||||
}
|
||||
private async Task UnsyncedGuildAsync(string evnt, ulong guildId)
|
||||
|
||||
private Task UnknownGuildAsync(string evnt, ulong guildId)
|
||||
{
|
||||
string details = $"{evnt} Guild={guildId}";
|
||||
await _gatewayLogger.DebugAsync($"Unsynced Guild ({details}).").ConfigureAwait(false);
|
||||
return _gatewayLogger.WarningAsync($"Unknown Guild ({details}).");
|
||||
}
|
||||
|
||||
private Task UnknownGuildEventAsync(string evnt, ulong eventId, ulong guildId)
|
||||
{
|
||||
string details = $"{evnt} Event={eventId} Guild={guildId}";
|
||||
return _gatewayLogger.WarningAsync($"Unknown Guild Event ({details}).");
|
||||
}
|
||||
|
||||
private Task UnsyncedGuildAsync(string evnt, ulong guildId)
|
||||
{
|
||||
string details = $"{evnt} Guild={guildId}";
|
||||
return _gatewayLogger.DebugAsync($"Unsynced Guild ({details}).");
|
||||
}
|
||||
|
||||
internal int GetAudioId() => _nextAudioId++;
|
||||
@@ -3558,11 +3595,12 @@ namespace Discord.WebSocket
|
||||
=> await BulkOverwriteGlobalApplicationCommandsAsync(properties, options);
|
||||
|
||||
/// <inheritdoc />
|
||||
async Task IDiscordClient.StartAsync()
|
||||
=> await StartAsync().ConfigureAwait(false);
|
||||
Task IDiscordClient.StartAsync()
|
||||
=> StartAsync();
|
||||
|
||||
/// <inheritdoc />
|
||||
async Task IDiscordClient.StopAsync()
|
||||
=> await StopAsync().ConfigureAwait(false);
|
||||
Task IDiscordClient.StopAsync()
|
||||
=> StopAsync();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace Discord.Audio
|
||||
GuildId = guildId;
|
||||
_connectionLock = new SemaphoreSlim(1, 1);
|
||||
_udp = udpSocketProvider();
|
||||
_udp.ReceivedDatagram += async (data, index, count) =>
|
||||
_udp.ReceivedDatagram += (data, index, count) =>
|
||||
{
|
||||
if (index != 0 || count != data.Length)
|
||||
{
|
||||
@@ -63,7 +63,7 @@ namespace Discord.Audio
|
||||
Buffer.BlockCopy(data, index, newData, 0, count);
|
||||
data = newData;
|
||||
}
|
||||
await _receivedPacketEvent.InvokeAsync(data).ConfigureAwait(false);
|
||||
return _receivedPacketEvent.InvokeAsync(data);
|
||||
};
|
||||
|
||||
WebSocketClient = webSocketProvider();
|
||||
@@ -83,10 +83,10 @@ namespace Discord.Audio
|
||||
}
|
||||
}
|
||||
};
|
||||
WebSocketClient.TextMessage += async text =>
|
||||
WebSocketClient.TextMessage += text =>
|
||||
{
|
||||
var msg = JsonConvert.DeserializeObject<SocketFrame>(text);
|
||||
await _receivedEvent.InvokeAsync((VoiceOpCode)msg.Operation, msg.Payload).ConfigureAwait(false);
|
||||
return _receivedEvent.InvokeAsync((VoiceOpCode)msg.Operation, msg.Payload);
|
||||
};
|
||||
WebSocketClient.Closed += async ex =>
|
||||
{
|
||||
@@ -129,23 +129,23 @@ namespace Discord.Audio
|
||||
#endregion
|
||||
|
||||
#region WebSocket
|
||||
public async Task SendHeartbeatAsync(RequestOptions options = null)
|
||||
public Task SendHeartbeatAsync(RequestOptions options = null)
|
||||
=> SendAsync(VoiceOpCode.Heartbeat, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), options: options);
|
||||
|
||||
public Task SendIdentityAsync(ulong userId, string sessionId, string token)
|
||||
{
|
||||
await SendAsync(VoiceOpCode.Heartbeat, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), options: options).ConfigureAwait(false);
|
||||
}
|
||||
public async Task SendIdentityAsync(ulong userId, string sessionId, string token)
|
||||
{
|
||||
await SendAsync(VoiceOpCode.Identify, new IdentifyParams
|
||||
return SendAsync(VoiceOpCode.Identify, new IdentifyParams
|
||||
{
|
||||
GuildId = GuildId,
|
||||
UserId = userId,
|
||||
SessionId = sessionId,
|
||||
Token = token
|
||||
}).ConfigureAwait(false);
|
||||
});
|
||||
}
|
||||
public async Task SendSelectProtocol(string externalIp, int externalPort)
|
||||
|
||||
public Task SendSelectProtocol(string externalIp, int externalPort)
|
||||
{
|
||||
await SendAsync(VoiceOpCode.SelectProtocol, new SelectProtocolParams
|
||||
return SendAsync(VoiceOpCode.SelectProtocol, new SelectProtocolParams
|
||||
{
|
||||
Protocol = "udp",
|
||||
Data = new UdpProtocolInfo
|
||||
@@ -154,15 +154,16 @@ namespace Discord.Audio
|
||||
Port = externalPort,
|
||||
Mode = Mode
|
||||
}
|
||||
}).ConfigureAwait(false);
|
||||
});
|
||||
}
|
||||
public async Task SendSetSpeaking(bool value)
|
||||
|
||||
public Task SendSetSpeaking(bool value)
|
||||
{
|
||||
await SendAsync(VoiceOpCode.Speaking, new SpeakingParams
|
||||
return SendAsync(VoiceOpCode.Speaking, new SpeakingParams
|
||||
{
|
||||
IsSpeaking = value,
|
||||
Delay = 0
|
||||
}).ConfigureAwait(false);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task ConnectAsync(string url)
|
||||
@@ -174,6 +175,7 @@ namespace Discord.Audio
|
||||
}
|
||||
finally { _connectionLock.Release(); }
|
||||
}
|
||||
|
||||
private async Task ConnectInternalAsync(string url)
|
||||
{
|
||||
ConnectionState = ConnectionState.Connecting;
|
||||
|
||||
@@ -259,13 +259,14 @@ namespace Discord.WebSocket
|
||||
|
||||
#region IMessageChannel
|
||||
/// <inheritdoc />
|
||||
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return await GetMessageAsync(id, options).ConfigureAwait(false);
|
||||
return GetMessageAsync(id, options);
|
||||
else
|
||||
return GetCachedMessage(id);
|
||||
return Task.FromResult((IMessage)GetCachedMessage(id));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options)
|
||||
=> mode == CacheMode.CacheOnly ? null : GetMessagesAsync(limit, options);
|
||||
|
||||
@@ -330,12 +330,12 @@ namespace Discord.WebSocket
|
||||
|
||||
#region IMessageChannel
|
||||
/// <inheritdoc />
|
||||
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return await GetMessageAsync(id, options).ConfigureAwait(false);
|
||||
return GetMessageAsync(id, options);
|
||||
else
|
||||
return GetCachedMessage(id);
|
||||
return Task.FromResult((IMessage)GetCachedMessage(id));
|
||||
}
|
||||
/// <inheritdoc />
|
||||
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options)
|
||||
|
||||
@@ -131,10 +131,8 @@ namespace Discord.WebSocket
|
||||
/// <returns>
|
||||
/// A task representing the asynchronous permission operation for adding the specified permissions to the channel.
|
||||
/// </returns>
|
||||
public virtual async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null)
|
||||
{
|
||||
await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, permissions, options).ConfigureAwait(false);
|
||||
}
|
||||
public virtual Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null)
|
||||
=> ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, permissions, options);
|
||||
|
||||
/// <summary>
|
||||
/// Adds or updates the permission overwrite for the given role.
|
||||
@@ -145,10 +143,9 @@ namespace Discord.WebSocket
|
||||
/// <returns>
|
||||
/// A task representing the asynchronous permission operation for adding the specified permissions to the channel.
|
||||
/// </returns>
|
||||
public virtual async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null)
|
||||
{
|
||||
await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, permissions, options).ConfigureAwait(false);
|
||||
}
|
||||
public virtual Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null)
|
||||
=> ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, permissions, options);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the permission overwrite for the given user, if one exists.
|
||||
/// </summary>
|
||||
@@ -157,10 +154,9 @@ namespace Discord.WebSocket
|
||||
/// <returns>
|
||||
/// A task representing the asynchronous operation for removing the specified permissions from the channel.
|
||||
/// </returns>
|
||||
public virtual async Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null)
|
||||
{
|
||||
await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user, options).ConfigureAwait(false);
|
||||
}
|
||||
public virtual Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null)
|
||||
=> ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user, options);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the permission overwrite for the given role, if one exists.
|
||||
/// </summary>
|
||||
@@ -169,10 +165,8 @@ namespace Discord.WebSocket
|
||||
/// <returns>
|
||||
/// A task representing the asynchronous operation for removing the specified permissions from the channel.
|
||||
/// </returns>
|
||||
public virtual async Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null)
|
||||
{
|
||||
await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role, options).ConfigureAwait(false);
|
||||
}
|
||||
public virtual Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null)
|
||||
=> ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role, options);
|
||||
|
||||
public new virtual SocketGuildUser GetUser(ulong id) => null;
|
||||
|
||||
@@ -207,17 +201,20 @@ namespace Discord.WebSocket
|
||||
OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IUser user)
|
||||
=> GetPermissionOverwrite(user);
|
||||
/// <inheritdoc />
|
||||
async Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options)
|
||||
=> await AddPermissionOverwriteAsync(role, permissions, options).ConfigureAwait(false);
|
||||
Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options)
|
||||
=> AddPermissionOverwriteAsync(role, permissions, options);
|
||||
|
||||
/// <inheritdoc />
|
||||
async Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options)
|
||||
=> await AddPermissionOverwriteAsync(user, permissions, options).ConfigureAwait(false);
|
||||
Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options)
|
||||
=> AddPermissionOverwriteAsync(user, permissions, options);
|
||||
|
||||
/// <inheritdoc />
|
||||
async Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role, RequestOptions options)
|
||||
=> await RemovePermissionOverwriteAsync(role, options).ConfigureAwait(false);
|
||||
Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role, RequestOptions options)
|
||||
=> RemovePermissionOverwriteAsync(role, options);
|
||||
|
||||
/// <inheritdoc />
|
||||
async Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user, RequestOptions options)
|
||||
=> await RemovePermissionOverwriteAsync(user, options).ConfigureAwait(false);
|
||||
Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user, RequestOptions options)
|
||||
=> RemovePermissionOverwriteAsync(user, options);
|
||||
|
||||
/// <inheritdoc />
|
||||
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
|
||||
|
||||
@@ -413,12 +413,12 @@ namespace Discord.WebSocket
|
||||
|
||||
#region IMessageChannel
|
||||
/// <inheritdoc />
|
||||
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return await GetMessageAsync(id, options).ConfigureAwait(false);
|
||||
return GetMessageAsync(id, options);
|
||||
else
|
||||
return GetCachedMessage(id);
|
||||
return Task.FromResult((IMessage)GetCachedMessage(id));
|
||||
}
|
||||
/// <inheritdoc />
|
||||
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options)
|
||||
|
||||
@@ -89,20 +89,17 @@ namespace Discord.WebSocket
|
||||
=> ChannelHelper.ModifyAsync(this, Discord, func, options);
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IAudioClient> ConnectAsync(bool selfDeaf = false, bool selfMute = false, bool external = false)
|
||||
{
|
||||
return await Guild.ConnectAudioAsync(Id, selfDeaf, selfMute, external).ConfigureAwait(false);
|
||||
}
|
||||
public Task<IAudioClient> ConnectAsync(bool selfDeaf = false, bool selfMute = false, bool external = false)
|
||||
=> Guild.ConnectAudioAsync(Id, selfDeaf, selfMute, external);
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task DisconnectAsync()
|
||||
=> await Guild.DisconnectAudioAsync();
|
||||
public Task DisconnectAsync()
|
||||
=> Guild.DisconnectAudioAsync();
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task ModifyAsync(Action<AudioChannelProperties> func, RequestOptions options = null)
|
||||
{
|
||||
await Guild.ModifyAudioAsync(Id, func, options).ConfigureAwait(false);
|
||||
}
|
||||
public Task ModifyAsync(Action<AudioChannelProperties> func, RequestOptions options = null)
|
||||
=> Guild.ModifyAudioAsync(Id, func, options);
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SocketGuildUser GetUser(ulong id)
|
||||
|
||||
@@ -1307,10 +1307,9 @@ namespace Discord.WebSocket
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task DownloadUsersAsync()
|
||||
{
|
||||
await Discord.DownloadUsersAsync(new[] { this }).ConfigureAwait(false);
|
||||
}
|
||||
public Task DownloadUsersAsync()
|
||||
=> Discord.DownloadUsersAsync(new[] { this });
|
||||
|
||||
internal void CompleteDownloadUsers()
|
||||
{
|
||||
_downloaderPromise.TrySetResultAsync(true);
|
||||
@@ -1545,7 +1544,8 @@ namespace Discord.WebSocket
|
||||
/// </summary>
|
||||
/// <param name="user">The user to disconnect.</param>
|
||||
/// <returns>A task that represents the asynchronous operation for disconnecting a user.</returns>
|
||||
async Task IGuild.DisconnectAsync(IGuildUser user) => await user.ModifyAsync(x => x.Channel = null);
|
||||
Task IGuild.DisconnectAsync(IGuildUser user)
|
||||
=> user.ModifyAsync(x => x.Channel = null);
|
||||
#endregion
|
||||
|
||||
#region Stickers
|
||||
@@ -1850,7 +1850,7 @@ namespace Discord.WebSocket
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ModifyAudioInternalAsync(ulong channelId, Action<AudioChannelProperties> func, RequestOptions options)
|
||||
private Task ModifyAudioInternalAsync(ulong channelId, Action<AudioChannelProperties> func, RequestOptions options)
|
||||
{
|
||||
if (_voiceStateUpdateParams == null || _voiceStateUpdateParams.ChannelId != channelId)
|
||||
throw new InvalidOperationException("Cannot modify properties of not connected audio channel");
|
||||
@@ -1863,7 +1863,7 @@ namespace Discord.WebSocket
|
||||
if (props.SelfMute.IsSpecified)
|
||||
_voiceStateUpdateParams.SelfMute = props.SelfMute.Value;
|
||||
|
||||
await Discord.ApiClient.SendVoiceStateUpdateAsync(_voiceStateUpdateParams, options).ConfigureAwait(false);
|
||||
return Discord.ApiClient.SendVoiceStateUpdateAsync(_voiceStateUpdateParams, options);
|
||||
}
|
||||
|
||||
internal async Task FinishConnectAudio(string url, string token)
|
||||
|
||||
@@ -305,7 +305,7 @@ namespace Discord.WebSocket
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async Task<RestFollowupMessage> FollowupAsync(
|
||||
public override Task<RestFollowupMessage> FollowupAsync(
|
||||
string text = null,
|
||||
Embed[] embeds = null,
|
||||
bool isTTS = false,
|
||||
@@ -338,11 +338,11 @@ namespace Discord.WebSocket
|
||||
if (ephemeral)
|
||||
args.Flags = MessageFlags.Ephemeral;
|
||||
|
||||
return await InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options);
|
||||
return InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async Task<RestFollowupMessage> FollowupWithFilesAsync(
|
||||
public override Task<RestFollowupMessage> FollowupWithFilesAsync(
|
||||
IEnumerable<FileAttachment> attachments,
|
||||
string text = null,
|
||||
Embed[] embeds = null,
|
||||
@@ -391,7 +391,7 @@ namespace Discord.WebSocket
|
||||
flags |= MessageFlags.Ephemeral;
|
||||
|
||||
var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray()) { Flags = flags, Content = text, IsTTS = isTTS, Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional<API.Embed[]>.Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional<API.AllowedMentions>.Unspecified, MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified };
|
||||
return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options).ConfigureAwait(false);
|
||||
return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -302,7 +302,7 @@ namespace Discord.WebSocket
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async Task<RestFollowupMessage> FollowupAsync(
|
||||
public override Task<RestFollowupMessage> FollowupAsync(
|
||||
string text = null,
|
||||
Embed[] embeds = null,
|
||||
bool isTTS = false,
|
||||
@@ -335,11 +335,11 @@ namespace Discord.WebSocket
|
||||
if (ephemeral)
|
||||
args.Flags = MessageFlags.Ephemeral;
|
||||
|
||||
return await InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options);
|
||||
return InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async Task<RestFollowupMessage> FollowupWithFilesAsync(
|
||||
public override Task<RestFollowupMessage> FollowupWithFilesAsync(
|
||||
IEnumerable<FileAttachment> attachments,
|
||||
string text = null,
|
||||
Embed[] embeds = null,
|
||||
@@ -388,7 +388,7 @@ namespace Discord.WebSocket
|
||||
flags |= MessageFlags.Ephemeral;
|
||||
|
||||
var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray()) { Flags = flags, Content = text, IsTTS = isTTS, Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional<API.Embed[]>.Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional<API.AllowedMentions>.Unspecified, MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified };
|
||||
return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options).ConfigureAwait(false);
|
||||
return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -234,7 +234,7 @@ namespace Discord.WebSocket
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async Task<RestFollowupMessage> FollowupAsync(
|
||||
public override Task<RestFollowupMessage> FollowupAsync(
|
||||
string text = null,
|
||||
Embed[] embeds = null,
|
||||
bool isTTS = false,
|
||||
@@ -267,11 +267,11 @@ namespace Discord.WebSocket
|
||||
if (ephemeral)
|
||||
args.Flags = MessageFlags.Ephemeral;
|
||||
|
||||
return await InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options);
|
||||
return InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async Task<RestFollowupMessage> FollowupWithFilesAsync(
|
||||
public override Task<RestFollowupMessage> FollowupWithFilesAsync(
|
||||
IEnumerable<FileAttachment> attachments,
|
||||
string text = null,
|
||||
Embed[] embeds = null,
|
||||
@@ -320,7 +320,7 @@ namespace Discord.WebSocket
|
||||
flags |= MessageFlags.Ephemeral;
|
||||
|
||||
var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray()) { Flags = flags, Content = text, IsTTS = isTTS, Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional<API.Embed[]>.Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional<API.AllowedMentions>.Unspecified, MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified };
|
||||
return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options).ConfigureAwait(false);
|
||||
return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -228,14 +228,14 @@ namespace Discord.WebSocket
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <exception cref="InvalidOperationException">This operation may only be called on a <see cref="INewsChannel"/> channel.</exception>
|
||||
public async Task CrosspostAsync(RequestOptions options = null)
|
||||
public Task CrosspostAsync(RequestOptions options = null)
|
||||
{
|
||||
if (!(Channel is INewsChannel))
|
||||
{
|
||||
throw new InvalidOperationException("Publishing (crossposting) is only valid in news channels.");
|
||||
}
|
||||
|
||||
await MessageHelper.CrosspostAsync(this, Discord, options);
|
||||
return MessageHelper.CrosspostAsync(this, Discord, options);
|
||||
}
|
||||
|
||||
private string DebuggerDisplay => $"{Author}: {Content} ({Id}{(Attachments.Count > 0 ? $", {Attachments.Count} Attachments" : "")})";
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace Discord.Net.Udp
|
||||
_cancelToken = _cancelTokenSource.Token;
|
||||
}
|
||||
|
||||
public async Task SendAsync(byte[] data, int index, int count)
|
||||
public Task SendAsync(byte[] data, int index, int count)
|
||||
{
|
||||
if (index != 0) //Should never happen?
|
||||
{
|
||||
@@ -124,7 +124,7 @@ namespace Discord.Net.Udp
|
||||
Buffer.BlockCopy(data, index, newData, 0, count);
|
||||
data = newData;
|
||||
}
|
||||
await _udp.SendAsync(data, count, _destination).ConfigureAwait(false);
|
||||
return _udp.SendAsync(data, count, _destination);
|
||||
}
|
||||
|
||||
private async Task RunAsync(CancellationToken cancelToken)
|
||||
|
||||
Reference in New Issue
Block a user