Co-Authored-By: ✨ <25006819+sabihoshi@users.noreply.github.com> Co-authored-by: ✨ <25006819+sabihoshi@users.noreply.github.com>tags/3.4.0
@@ -21,7 +21,7 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
/// <remarks> | /// <remarks> | ||||
/// <note type="important"> | /// <note type="important"> | ||||
/// The returned collection is an asynchronous enumerable object; one must call | |||||
/// The returned collection is an asynchronous enumerable object; one must call | |||||
/// <see cref="AsyncEnumerableExtensions.FlattenAsync{T}"/> to access the individual messages as a | /// <see cref="AsyncEnumerableExtensions.FlattenAsync{T}"/> to access the individual messages as a | ||||
/// collection. | /// collection. | ||||
/// </note> | /// </note> | ||||
@@ -227,7 +227,7 @@ namespace Discord.Rest | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | ||||
=> AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>(); //Overridden //Overridden in Text/Voice | |||||
=> AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>(); //Overridden in Text/Voice | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | ||||
=> Task.FromResult<IGuildUser>(null); //Overridden in Text/Voice | => Task.FromResult<IGuildUser>(null); //Overridden in Text/Voice | ||||
@@ -261,7 +261,7 @@ namespace Discord.Rest | |||||
/// The duration on which this thread archives after. | /// The duration on which this thread archives after. | ||||
/// <para> | /// <para> | ||||
/// <b>Note: </b> Options <see cref="ThreadArchiveDuration.OneWeek"/> and <see cref="ThreadArchiveDuration.ThreeDays"/> | /// <b>Note: </b> Options <see cref="ThreadArchiveDuration.OneWeek"/> and <see cref="ThreadArchiveDuration.ThreeDays"/> | ||||
/// are only available for guilds that are boosted. You can check in the <see cref="IGuild.Features"/> to see if the | |||||
/// are only available for guilds that are boosted. You can check in the <see cref="IGuild.Features"/> to see if the | |||||
/// guild has the <b>THREE_DAY_THREAD_ARCHIVE</b> and <b>SEVEN_DAY_THREAD_ARCHIVE</b>. | /// guild has the <b>THREE_DAY_THREAD_ARCHIVE</b> and <b>SEVEN_DAY_THREAD_ARCHIVE</b>. | ||||
/// </para> | /// </para> | ||||
/// </param> | /// </param> | ||||
@@ -364,10 +364,9 @@ namespace Discord.Rest | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | ||||
{ | { | ||||
if (mode == CacheMode.AllowDownload) | |||||
return GetUsersAsync(options); | |||||
else | |||||
return AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>(); | |||||
return mode == CacheMode.AllowDownload | |||||
? GetUsersAsync(options) | |||||
: AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>(); | |||||
} | } | ||||
#endregion | #endregion | ||||
@@ -209,7 +209,7 @@ namespace Discord.WebSocket | |||||
/// Sets the <paramref name="activity"/> of the logged-in user. | /// Sets the <paramref name="activity"/> of the logged-in user. | ||||
/// </summary> | /// </summary> | ||||
/// <remarks> | /// <remarks> | ||||
/// This method sets the <paramref name="activity"/> of the user. | |||||
/// This method sets the <paramref name="activity"/> of the user. | |||||
/// <note type="note"> | /// <note type="note"> | ||||
/// Discord will only accept setting of name and the type of activity. | /// Discord will only accept setting of name and the type of activity. | ||||
/// </note> | /// </note> | ||||
@@ -219,7 +219,7 @@ namespace Discord.WebSocket | |||||
/// </note> | /// </note> | ||||
/// <note type="warning"> | /// <note type="warning"> | ||||
/// Rich Presence cannot be set via this method or client. Rich Presence is strictly limited to RPC | /// Rich Presence cannot be set via this method or client. Rich Presence is strictly limited to RPC | ||||
/// clients only. | |||||
/// clients only. | |||||
/// </note> | /// </note> | ||||
/// </remarks> | /// </remarks> | ||||
/// <param name="activity">The activity to be set.</param> | /// <param name="activity">The activity to be set.</param> | ||||
@@ -240,7 +240,7 @@ namespace Discord.WebSocket | |||||
/// Creates a guild for the logged-in user who is in less than 10 active guilds. | /// Creates a guild for the logged-in user who is in less than 10 active guilds. | ||||
/// </summary> | /// </summary> | ||||
/// <remarks> | /// <remarks> | ||||
/// This method creates a new guild on behalf of the logged-in user. | |||||
/// This method creates a new guild on behalf of the logged-in user. | |||||
/// <note type="warning"> | /// <note type="warning"> | ||||
/// Due to Discord's limitation, this method will only work for users that are in less than 10 guilds. | /// Due to Discord's limitation, this method will only work for users that are in less than 10 guilds. | ||||
/// </note> | /// </note> | ||||
@@ -317,8 +317,15 @@ namespace Discord.WebSocket | |||||
=> await CreateGuildAsync(name, region, jpegIcon, options).ConfigureAwait(false); | => await CreateGuildAsync(name, region, jpegIcon, options).ConfigureAwait(false); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
Task<IUser> IDiscordClient.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||||
=> Task.FromResult<IUser>(GetUser(id)); | |||||
async Task<IUser> IDiscordClient.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||||
{ | |||||
var user = GetUser(id); | |||||
if (user is not null || mode == CacheMode.CacheOnly) | |||||
return user; | |||||
return await Rest.GetUserAsync(id, options).ConfigureAwait(false); | |||||
} | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
Task<IUser> IDiscordClient.GetUserAsync(string username, string discriminator, RequestOptions options) | Task<IUser> IDiscordClient.GetUserAsync(string username, string discriminator, RequestOptions options) | ||||
=> Task.FromResult<IUser>(GetUser(username, discriminator)); | => Task.FromResult<IUser>(GetUser(username, discriminator)); | ||||
@@ -533,8 +533,15 @@ namespace Discord.WebSocket | |||||
=> await CreateGuildAsync(name, region, jpegIcon).ConfigureAwait(false); | => await CreateGuildAsync(name, region, jpegIcon).ConfigureAwait(false); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
Task<IUser> IDiscordClient.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||||
=> Task.FromResult<IUser>(GetUser(id)); | |||||
async Task<IUser> IDiscordClient.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||||
{ | |||||
var user = GetUser(id); | |||||
if (user is not null || mode == CacheMode.CacheOnly) | |||||
return user; | |||||
return await Rest.GetUserAsync(id, options).ConfigureAwait(false); | |||||
} | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
Task<IUser> IDiscordClient.GetUserAsync(string username, string discriminator, RequestOptions options) | Task<IUser> IDiscordClient.GetUserAsync(string username, string discriminator, RequestOptions options) | ||||
=> Task.FromResult<IUser>(GetUser(username, discriminator)); | => Task.FromResult<IUser>(GetUser(username, discriminator)); | ||||
@@ -543,7 +543,7 @@ namespace Discord.WebSocket | |||||
if(model == null) | if(model == null) | ||||
return null; | return null; | ||||
if (model.GuildId.IsSpecified) | if (model.GuildId.IsSpecified) | ||||
{ | { | ||||
var guild = State.GetGuild(model.GuildId.Value); | var guild = State.GetGuild(model.GuildId.Value); | ||||
@@ -2128,7 +2128,7 @@ namespace Discord.WebSocket | |||||
{ | { | ||||
await TimedInvokeAsync(_speakerRemoved, nameof(SpeakerRemoved), stage, guildUser); | await TimedInvokeAsync(_speakerRemoved, nameof(SpeakerRemoved), stage, guildUser); | ||||
} | } | ||||
} | |||||
} | |||||
} | } | ||||
await TimedInvokeAsync(_userVoiceStateUpdatedEvent, nameof(UserVoiceStateUpdated), user, before, after).ConfigureAwait(false); | await TimedInvokeAsync(_userVoiceStateUpdatedEvent, nameof(UserVoiceStateUpdated), user, before, after).ConfigureAwait(false); | ||||
@@ -2520,7 +2520,7 @@ namespace Discord.WebSocket | |||||
} | } | ||||
break; | break; | ||||
case "THREAD_MEMBERS_UPDATE": | |||||
case "THREAD_MEMBERS_UPDATE": | |||||
{ | { | ||||
await _gatewayLogger.DebugAsync("Received Dispatch (THREAD_MEMBERS_UPDATE)").ConfigureAwait(false); | await _gatewayLogger.DebugAsync("Received Dispatch (THREAD_MEMBERS_UPDATE)").ConfigureAwait(false); | ||||
@@ -3113,7 +3113,14 @@ namespace Discord.WebSocket | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
async Task<IUser> IDiscordClient.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | async Task<IUser> IDiscordClient.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | ||||
=> mode == CacheMode.AllowDownload ? await GetUserAsync(id, options).ConfigureAwait(false) : GetUser(id); | |||||
{ | |||||
var user = GetUser(id); | |||||
if (user is not null || mode == CacheMode.CacheOnly) | |||||
return user; | |||||
return await Rest.GetUserAsync(id, options).ConfigureAwait(false); | |||||
} | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
Task<IUser> IDiscordClient.GetUserAsync(string username, string discriminator, RequestOptions options) | Task<IUser> IDiscordClient.GetUserAsync(string username, string discriminator, RequestOptions options) | ||||
=> Task.FromResult<IUser>(GetUser(username, discriminator)); | => Task.FromResult<IUser>(GetUser(username, discriminator)); | ||||
@@ -4,6 +4,7 @@ using System.Collections.Immutable; | |||||
using System.Diagnostics; | using System.Diagnostics; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using Discord.Rest; | |||||
using Model = Discord.API.Channel; | using Model = Discord.API.Channel; | ||||
namespace Discord.WebSocket | namespace Discord.WebSocket | ||||
@@ -64,21 +65,44 @@ namespace Discord.WebSocket | |||||
#endregion | #endregion | ||||
#region IGuildChannel | #region IGuildChannel | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | |||||
=> ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>(Users).ToAsyncEnumerable(); | |||||
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, | |||||
RequestOptions options) | |||||
{ | |||||
return mode == CacheMode.AllowDownload | |||||
? ChannelHelper.GetUsersAsync(this, Guild, Discord, null, null, options) | |||||
: ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>(Users).ToAsyncEnumerable(); | |||||
} | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||||
=> Task.FromResult<IGuildUser>(GetUser(id)); | |||||
async Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||||
{ | |||||
var user = GetUser(id); | |||||
if (user is not null || mode == CacheMode.CacheOnly) | |||||
return user; | |||||
return await ChannelHelper.GetUserAsync(this, Guild, Discord, id, options).ConfigureAwait(false); | |||||
} | |||||
#endregion | #endregion | ||||
#region IChannel | #region IChannel | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | ||||
=> ImmutableArray.Create<IReadOnlyCollection<IUser>>(Users).ToAsyncEnumerable(); | |||||
{ | |||||
return mode == CacheMode.AllowDownload | |||||
? ChannelHelper.GetUsersAsync(this, Guild, Discord, null, null, options) | |||||
: ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>(Users).ToAsyncEnumerable(); | |||||
} | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||||
=> Task.FromResult<IUser>(GetUser(id)); | |||||
async Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||||
{ | |||||
var user = GetUser(id); | |||||
if (user is not null || mode == CacheMode.CacheOnly) | |||||
return user; | |||||
return await ChannelHelper.GetUserAsync(this, Guild, Discord, id, options).ConfigureAwait(false); | |||||
} | |||||
#endregion | #endregion | ||||
} | } | ||||
} | } |
@@ -352,7 +352,7 @@ namespace Discord.WebSocket | |||||
Task IAudioChannel.ModifyAsync(Action<AudioChannelProperties> func, RequestOptions options) { throw new NotSupportedException(); } | Task IAudioChannel.ModifyAsync(Action<AudioChannelProperties> func, RequestOptions options) { throw new NotSupportedException(); } | ||||
#endregion | #endregion | ||||
#region IChannel | |||||
#region IChannel | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | ||||
=> Task.FromResult<IUser>(GetUser(id)); | => Task.FromResult<IUser>(GetUser(id)); | ||||
@@ -214,10 +214,10 @@ namespace Discord.WebSocket | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | ||||
=> ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>(Users).ToAsyncEnumerable(); | |||||
=> ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>(Users).ToAsyncEnumerable(); //Overridden in Text/Voice | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | ||||
=> Task.FromResult<IGuildUser>(GetUser(id)); | |||||
=> Task.FromResult<IGuildUser>(GetUser(id)); //Overridden in Text/Voice | |||||
#endregion | #endregion | ||||
#region IChannel | #region IChannel | ||||
@@ -103,7 +103,7 @@ namespace Discord.WebSocket | |||||
/// The duration on which this thread archives after. | /// The duration on which this thread archives after. | ||||
/// <para> | /// <para> | ||||
/// <b>Note: </b> Options <see cref="ThreadArchiveDuration.OneWeek"/> and <see cref="ThreadArchiveDuration.ThreeDays"/> | /// <b>Note: </b> Options <see cref="ThreadArchiveDuration.OneWeek"/> and <see cref="ThreadArchiveDuration.ThreeDays"/> | ||||
/// are only available for guilds that are boosted. You can check in the <see cref="IGuild.Features"/> to see if the | |||||
/// are only available for guilds that are boosted. You can check in the <see cref="IGuild.Features"/> to see if the | |||||
/// guild has the <b>THREE_DAY_THREAD_ARCHIVE</b> and <b>SEVEN_DAY_THREAD_ARCHIVE</b>. | /// guild has the <b>THREE_DAY_THREAD_ARCHIVE</b> and <b>SEVEN_DAY_THREAD_ARCHIVE</b>. | ||||
/// </para> | /// </para> | ||||
/// </param> | /// </param> | ||||
@@ -355,11 +355,22 @@ namespace Discord.WebSocket | |||||
#region IGuildChannel | #region IGuildChannel | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||||
=> Task.FromResult<IGuildUser>(GetUser(id)); | |||||
async Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||||
{ | |||||
var user = GetUser(id); | |||||
if (user is not null || mode == CacheMode.CacheOnly) | |||||
return user; | |||||
return await ChannelHelper.GetUserAsync(this, Guild, Discord, id, options).ConfigureAwait(false); | |||||
} | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | ||||
=> ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>(Users).ToAsyncEnumerable(); | |||||
{ | |||||
return mode == CacheMode.AllowDownload | |||||
? ChannelHelper.GetUsersAsync(this, Guild, Discord, null, null, options) | |||||
: ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>(Users).ToAsyncEnumerable(); | |||||
} | |||||
#endregion | #endregion | ||||
#region IMessageChannel | #region IMessageChannel | ||||
@@ -372,7 +372,7 @@ namespace Discord.WebSocket | |||||
/// This field is based off of caching alone, since there is no events returned on the guild model. | /// This field is based off of caching alone, since there is no events returned on the guild model. | ||||
/// </remarks> | /// </remarks> | ||||
/// <returns> | /// <returns> | ||||
/// A read-only collection of guild events found within this guild. | |||||
/// A read-only collection of guild events found within this guild. | |||||
/// </returns> | /// </returns> | ||||
public IReadOnlyCollection<SocketGuildEvent> Events => _events.ToReadOnlyCollection(); | public IReadOnlyCollection<SocketGuildEvent> Events => _events.ToReadOnlyCollection(); | ||||
@@ -1928,8 +1928,15 @@ namespace Discord.WebSocket | |||||
async Task<IGuildUser> IGuild.AddGuildUserAsync(ulong userId, string accessToken, Action<AddGuildUserProperties> func, RequestOptions options) | async Task<IGuildUser> IGuild.AddGuildUserAsync(ulong userId, string accessToken, Action<AddGuildUserProperties> func, RequestOptions options) | ||||
=> await AddGuildUserAsync(userId, accessToken, func, options); | => await AddGuildUserAsync(userId, accessToken, func, options); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
Task<IGuildUser> IGuild.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||||
=> Task.FromResult<IGuildUser>(GetUser(id)); | |||||
async Task<IGuildUser> IGuild.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||||
{ | |||||
var user = GetUser(id); | |||||
if (user is not null || mode == CacheMode.CacheOnly) | |||||
return user; | |||||
return await GuildHelper.GetUserAsync(this, Discord, id, options).ConfigureAwait(false); | |||||
} | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
Task<IGuildUser> IGuild.GetCurrentUserAsync(CacheMode mode, RequestOptions options) | Task<IGuildUser> IGuild.GetCurrentUserAsync(CacheMode mode, RequestOptions options) | ||||
=> Task.FromResult<IGuildUser>(CurrentUser); | => Task.FromResult<IGuildUser>(CurrentUser); | ||||