[Feature] Follow news channels (#2590)
* initial commit * Apply suggestions from code review --------- Co-authored-by: Casmir <68127614+csmir@users.noreply.github.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
/// <summary>
|
||||
@@ -5,5 +7,12 @@ namespace Discord
|
||||
/// </summary>
|
||||
public interface INewsChannel : ITextChannel
|
||||
{
|
||||
/// <summary>
|
||||
/// Follow this channel to send messages to a target channel.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The Id of the created webhook.
|
||||
/// </returns>
|
||||
Task<ulong> FollowAnnouncementChannelAsync(ulong channelId, RequestOptions options);
|
||||
}
|
||||
}
|
||||
|
||||
12
src/Discord.Net.Rest/API/Common/FollowedChannel.cs
Normal file
12
src/Discord.Net.Rest/API/Common/FollowedChannel.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API;
|
||||
|
||||
internal class FollowedChannel
|
||||
{
|
||||
[JsonProperty("channel_id")]
|
||||
public ulong ChannelId { get; set; }
|
||||
|
||||
[JsonProperty("webhook_id")]
|
||||
public ulong WebhookId { get; set; }
|
||||
}
|
||||
@@ -1146,6 +1146,16 @@ namespace Discord.API
|
||||
var ids = new BucketIds(channelId: channelId);
|
||||
await SendAsync("POST", () => $"channels/{channelId}/messages/{messageId}/crosspost", ids, options: options).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<FollowedChannel> FollowChannelAsync(ulong newsChannelId, ulong followingChannelId, RequestOptions options = null)
|
||||
{
|
||||
Preconditions.NotEqual(newsChannelId, 0, nameof(newsChannelId));
|
||||
Preconditions.NotEqual(followingChannelId, 0, nameof(followingChannelId));
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
|
||||
var ids = new BucketIds(channelId: newsChannelId);
|
||||
return await SendJsonAsync<FollowedChannel>("POST", () => $"channels/{newsChannelId}/followers", new { webhook_channel_id = followingChannelId}, ids, options: options).ConfigureAwait(false);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Channel Permissions
|
||||
|
||||
@@ -590,6 +590,12 @@ namespace Discord.Rest
|
||||
return models.Select(x => RestWebhook.Create(client, channel, x))
|
||||
.ToImmutableArray();
|
||||
}
|
||||
|
||||
public static async Task<ulong> FollowAnnouncementChannelAsync(INewsChannel newsChannel, ulong channelId, BaseDiscordClient client, RequestOptions options)
|
||||
{
|
||||
var model = await client.ApiClient.FollowChannelAsync(newsChannel.Id, channelId, options);
|
||||
return model.WebhookId;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Categories
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Model = Discord.API.Channel;
|
||||
|
||||
namespace Discord.Rest
|
||||
@@ -25,5 +26,9 @@ namespace Discord.Rest
|
||||
return entity;
|
||||
}
|
||||
public override int SlowModeInterval => throw new NotSupportedException("News channels do not support Slow Mode.");
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<ulong> FollowAnnouncementChannelAsync(ulong channelId, RequestOptions options = null)
|
||||
=> ChannelHelper.FollowAnnouncementChannelAsync(this, channelId, Discord, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Discord.Rest;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -36,5 +37,13 @@ namespace Discord.WebSocket
|
||||
public override int SlowModeInterval
|
||||
=> throw new NotSupportedException("News channels do not support Slow Mode.");
|
||||
|
||||
/// <inheritdoc cref="INewsChannel.FollowAnnouncementChannelAsync"/>
|
||||
public Task<ulong> FollowAnnouncementChannelAsync(ITextChannel channel, RequestOptions options = null)
|
||||
=> FollowAnnouncementChannelAsync(channel.Id, options);
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<ulong> FollowAnnouncementChannelAsync(ulong channelId, RequestOptions options = null)
|
||||
=> ChannelHelper.FollowAnnouncementChannelAsync(this, channelId, Discord, options);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user