Browse Source

Merge branch 'dev' into Interactions

pull/1923/head
quin lynch 3 years ago
parent
commit
97175ecae9
15 changed files with 154 additions and 7 deletions
  1. +45
    -1
      src/Discord.Net.Core/Entities/Channels/INestedChannel.cs
  2. +5
    -1
      src/Discord.Net.Core/Entities/Invites/TargetUserType.cs
  3. +4
    -0
      src/Discord.Net.Core/Entities/Teams/ITeam.cs
  4. +2
    -0
      src/Discord.Net.Rest/API/Common/Team.cs
  5. +6
    -0
      src/Discord.Net.Rest/API/Rest/CreateChannelInviteParams.cs
  6. +6
    -0
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  7. +48
    -0
      src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs
  8. +6
    -2
      src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs
  9. +7
    -1
      src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs
  10. +3
    -0
      src/Discord.Net.Rest/Entities/Teams/RestTeam.cs
  11. +6
    -0
      src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs
  12. +6
    -0
      src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs
  13. +2
    -2
      test/Discord.Net.Tests.Unit/EmbedBuilderTests.cs
  14. +4
    -0
      test/Discord.Net.Tests.Unit/MockedEntities/MockedTextChannel.cs
  15. +4
    -0
      test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs

+ 45
- 1
src/Discord.Net.Core/Entities/Channels/INestedChannel.cs View File

@@ -12,7 +12,7 @@ namespace Discord
/// Gets the parent (category) ID of this channel in the guild's channel list.
/// </summary>
/// <returns>
/// A <see cref="ulong"/> representing the snowflake identifier of the parent of this channel;
/// A <see cref="ulong"/> representing the snowflake identifier of the parent of this channel;
/// <c>null</c> if none is set.
/// </returns>
ulong? CategoryId { get; }
@@ -56,6 +56,50 @@ namespace Discord
/// metadata object containing information for the created invite.
/// </returns>
Task<IInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null);

/// <summary>
/// Creates a new invite to this channel.
/// </summary>
/// <example>
/// <para>The following example creates a new invite to this channel; the invite lasts for 12 hours and can only
/// be used 3 times throughout its lifespan.</para>
/// <code language="cs">
/// await guildChannel.CreateInviteAsync(maxAge: 43200, maxUses: 3);
/// </code>
/// </example>
/// <param name="applicationId">The id of the embedded application to open for this invite</param>
/// <param name="maxAge">The time (in seconds) until the invite expires. Set to <c>null</c> to never expire.</param>
/// <param name="maxUses">The max amount of times this invite may be used. Set to <c>null</c> to have unlimited uses.</param>
/// <param name="isTemporary">If <c>true</c>, the user accepting this invite will be kicked from the guild after closing their client.</param>
/// <param name="isUnique">If <c>true</c>, don't try to reuse a similar invite (useful for creating many unique one time use invites).</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous invite creation operation. The task result contains an invite
/// metadata object containing information for the created invite.
/// </returns>
Task<IInviteMetadata> CreateInviteToApplicationAsync(ulong applicationId, int? maxAge = 86400, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null);

/// <summary>
/// Creates a new invite to this channel.
/// </summary>
/// <example>
/// <para>The following example creates a new invite to this channel; the invite lasts for 12 hours and can only
/// be used 3 times throughout its lifespan.</para>
/// <code language="cs">
/// await guildChannel.CreateInviteAsync(maxAge: 43200, maxUses: 3);
/// </code>
/// </example>
/// <param name="user">The id of the user whose stream to display for this invite</param>
/// <param name="maxAge">The time (in seconds) until the invite expires. Set to <c>null</c> to never expire.</param>
/// <param name="maxUses">The max amount of times this invite may be used. Set to <c>null</c> to have unlimited uses.</param>
/// <param name="isTemporary">If <c>true</c>, the user accepting this invite will be kicked from the guild after closing their client.</param>
/// <param name="isUnique">If <c>true</c>, don't try to reuse a similar invite (useful for creating many unique one time use invites).</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous invite creation operation. The task result contains an invite
/// metadata object containing information for the created invite.
/// </returns>
Task<IInviteMetadata> CreateInviteToStreamAsync(IUser user, int? maxAge = 86400, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null);
/// <summary>
/// Gets a collection of all invites to this channel.
/// </summary>B


+ 5
- 1
src/Discord.Net.Core/Entities/Invites/TargetUserType.cs View File

@@ -9,6 +9,10 @@ namespace Discord
/// <summary>
/// The invite is for a Go Live stream.
/// </summary>
Stream = 1
Stream = 1,
/// <summary>
/// The invite is for embedded application.
/// </summary>
EmbeddedApplication = 2
}
}

+ 4
- 0
src/Discord.Net.Core/Entities/Teams/ITeam.cs View File

