Skip to content

Commit ca6c9bc

Browse files
Get Archived thread calls on text channels (#3198)
* Get Archived thread calls on text channels * Throw not supported exceptions on Thread&Voice channels * Extract interface * Should probably also change these * Move to regions
1 parent 8668092 commit ca6c9bc

File tree

13 files changed

+269
-127
lines changed

13 files changed

+269
-127
lines changed

src/Discord.Net.Core/Entities/Channels/IForumChannel.cs

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Discord
1010
/// <summary>
1111
/// Represents a forum channel in a guild that can create posts.
1212
/// </summary>
13-
public interface IForumChannel : IMentionable, INestedChannel, IIntegrationChannel
13+
public interface IForumChannel : IMentionable, INestedChannel, IIntegrationChannel, IThreadContainerChannel
1414
{
1515
/// <summary>
1616
/// Gets a value that indicates whether the channel is NSFW.
@@ -226,53 +226,5 @@ public Task<IThreadChannel> CreatePostWithFilesAsync(string title, IEnumerable<F
226226
int? slowmode = null, string text = null, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null,
227227
MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None, ForumTag[] tags = null);
228228

229-
/// <summary>
230-
/// Gets a collection of active threads within this forum channel.
231-
/// </summary>
232-
/// <param name="options">The options to be used when sending the request.</param>
233-
/// <returns>
234-
/// A task that represents an asynchronous get operation for retrieving the threads. The task result contains
235-
/// a collection of active threads.
236-
/// </returns>
237-
Task<IReadOnlyCollection<IThreadChannel>> GetActiveThreadsAsync(RequestOptions options = null);
238-
239-
/// <summary>
240-
/// Gets a collection of publicly archived threads within this forum channel.
241-
/// </summary>
242-
/// <param name="limit">The optional limit of how many to get.</param>
243-
/// <param name="before">The optional date to return threads created before this timestamp.</param>
244-
/// <param name="options">The options to be used when sending the request.</param>
245-
/// <returns>
246-
/// A task that represents an asynchronous get operation for retrieving the threads. The task result contains
247-
/// a collection of publicly archived threads.
248-
/// </returns>
249-
Task<IReadOnlyCollection<IThreadChannel>> GetPublicArchivedThreadsAsync(int? limit = null, DateTimeOffset? before = null, RequestOptions options = null);
250-
251-
/// <summary>
252-
/// Gets a collection of privately archived threads within this forum channel.
253-
/// </summary>
254-
/// <remarks>
255-
/// The bot requires the <see cref="GuildPermission.ManageThreads"/> permission in order to execute this request.
256-
/// </remarks>
257-
/// <param name="limit">The optional limit of how many to get.</param>
258-
/// <param name="before">The optional date to return threads created before this timestamp.</param>
259-
/// <param name="options">The options to be used when sending the request.</param>
260-
/// <returns>
261-
/// A task that represents an asynchronous get operation for retrieving the threads. The task result contains
262-
/// a collection of privately archived threads.
263-
/// </returns>
264-
Task<IReadOnlyCollection<IThreadChannel>> GetPrivateArchivedThreadsAsync(int? limit = null, DateTimeOffset? before = null, RequestOptions options = null);
265-
266-
/// <summary>
267-
/// Gets a collection of privately archived threads that the current bot has joined within this forum channel.
268-
/// </summary>
269-
/// <param name="limit">The optional limit of how many to get.</param>
270-
/// <param name="before">The optional date to return threads created before this timestamp.</param>
271-
/// <param name="options">The options to be used when sending the request.</param>
272-
/// <returns>
273-
/// A task that represents an asynchronous get operation for retrieving the threads. The task result contains
274-
/// a collection of privately archived threads.
275-
/// </returns>
276-
Task<IReadOnlyCollection<IThreadChannel>> GetJoinedPrivateArchivedThreadsAsync(int? limit = null, DateTimeOffset? before = null, RequestOptions options = null);
277229
}
278230
}

