Browse Source

fix: Crosspost throwing InvalidOperationException (#1671)

* Add INewsChannel

* Renaming variable to match the new type
tags/2.3.0
Paulo GitHub 4 years ago
parent
commit
9134443494
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 7 deletions
  1. +9
    -0
      src/Discord.Net.Core/Entities/Channels/INewsChannel.cs
  2. +1
    -1
      src/Discord.Net.Rest/Entities/Channels/RestNewsChannel.cs
  3. +2
    -2
      src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs
  4. +1
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketNewsChannel.cs
  5. +1
    -1
      src/Discord.Net.WebSocket/Entities/Invites/SocketInvite.cs
  6. +2
    -2
      src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs

+ 9
- 0
src/Discord.Net.Core/Entities/Channels/INewsChannel.cs View File

@@ -0,0 +1,9 @@
namespace Discord
{
/// <summary>
/// Represents a generic news channel in a guild that can send and receive messages.
/// </summary>
public interface INewsChannel : ITextChannel
{
}
}

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

@@ -12,7 +12,7 @@ namespace Discord.Rest
/// Represents a REST-based news channel in a guild that has the same properties as a <see cref="RestTextChannel"/>.
/// </summary>
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class RestNewsChannel : RestTextChannel
public class RestNewsChannel : RestTextChannel, INewsChannel
{
internal RestNewsChannel(BaseDiscordClient discord, IGuild guild, ulong id)
:base(discord, guild, id)


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

@@ -154,10 +154,10 @@ namespace Discord.Rest
=> MentionUtils.Resolve(this, 0, userHandling, channelHandling, roleHandling, everyoneHandling, emojiHandling);

/// <inheritdoc />
/// <exception cref="InvalidOperationException">This operation may only be called on a <see cref="RestNewsChannel"/> channel.</exception>
/// <exception cref="InvalidOperationException">This operation may only be called on a <see cref="INewsChannel"/> channel.</exception>
public async Task CrosspostAsync(RequestOptions options = null)
{
if (!(Channel is RestNewsChannel))
if (!(Channel is INewsChannel))
{
throw new InvalidOperationException("Publishing (crossposting) is only valid in news channels.");
}


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

@@ -15,7 +15,7 @@ namespace Discord.WebSocket
/// </note>
/// </remarks>
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class SocketNewsChannel : SocketTextChannel
public class SocketNewsChannel : SocketTextChannel, INewsChannel
{
internal SocketNewsChannel(DiscordSocketClient discord, ulong id, SocketGuild guild)
:base(discord, id, guild)


+ 1
- 1
src/Discord.Net.WebSocket/Entities/Invites/SocketInvite.cs View File

@@ -34,7 +34,7 @@ namespace Discord.WebSocket
case ICategoryChannel categoryChannel: return ChannelType.Category;
case IDMChannel dmChannel: return ChannelType.DM;
case IGroupChannel groupChannel: return ChannelType.Group;
case SocketNewsChannel socketNewsChannel: return ChannelType.News;
case INewsChannel newsChannel: return ChannelType.News;
case ITextChannel textChannel: return ChannelType.Text;
default: throw new InvalidOperationException("Invalid channel type.");
}


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

@@ -158,10 +158,10 @@ namespace Discord.WebSocket
=> MentionUtils.Resolve(this, 0, userHandling, channelHandling, roleHandling, everyoneHandling, emojiHandling);

/// <inheritdoc />
/// <exception cref="InvalidOperationException">This operation may only be called on a <see cref="SocketNewsChannel"/> channel.</exception>
/// <exception cref="InvalidOperationException">This operation may only be called on a <see cref="INewsChannel"/> channel.</exception>
public async Task CrosspostAsync(RequestOptions options = null)
{
if (!(Channel is SocketNewsChannel))
if (!(Channel is INewsChannel))
{
throw new InvalidOperationException("Publishing (crossposting) is only valid in news channels.");
}


Loading…
Cancel
Save