Browse Source

feature: Add DefaultArchiveDuration to ITextChannel (#2295)

tags/3.7.0
Armano den Boef GitHub 3 years ago
parent
commit
1f01881beb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 2 deletions
  1. +11
    -0
      src/Discord.Net.Core/Entities/Channels/ITextChannel.cs
  2. +3
    -0
      src/Discord.Net.Rest/API/Common/Channel.cs
  3. +8
    -1
      src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs
  4. +7
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs
  5. +2
    -0
      test/Discord.Net.Tests.Unit/MockedEntities/MockedTextChannel.cs

+ 11
- 0
src/Discord.Net.Core/Entities/Channels/ITextChannel.cs View File

@@ -35,6 +35,17 @@ namespace Discord
/// </returns>
int SlowModeInterval { get; }

/// <summary>
/// Gets the default auto-archive duration for client-created threads in this channel.
/// </summary>
/// <remarks>
/// The value of this property does not affect API thread creation, it will not respect this value.
/// </remarks>
/// <returns>
/// The default auto-archive duration for thread creation in this channel.
/// </returns>
ThreadArchiveDuration DefaultArchiveDuration { get; }

/// <summary>
/// Bulk-deletes multiple messages.
/// </summary>


+ 3
- 0
src/Discord.Net.Rest/API/Common/Channel.cs View File

@@ -66,5 +66,8 @@ namespace Discord.API

[JsonProperty("member_count")]
public Optional<int> MemberCount { get; set; }

[JsonProperty("default_auto_archive_duration")]
public Optional<ThreadArchiveDuration> AutoArchiveDuration { get; set; }
}
}

+ 8
- 1
src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs View File

@@ -21,11 +21,12 @@ namespace Discord.Rest
public virtual int SlowModeInterval { get; private set; }
/// <inheritdoc />
public ulong? CategoryId { get; private set; }

/// <inheritdoc />
public string Mention => MentionUtils.MentionChannel(Id);
/// <inheritdoc />
public bool IsNsfw { get; private set; }
/// <inheritdoc />
public ThreadArchiveDuration DefaultArchiveDuration { get; private set; }

internal RestTextChannel(BaseDiscordClient discord, IGuild guild, ulong id)
: base(discord, guild, id)
@@ -46,6 +47,12 @@ namespace Discord.Rest
if (model.SlowMode.IsSpecified)
SlowModeInterval = model.SlowMode.Value;
IsNsfw = model.Nsfw.GetValueOrDefault();

if (model.AutoArchiveDuration.IsSpecified)
DefaultArchiveDuration = model.AutoArchiveDuration.Value;
else
DefaultArchiveDuration = ThreadArchiveDuration.OneDay;
// basic value at channel creation. Shouldn't be called since guild text channels always have this property
}

/// <inheritdoc />


+ 7
- 1
src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs View File

@@ -40,7 +40,8 @@ namespace Discord.WebSocket
private bool _nsfw;
/// <inheritdoc />
public bool IsNsfw => _nsfw;

/// <inheritdoc />
public ThreadArchiveDuration DefaultArchiveDuration { get; private set; }
/// <inheritdoc />
public string Mention => MentionUtils.MentionChannel(Id);
/// <inheritdoc />
@@ -76,6 +77,11 @@ namespace Discord.WebSocket
Topic = model.Topic.GetValueOrDefault();
SlowModeInterval = model.SlowMode.GetValueOrDefault(); // some guilds haven't been patched to include this yet?
_nsfw = model.Nsfw.GetValueOrDefault();
if (model.AutoArchiveDuration.IsSpecified)
DefaultArchiveDuration = model.AutoArchiveDuration.Value;
else
DefaultArchiveDuration = ThreadArchiveDuration.OneDay;
// basic value at channel creation. Shouldn't be called since guild text channels always have this property
}

/// <inheritdoc />


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

@@ -10,6 +10,8 @@ namespace Discord
{
public bool IsNsfw => throw new NotImplementedException();

public ThreadArchiveDuration DefaultArchiveDuration => throw new NotImplementedException();

public string Topic => throw new NotImplementedException();

public int SlowModeInterval => throw new NotImplementedException();


Loading…
Cancel
Save