src/Discord.Net.Core/Entities/Channels/ITextChannel.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Discord
88
/// <summary>
99
/// Represents a generic channel in a guild that can send and receive messages.
1010
/// </summary>
11-
public interface ITextChannel : IMessageChannel, IMentionable, INestedChannel, IIntegrationChannel
11+
public interface ITextChannel : IMessageChannel, IMentionable, INestedChannel, IIntegrationChannel, IThreadContainerChannel
1212
{
1313
/// <summary>
1414
/// Gets a value that indicates whether the channel is NSFW.
@@ -125,7 +125,7 @@ public interface ITextChannel : IMessageChannel, IMentionable, INestedChannel, I
125125
/// The duration on which this thread archives after.
126126
/// <para>
127127
/// <b>Note: </b> Options <see cref="ThreadArchiveDuration.OneWeek"/> and <see cref="ThreadArchiveDuration.ThreeDays"/>
128-
/// are only available for guilds that are boosted. You can check in the <see cref="IGuild.Features"/> to see if the
128+
/// are only available for guilds that are boosted. You can check in the <see cref="IGuild.Features"/> to see if the
129129
/// guild has the <b>THREE_DAY_THREAD_ARCHIVE</b> and <b>SEVEN_DAY_THREAD_ARCHIVE</b>.
130130
/// </para>
131131
/// </param>
@@ -139,14 +139,5 @@ public interface ITextChannel : IMessageChannel, IMentionable, INestedChannel, I
139139
Task<IThreadChannel> CreateThreadAsync(string name, ThreadType type = ThreadType.PublicThread, ThreadArchiveDuration autoArchiveDuration = ThreadArchiveDuration.OneDay,
140140
IMessage message = null, bool? invitable = null, int? slowmode = null, RequestOptions options = null);
141141

142-
/// <summary>
143-
/// Gets a collection of active threads within this channel.
144-
/// </summary>
145-
/// <param name="options">The options to be used when sending the request.</param>
146-
/// <returns>
147-
/// A task that represents an asynchronous get operation for retrieving the threads. The task result contains
148-
/// a collection of active threads.
149-
/// </returns>
150-
Task<IReadOnlyCollection<IThreadChannel>> GetActiveThreadsAsync(RequestOptions options = null);
151142
}
152143
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
5+
namespace Discord
6+
{
7+
/// <summary>
8+
/// Represents a channel that can contain and query threads.
9+
/// </summary>
10+
public interface IThreadContainerChannel
11+
{
12+
/// <summary>
13+
/// Gets a collection of active threads within this channel.
14+
/// </summary>
15+
/// <param name="options">The options to be used when sending the request.</param>
16+
/// <returns>
17+
/// A task that represents an asynchronous get operation for retrieving the threads. The task result contains
18+
/// a collection of active threads.
19+
/// </returns>
20+
Task<IReadOnlyCollection<IThreadChannel>> GetActiveThreadsAsync(RequestOptions options = null);
21+
22+
/// <summary>
23+
/// Gets a collection of publicly archived threads within this channel.
24+
/// </summary>
25+
/// <param name="limit">The optional limit of how many to get.</param>
26+
/// <param name="before">The optional date to return threads created before this timestamp.</param>
27+
/// <param name="options">The options to be used when sending the request.</param>
28+
/// <returns>
29+
/// A task that represents an asynchronous get operation for retrieving the threads. The task result contains
30+
/// a collection of publicly archived threads.
31+
/// </returns>
32+
Task<IReadOnlyCollection<IThreadChannel>> GetPublicArchivedThreadsAsync(int? limit = null, DateTimeOffset? before = null, RequestOptions options = null);
33+
34+
/// <summary>
35+
/// Gets a collection of privately archived threads within this channel.
36+
/// </summary>
37+
/// <remarks>
38+
/// The bot requires the <see cref="GuildPermission.ManageThreads"/> permission in order to execute this request.
39+
/// </remarks>
40+
/// <param name="limit">The optional limit of how many to get.</param>
41+
/// <param name="before">The optional date to return threads created before this timestamp.</param>
42+
/// <param name="options">The options to be used when sending the request.</param>
43+
/// <returns>
44+
/// A task that represents an asynchronous get operation for retrieving the threads. The task result contains
45+
/// a collection of privately archived threads.
46+
/// </returns>
47+
Task<IReadOnlyCollection<IThreadChannel>> GetPrivateArchivedThreadsAsync(int? limit = null, DateTimeOffset? before = null, RequestOptions options = null);
48+
49+
/// <summary>
50+
/// Gets a collection of privately archived threads that the current bot has joined within this channel.
51+
/// </summary>
52+
/// <param name="limit">The optional limit of how many to get.</param>
53+
/// <param name="before">The optional date to return threads created before this timestamp.</param>
54+
/// <param name="options">The options to be used when sending the request.</param>
55+
/// <returns>
56+
/// A task that represents an asynchronous get operation for retrieving the threads. The task result contains
57+
/// a collection of privately archived threads.
58+
/// </returns>
59+
Task<IReadOnlyCollection<IThreadChannel>> GetJoinedPrivateArchivedThreadsAsync(int? limit = null, DateTimeOffset? before = null, RequestOptions options = null);
60+
}
61+
}

