Browse Source

1. Aligned with naming standards

2. Clarified xml docs
3. Properly threw exceptions instead of failing silently.
pull/1530/head
Matt Smith 5 years ago
parent
commit
537aa7e247
5 changed files with 25 additions and 16 deletions
  1. +5
    -2
      src/Discord.Net.Core/Entities/Messages/IUserMessage.cs
  2. +1
    -1
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  3. +4
    -4
      src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs
  4. +6
    -3
      src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs
  5. +9
    -6
      src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs

+ 5
- 2
src/Discord.Net.Core/Entities/Messages/IUserMessage.cs View File

@@ -58,13 +58,16 @@ namespace Discord
Task UnpinAsync(RequestOptions options = null);

/// <summary>
/// Publish this message when executed in a News Channel.
/// Publish (crosspost) this message.
/// </summary>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous operation for publishing this message.
/// </returns>
Task PublishAsync(RequestOptions options = null);
/// <remarks>
/// Publishing (crossposting) is only available in news channels.
/// </remarks>
Task CrosspostAsync(RequestOptions options = null);

/// <summary>
/// Transforms this message's text into a human-readable form by resolving its tags.


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

@@ -695,7 +695,7 @@ namespace Discord.API
var ids = new BucketIds(channelId: channelId);
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(messageId, 0, nameof(messageId));


+ 4
- 4
src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs View File

@@ -286,13 +286,13 @@ namespace Discord.Rest
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)
{
await client.ApiClient.PublishAsync(channelId, msgId, options).ConfigureAwait(false);
await client.ApiClient.CrosspostAsync(channelId, msgId, options).ConfigureAwait(false);
}
}
}

+ 6
- 3
src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs View File

@@ -148,12 +148,15 @@ namespace Discord.Rest
TagHandling roleHandling = TagHandling.Name, TagHandling everyoneHandling = TagHandling.Ignore, TagHandling emojiHandling = TagHandling.Name)
=> 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" : "")})";


+ 9
- 6
src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs View File

@@ -147,16 +147,19 @@ namespace Discord.WebSocket
public string Resolve(TagHandling userHandling = TagHandling.Name, TagHandling channelHandling = TagHandling.Name,
TagHandling roleHandling = TagHandling.Name, TagHandling everyoneHandling = TagHandling.Ignore, TagHandling emojiHandling = TagHandling.Name)
=> 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;
}
}

Loading…
Cancel
Save