Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Crosspost throwing InvalidOperationException #1671

Merged
merged 2 commits into from
Nov 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Discord.Net.Core/Entities/Channels/INewsChannel.cs
Original file line number Diff line number Diff line change
@@ -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
{
}
}
2 changes: 1 addition & 1 deletion src/Discord.Net.Rest/Entities/Channels/RestNewsChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ public Task ModifySuppressionAsync(bool suppressEmbeds, RequestOptions options =
=> 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.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Discord.Net.WebSocket/Entities/Invites/SocketInvite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ChannelType IInvite.ChannelType
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.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ public Task ModifySuppressionAsync(bool suppressEmbeds, RequestOptions options =
=> 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.");
}
Expand Down