2. Clarified xml docs 3. Properly threw exceptions instead of failing silently.pull/1530/head
@@ -58,13 +58,16 @@ namespace Discord | |||||
Task UnpinAsync(RequestOptions options = null); | Task UnpinAsync(RequestOptions options = null); | ||||
/// <summary> | /// <summary> | ||||
/// Publish this message when executed in a News Channel. | |||||
/// Publish (crosspost) this message. | |||||
/// </summary> | /// </summary> | ||||
/// <param name="options">The options to be used when sending the request.</param> | /// <param name="options">The options to be used when sending the request.</param> | ||||
/// <returns> | /// <returns> | ||||
/// A task that represents the asynchronous operation for publishing this message. | /// A task that represents the asynchronous operation for publishing this message. | ||||
/// </returns> | /// </returns> | ||||
Task PublishAsync(RequestOptions options = null); | |||||
/// <remarks> | |||||
/// Publishing (crossposting) is only available in news channels. | |||||
/// </remarks> | |||||
Task CrosspostAsync(RequestOptions options = null); | |||||
/// <summary> | /// <summary> | ||||
/// Transforms this message's text into a human-readable form by resolving its tags. | /// Transforms this message's text into a human-readable form by resolving its tags. | ||||
@@ -695,7 +695,7 @@ namespace Discord.API | |||||
var ids = new BucketIds(channelId: channelId); | var ids = new BucketIds(channelId: channelId); | ||||
await SendAsync("POST", () => $"channels/{channelId}/typing", ids, options: options).ConfigureAwait(false); | await SendAsync("POST", () => $"channels/{channelId}/typing", ids, options: options).ConfigureAwait(false); | ||||
} | } | ||||
public async Task PublishAsync(ulong channelId, ulong messageId, RequestOptions options = null) | |||||
public async Task CrosspostAsync(ulong channelId, ulong messageId, RequestOptions options = null) | |||||
{ | { | ||||
Preconditions.NotEqual(channelId, 0, nameof(channelId)); | Preconditions.NotEqual(channelId, 0, nameof(channelId)); | ||||
Preconditions.NotEqual(messageId, 0, nameof(messageId)); | Preconditions.NotEqual(messageId, 0, nameof(messageId)); | ||||
@@ -286,13 +286,13 @@ namespace Discord.Rest | |||||
return MessageSource.User; | return MessageSource.User; | ||||
} | } | ||||
public static Task PublishAsync(IMessage msg, BaseDiscordClient client, RequestOptions options) | |||||
=> PublishAsync(msg.Channel.Id, msg.Id, client, options); | |||||
public static Task CrosspostAsync(IMessage msg, BaseDiscordClient client, RequestOptions options) | |||||
=> CrosspostAsync(msg.Channel.Id, msg.Id, client, options); | |||||
public static async Task PublishAsync(ulong channelId, ulong msgId, BaseDiscordClient client, | |||||
public static async Task CrosspostAsync(ulong channelId, ulong msgId, BaseDiscordClient client, | |||||
RequestOptions options) | RequestOptions options) | ||||
{ | { | ||||
await client.ApiClient.PublishAsync(channelId, msgId, options).ConfigureAwait(false); | |||||
await client.ApiClient.CrosspostAsync(channelId, msgId, options).ConfigureAwait(false); | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -148,12 +148,15 @@ namespace Discord.Rest | |||||
TagHandling roleHandling = TagHandling.Name, TagHandling everyoneHandling = TagHandling.Ignore, TagHandling emojiHandling = TagHandling.Name) | TagHandling roleHandling = TagHandling.Name, TagHandling everyoneHandling = TagHandling.Ignore, TagHandling emojiHandling = TagHandling.Name) | ||||
=> MentionUtils.Resolve(this, 0, userHandling, channelHandling, roleHandling, everyoneHandling, emojiHandling); | => MentionUtils.Resolve(this, 0, userHandling, channelHandling, roleHandling, everyoneHandling, emojiHandling); | ||||
public async Task PublishAsync(RequestOptions options = null) | |||||
/// <inheritdoc /> | |||||
public async Task CrosspostAsync(RequestOptions options = null) | |||||
{ | { | ||||
if (Channel.GetType() == typeof(RestNewsChannel)) | |||||
if (!(Channel is RestNewsChannel)) | |||||
{ | { | ||||
await MessageHelper.PublishAsync(this, Discord, options); | |||||
throw new InvalidOperationException("Publishing (crossposting) is only valid in news channels."); | |||||
} | } | ||||
await MessageHelper.CrosspostAsync(this, Discord, options); | |||||
} | } | ||||
private string DebuggerDisplay => $"{Author}: {Content} ({Id}{(Attachments.Count > 0 ? $", {Attachments.Count} Attachments" : "")})"; | private string DebuggerDisplay => $"{Author}: {Content} ({Id}{(Attachments.Count > 0 ? $", {Attachments.Count} Attachments" : "")})"; | ||||
@@ -147,16 +147,19 @@ namespace Discord.WebSocket | |||||
public string Resolve(TagHandling userHandling = TagHandling.Name, TagHandling channelHandling = TagHandling.Name, | public string Resolve(TagHandling userHandling = TagHandling.Name, TagHandling channelHandling = TagHandling.Name, | ||||
TagHandling roleHandling = TagHandling.Name, TagHandling everyoneHandling = TagHandling.Ignore, TagHandling emojiHandling = TagHandling.Name) | TagHandling roleHandling = TagHandling.Name, TagHandling everyoneHandling = TagHandling.Ignore, TagHandling emojiHandling = TagHandling.Name) | ||||
=> MentionUtils.Resolve(this, 0, userHandling, channelHandling, roleHandling, everyoneHandling, emojiHandling); | => MentionUtils.Resolve(this, 0, userHandling, channelHandling, roleHandling, everyoneHandling, emojiHandling); | ||||
private string DebuggerDisplay => $"{Author}: {Content} ({Id}{(Attachments.Count > 0 ? $", {Attachments.Count} Attachments" : "")})"; | |||||
internal new SocketUserMessage Clone() => MemberwiseClone() as SocketUserMessage; | |||||
public async Task PublishAsync(RequestOptions options = null) | |||||
/// <inheritdoc /> | |||||
public async Task CrosspostAsync(RequestOptions options = null) | |||||
{ | { | ||||
if (Channel.GetType() == typeof(SocketNewsChannel)) | |||||
if (!(Channel is SocketNewsChannel)) | |||||
{ | { | ||||
await MessageHelper.PublishAsync(this, Discord, options); | |||||
throw new InvalidOperationException("Publishing (crossposting) is only valid in news channels."); | |||||
} | } | ||||
await MessageHelper.CrosspostAsync(this, Discord, options); | |||||
} | } | ||||
private string DebuggerDisplay => $"{Author}: {Content} ({Id}{(Attachments.Count > 0 ? $", {Attachments.Count} Attachments" : "")})"; | |||||
internal new SocketUserMessage Clone() => MemberwiseClone() as SocketUserMessage; | |||||
} | } | ||||
} | } |