src/Discord.Net.Rest/Entities/Channels/RestForumChannel.cs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,6 @@ public Task<RestThreadChannel> CreatePostWithFilesAsync(string title, IEnumerabl
138138
MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None, ForumTag[] tags = null)
139139
=> ThreadHelper.CreatePostAsync(this, Discord, title, attachments, archiveDuration, slowmode, text, embed, options, allowedMentions, components, stickers, embeds, flags, tags?.Select(tag => tag.Id).ToArray());
140140

141-
/// <inheritdoc cref="ITextChannel.GetActiveThreadsAsync(RequestOptions)"/>
142-
public Task<IReadOnlyCollection<RestThreadChannel>> GetActiveThreadsAsync(RequestOptions options = null)
143-
=> ThreadHelper.GetActiveThreadsAsync(Guild, Id, Discord, options);
144-
145-
/// <inheritdoc cref="IForumChannel.GetJoinedPrivateArchivedThreadsAsync(int?, DateTimeOffset?, RequestOptions)"/>
146-
public Task<IReadOnlyCollection<RestThreadChannel>> GetJoinedPrivateArchivedThreadsAsync(int? limit = null, DateTimeOffset? before = null, RequestOptions options = null)
147-
=> ThreadHelper.GetJoinedPrivateArchivedThreadsAsync(this, Discord, limit, before, options);
148-
149-
/// <inheritdoc cref="IForumChannel.GetPrivateArchivedThreadsAsync(int?, DateTimeOffset?, RequestOptions)"/>
150-
public Task<IReadOnlyCollection<RestThreadChannel>> GetPrivateArchivedThreadsAsync(int? limit = null, DateTimeOffset? before = null, RequestOptions options = null)
151-
=> ThreadHelper.GetPrivateArchivedThreadsAsync(this, Discord, limit, before, options);
152-
153-
/// <inheritdoc cref="IForumChannel.GetPublicArchivedThreadsAsync(int?, DateTimeOffset?, RequestOptions)"/>
154-
public Task<IReadOnlyCollection<RestThreadChannel>> GetPublicArchivedThreadsAsync(int? limit = null, DateTimeOffset? before = null, RequestOptions options = null)
155-
=> ThreadHelper.GetPublicArchivedThreadsAsync(this, Discord, limit, before, options);
156-
157141
/// <inheritdoc cref="IIntegrationChannel.CreateWebhookAsync"/>
158142
public Task<RestWebhook> CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null)
159143
=> ChannelHelper.CreateWebhookAsync(this, Discord, name, avatar, options);
@@ -167,14 +151,6 @@ public Task<IReadOnlyCollection<RestWebhook>> GetWebhooksAsync(RequestOptions op
167151
=> ChannelHelper.GetWebhooksAsync(this, Discord, options);
168152

169153
#region IForumChannel
170-
async Task<IReadOnlyCollection<IThreadChannel>> IForumChannel.GetActiveThreadsAsync(RequestOptions options)
171-
=> await GetActiveThreadsAsync(options).ConfigureAwait(false);
172-
async Task<IReadOnlyCollection<IThreadChannel>> IForumChannel.GetPublicArchivedThreadsAsync(int? limit, DateTimeOffset? before, RequestOptions options)
173-
=> await GetPublicArchivedThreadsAsync(limit, before, options).ConfigureAwait(false);
174-
async Task<IReadOnlyCollection<IThreadChannel>> IForumChannel.GetPrivateArchivedThreadsAsync(int? limit, DateTimeOffset? before, RequestOptions options)
175-
=> await GetPrivateArchivedThreadsAsync(limit, before, options).ConfigureAwait(false);
176-
async Task<IReadOnlyCollection<IThreadChannel>> IForumChannel.GetJoinedPrivateArchivedThreadsAsync(int? limit, DateTimeOffset? before, RequestOptions options)
177-
=> await GetJoinedPrivateArchivedThreadsAsync(limit, before, options).ConfigureAwait(false);
178154
async Task<IThreadChannel> IForumChannel.CreatePostAsync(string title, ThreadArchiveDuration archiveDuration, int? slowmode, string text, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageComponent components, ISticker[] stickers, Embed[] embeds, MessageFlags flags, ForumTag[] tags)
179155
=> await CreatePostAsync(title, archiveDuration, slowmode, text, embed, options, allowedMentions, components, stickers, embeds, flags, tags).ConfigureAwait(false);
180156
async Task<IThreadChannel> IForumChannel.CreatePostWithFileAsync(string title, string filePath, ThreadArchiveDuration archiveDuration, int? slowmode, string text, Embed embed, RequestOptions options, bool isSpoiler, AllowedMentions allowedMentions, MessageComponent components, ISticker[] stickers, Embed[] embeds, MessageFlags flags, ForumTag[] tags)
@@ -230,5 +206,32 @@ async Task<IReadOnlyCollection<IWebhook>> IIntegrationChannel.GetWebhooksAsync(R
230206

231207
#endregion
232208

209+
#region IThreadContainerChannel
210+
/// <inheritdoc cref="IThreadContainerChannel.GetActiveThreadsAsync(RequestOptions)"/>
211+
public Task<IReadOnlyCollection<RestThreadChannel>> GetActiveThreadsAsync(RequestOptions options = null)
212+
=> ThreadHelper.GetActiveThreadsAsync(Guild, Id, Discord, options);
213+
214+
/// <inheritdoc cref="IThreadContainerChannel.GetJoinedPrivateArchivedThreadsAsync(int?, DateTimeOffset?, RequestOptions)"/>
215+
public Task<IReadOnlyCollection<RestThreadChannel>> GetJoinedPrivateArchivedThreadsAsync(int? limit = null, DateTimeOffset? before = null, RequestOptions options = null)
216+
=> ThreadHelper.GetJoinedPrivateArchivedThreadsAsync(this, Discord, limit, before, options);
217+
218+
/// <inheritdoc cref="IThreadContainerChannel.GetPrivateArchivedThreadsAsync(int?, DateTimeOffset?, RequestOptions)"/>
219+
public Task<IReadOnlyCollection<RestThreadChannel>> GetPrivateArchivedThreadsAsync(int? limit = null, DateTimeOffset? before = null, RequestOptions options = null)
220+
=> ThreadHelper.GetPrivateArchivedThreadsAsync(this, Discord, limit, before, options);
221+
222+
/// <inheritdoc cref="IThreadContainerChannel.GetPublicArchivedThreadsAsync(int?, DateTimeOffset?, RequestOptions)"/>
223+
public Task<IReadOnlyCollection<RestThreadChannel>> GetPublicArchivedThreadsAsync(int? limit = null, DateTimeOffset? before = null, RequestOptions options = null)
224+
=> ThreadHelper.GetPublicArchivedThreadsAsync(this, Discord, limit, before, options);
225+
226+
async Task<IReadOnlyCollection<IThreadChannel>> IThreadContainerChannel.GetActiveThreadsAsync(RequestOptions options)
227+
=> await GetActiveThreadsAsync(options).ConfigureAwait(false);
228+
async Task<IReadOnlyCollection<IThreadChannel>> IThreadContainerChannel.GetPublicArchivedThreadsAsync(int? limit, DateTimeOffset? before, RequestOptions options)
229+
=> await GetPublicArchivedThreadsAsync(limit, before, options).ConfigureAwait(false);
230+
async Task<IReadOnlyCollection<IThreadChannel>> IThreadContainerChannel.GetPrivateArchivedThreadsAsync(int? limit, DateTimeOffset? before, RequestOptions options)
231+
=> await GetPrivateArchivedThreadsAsync(limit, before, options).ConfigureAwait(false);
232+
async Task<IReadOnlyCollection<IThreadChannel>> IThreadContainerChannel.GetJoinedPrivateArchivedThreadsAsync(int? limit, DateTimeOffset? before, RequestOptions options)
233+
=> await GetJoinedPrivateArchivedThreadsAsync(limit, before, options).ConfigureAwait(false);
234+
#endregion
235+
233236
}
234237
}

0 commit comments

Comments
 (0)