@@ -20,6 +20,10 @@ namespace Discord
/// </summary>
IReadOnlyList<ITeamMember> TeamMembers { get; }
/// <summary>
/// Gets the name of this team.
/// </summary>
string Name { get; }
/// <summary>
/// Gets the user identifier that owns this team.
/// </summary>
ulong OwnerUserId { get; }


+ 2
- 0
src/Discord.Net.Rest/API/Common/Team.cs View File

@@ -11,6 +11,8 @@ namespace Discord.API
public ulong Id { get; set; }
[JsonProperty("members")]
public TeamMember[] TeamMembers { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("owner_user_id")]
public ulong OwnerUserId { get; set; }
}


+ 6
- 0
src/Discord.Net.Rest/API/Rest/CreateChannelInviteParams.cs View File

@@ -14,5 +14,11 @@ namespace Discord.API.Rest
public Optional<bool> IsTemporary { get; set; }
[JsonProperty("unique")]
public Optional<bool> IsUnique { get; set; }
[JsonProperty("target_type")]
public Optional<TargetUserType> TargetType { get; set; }
[JsonProperty("target_user_id")]
public Optional<ulong> TargetUserId { get; set; }
[JsonProperty("target_application_id")]
public Optional<ulong> TargetApplicationId { get; set; }
}
}

+ 6
- 0
src/Discord.Net.Rest/DiscordRestApiClient.cs View File

@@ -1294,6 +1294,12 @@ namespace Discord.API
Preconditions.AtLeast(args.MaxUses, 0, nameof(args.MaxUses));
Preconditions.AtMost(args.MaxAge, 86400, nameof(args.MaxAge),
"The maximum age of an invite must be less than or equal to a day (86400 seconds).");
if (args.TargetType.IsSpecified)
{
Preconditions.NotEqual((int)args.TargetType.Value, (int)TargetUserType.Undefined, nameof(args.TargetType));
if (args.TargetType.Value == TargetUserType.Stream) Preconditions.GreaterThan(args.TargetUserId, 0, nameof(args.TargetUserId));
if (args.TargetType.Value == TargetUserType.EmbeddedApplication) Preconditions.GreaterThan(args.TargetApplicationId, 0, nameof(args.TargetUserId));
}
options = RequestOptions.CreateOrClone(options);

var ids = new BucketIds(channelId: channelId);


+ 48
- 0
src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs View File

@@ -120,6 +120,54 @@ namespace Discord.Rest
return RestInviteMetadata.Create(client, null, channel, model);
}

/// <exception cref="ArgumentException">
/// <paramref name="channel.Id"/> may not be equal to zero.
/// -and-
/// <paramref name="maxAge"/> and <paramref name="maxUses"/> must be greater than zero.
/// -and-
/// <paramref name="maxAge"/> must be lesser than 86400.
/// </exception>
public static async Task<RestInviteMetadata> CreateInviteToStreamAsync(IGuildChannel channel, BaseDiscordClient client,
int? maxAge, int? maxUses, bool isTemporary, bool isUnique, IUser user,
RequestOptions options)
{
var args = new API.Rest.CreateChannelInviteParams
{
IsTemporary = isTemporary,
IsUnique = isUnique,
MaxAge = maxAge ?? 0,
MaxUses = maxUses ?? 0,
TargetType = TargetUserType.Stream,
TargetUserId = user.Id
};
var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args, options).ConfigureAwait(false);
return RestInviteMetadata.Create(client, null, channel, model);
}

/// <exception cref="ArgumentException">
/// <paramref name="channel.Id"/> may not be equal to zero.
/// -and-
/// <paramref name="maxAge"/> and <paramref name="maxUses"/> must be greater than zero.
/// -and-
/// <paramref name="maxAge"/> must be lesser than 86400.
/// </exception>
public static async Task<RestInviteMetadata> CreateInviteToApplicationAsync(IGuildChannel channel, BaseDiscordClient client,
int? maxAge, int? maxUses, bool isTemporary, bool isUnique, ulong applicationId,
RequestOptions options)
{
var args = new API.Rest.CreateChannelInviteParams
{
IsTemporary = isTemporary,
IsUnique = isUnique,
MaxAge = maxAge ?? 0,
MaxUses = maxUses ?? 0,
TargetType = TargetUserType.EmbeddedApplication,
TargetApplicationId = applicationId
};
var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args, options).ConfigureAwait(false);
return RestInviteMetadata.Create(client, null, channel, model);
}

//Messages
public static async Task<RestMessage> GetMessageAsync(IMessageChannel channel, BaseDiscordClient client,
ulong id, RequestOptions options)


+ 6
- 2
src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs View File

@@ -17,7 +17,7 @@ namespace Discord.Rest
/// <inheritdoc />
public string Topic { get; private set; }
/// <inheritdoc />
public virtual int SlowModeInterval { get; private set; }
public virtual int SlowModeInterval { get; private set; }
/// <inheritdoc />
public ulong? CategoryId { get; private set; }

@@ -78,7 +78,7 @@ namespace Discord.Rest
/// </exception>
/// <returns>
/// A paged collection containing a collection of guild users that can access this channel. Flattening the
/// paginated response into a collection of users with
/// paginated response into a collection of users with
/// <see cref="AsyncEnumerableExtensions.FlattenAsync{T}"/> is required if you wish to access the users.
/// </returns>
public IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(RequestOptions options = null)
@@ -215,6 +215,10 @@ namespace Discord.Rest
/// <inheritdoc />
public async Task<IInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
=> await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false);
public Task<IInviteMetadata> CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
=> throw new NotImplementedException();
public Task<IInviteMetadata> CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
=> throw new NotImplementedException();
/// <inheritdoc />
public async Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null)
=> await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false);


+ 7
- 1
src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs View File

@@ -60,12 +60,18 @@ namespace Discord.Rest
/// <inheritdoc />
public Task SyncPermissionsAsync(RequestOptions options = null)
=> ChannelHelper.SyncPermissionsAsync(this, Discord, options);
//Invites
/// <inheritdoc />
public async Task<IInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
=> await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false);
/// <inheritdoc />
public async Task<IInviteMetadata> CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
=> await ChannelHelper.CreateInviteToApplicationAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, applicationId, options).ConfigureAwait(false);
/// <inheritdoc />
public async Task<IInviteMetadata> CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
=> await ChannelHelper.CreateInviteToStreamAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, user, options).ConfigureAwait(false);
/// <inheritdoc />
public async Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null)
=> await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false);



+ 3
- 0
src/Discord.Net.Rest/Entities/Teams/RestTeam.cs View File

@@ -12,6 +12,8 @@ namespace Discord.Rest
/// <inheritdoc />
public IReadOnlyList<ITeamMember> TeamMembers { get; private set; }
/// <inheritdoc />
public string Name { get; private set; }
/// <inheritdoc />
public ulong OwnerUserId { get; private set; }

private string _iconId;
@@ -30,6 +32,7 @@ namespace Discord.Rest
{
if (model.Icon.IsSpecified)
_iconId = model.Icon.Value;
Name = model.Name;
OwnerUserId = model.OwnerUserId;
TeamMembers = model.TeamMembers.Select(x => new RestTeamMember(Discord, x)).ToImmutableArray();
}


+ 6
- 0
src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs View File

@@ -258,6 +258,12 @@ namespace Discord.WebSocket
public async Task<IInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
=> await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false);
/// <inheritdoc />
public async Task<IInviteMetadata> CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
=> await ChannelHelper.CreateInviteToApplicationAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, applicationId, options).ConfigureAwait(false);
/// <inheritdoc />
public async Task<IInviteMetadata> CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
=> await ChannelHelper.CreateInviteToStreamAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, user, options).ConfigureAwait(false);
/// <inheritdoc />
public async Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null)
=> await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false);



+ 6
- 0
src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs View File

@@ -90,6 +90,12 @@ namespace Discord.WebSocket
public async Task<IInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
=> await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false);
/// <inheritdoc />
public async Task<IInviteMetadata> CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
=> await ChannelHelper.CreateInviteToApplicationAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, applicationId, options).ConfigureAwait(false);
/// <inheritdoc />
public async Task<IInviteMetadata> CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
=> await ChannelHelper.CreateInviteToStreamAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, user, options).ConfigureAwait(false);
/// <inheritdoc />
public async Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null)
=> await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false);



+ 2
- 2
test/Discord.Net.Tests.Unit/EmbedBuilderTests.cs View File

@@ -126,7 +126,7 @@ namespace Discord
{
IEnumerable<string> GetInvalid()
{
yield return new string('a', 2049);
yield return new string('a', 4097);
}
foreach (var description in GetInvalid())
{
@@ -149,7 +149,7 @@ namespace Discord
{
yield return string.Empty;
yield return null;
yield return new string('a', 2048);
yield return new string('a', 4096);
}
foreach (var description in GetValid())
{


+ 4
- 0
test/Discord.Net.Tests.Unit/MockedEntities/MockedTextChannel.cs View File

@@ -46,6 +46,10 @@ namespace Discord
{
throw new NotImplementedException();
}
public Task<IInviteMetadata> CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
=> throw new NotImplementedException();
public Task<IInviteMetadata> CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
=> throw new NotImplementedException();

public Task<IWebhook> CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null)
{


+ 4
- 0
test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs View File

@@ -47,6 +47,10 @@ namespace Discord
{
throw new NotImplementedException();
}
public Task<IInviteMetadata> CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
=> throw new NotImplementedException();
public Task<IInviteMetadata> CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
=> throw new NotImplementedException();

public Task DeleteAsync(RequestOptions options = null)
{


Loading…
Cancel
Save