Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ async static Task PropertiesAsync()
attachment = new QuotedPrintableAttachmentProperties("polish.txt",
new MemoryStream("R=C3=B3=C5=BCowy means pink"u8.ToArray()));

// TODO: This guide is outdated for the new channels interface representation.
TextChannel textChannel = null!;

HttpClient httpClient = null!;
Expand Down
20 changes: 10 additions & 10 deletions NetCord.Services/ApplicationCommands/ApplicationCommandContexts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ApplicationCommandContext(ApplicationCommandInteraction interaction
public Guild? Guild => Interaction.Guild;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

public User User => Interaction.User;

Expand All @@ -50,7 +50,7 @@ public class HttpApplicationCommandContext(ApplicationCommandInteraction interac
public RestClient Client => client;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => (ITextChannel)Interaction.Channel;

public User User => Interaction.User;
}
Expand Down Expand Up @@ -84,7 +84,7 @@ public class SlashCommandContext(SlashCommandInteraction interaction, GatewayCli
public Guild? Guild => Interaction.Guild;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

public User User => Interaction.User;

Expand All @@ -105,7 +105,7 @@ public class HttpSlashCommandContext(SlashCommandInteraction interaction, RestCl
public RestClient Client => client;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

public User User => Interaction.User;
}
Expand Down Expand Up @@ -139,7 +139,7 @@ public class UserCommandContext(UserCommandInteraction interaction, GatewayClien
public Guild? Guild => Interaction.Guild;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

public User User => Interaction.User;

Expand All @@ -165,7 +165,7 @@ public class HttpUserCommandContext(UserCommandInteraction interaction, RestClie
public RestClient Client => client;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

public User User => Interaction.User;

Expand Down Expand Up @@ -204,7 +204,7 @@ public class MessageCommandContext(MessageCommandInteraction interaction, Gatewa
public Guild? Guild => Interaction.Guild;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

public User User => Interaction.User;

Expand All @@ -230,7 +230,7 @@ public class HttpMessageCommandContext(MessageCommandInteraction interaction, Re
public RestClient Client => client;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

public User User => Interaction.User;

Expand Down Expand Up @@ -269,7 +269,7 @@ public class EntryPointCommandContext(EntryPointCommandInteraction interaction,
public Guild? Guild => Interaction.Guild;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

public User User => Interaction.User;

Expand All @@ -290,7 +290,7 @@ public class HttpEntryPointCommandContext(EntryPointCommandInteraction interacti
public RestClient Client => client;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

public User User => Interaction.User;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class AutocompleteInteractionContext(AutocompleteInteraction interaction,
public Guild? Guild => Interaction.Guild;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => (ITextChannel)Interaction.Channel;

public User User => Interaction.User;

Expand All @@ -49,7 +49,7 @@ public class HttpAutocompleteInteractionContext(AutocompleteInteraction interact
public RestClient Client => client;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => (ITextChannel)Interaction.Channel;

public User User => Interaction.User;
}
2 changes: 1 addition & 1 deletion NetCord.Services/Commands/CommandContexts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class CommandContext(Message message, GatewayClient client)
public Guild? Guild => Message.Guild;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel? Channel => Message.Channel;
public ITextChannel? Channel => Message.Channel;

public User User => Message.Author;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public override ValueTask<CommandTypeParserResult> ParseAsync(ReadOnlyMemory<cha
return new(GetChannel<TextChannel>(channel, input.Span));
}
else
return new(GetGuildChannel<Channel>(guild, input.Span));
return new(GetGuildChannel<IChannel>(guild, input.Span));

return new(CommandTypeParserResult.Fail("The channel was not found."));
}

protected CommandTypeParserResult GetChannel<T>(TextChannel channel, ReadOnlySpan<char> input)
protected CommandTypeParserResult GetChannel<T>(ITextChannel channel, ReadOnlySpan<char> input)
{
if (Mention.TryParseChannel(input, out var id))
{
Expand Down
2 changes: 1 addition & 1 deletion NetCord.Services/Commands/TypeReaders/UserTypeReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override ValueTask<CommandTypeParserResult> ParseAsync(ReadOnlyMemory<cha
return new(CommandTypeParserResult.Fail("The user was not found."));
}

protected CommandTypeParserResult GetUser(DMChannel dMChannel, ReadOnlySpan<char> input)
protected CommandTypeParserResult GetUser(IDMChannel dMChannel, ReadOnlySpan<char> input)
{
var users = dMChannel.Users;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ComponentInteractionContext(ComponentInteraction interaction, Gatew
public Guild? Guild => Interaction.Guild;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

ulong? IGuildContext.GuildId => Interaction.GuildId;
}
Expand All @@ -53,7 +53,7 @@ public class HttpComponentInteractionContext(ComponentInteraction interaction, R
public User User => Interaction.User;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;
}

/// <summary>
Expand Down Expand Up @@ -90,7 +90,7 @@ public class MessageComponentInteractionContext(MessageComponentInteraction inte
public Guild? Guild => Interaction.Guild;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

ulong? IGuildContext.GuildId => Interaction.GuildId;
}
Expand All @@ -114,7 +114,7 @@ public class HttpMessageComponentInteractionContext(MessageComponentInteraction
public User User => Interaction.User;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;
}

/// <summary>
Expand Down Expand Up @@ -151,7 +151,7 @@ public class ButtonInteractionContext(ButtonInteraction interaction, GatewayClie
public Guild? Guild => Interaction.Guild;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

ulong? IGuildContext.GuildId => Interaction.GuildId;
}
Expand All @@ -175,7 +175,7 @@ public class HttpButtonInteractionContext(ButtonInteraction interaction, RestCli
public User User => Interaction.User;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;
}

/// <summary>
Expand Down Expand Up @@ -212,7 +212,7 @@ public class StringMenuInteractionContext(StringMenuInteraction interaction, Gat
public Guild? Guild => Interaction.Guild;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

/// <summary>
/// The selected string values from the menu.
Expand Down Expand Up @@ -241,7 +241,7 @@ public class HttpStringMenuInteractionContext(StringMenuInteraction interaction,
public User User => Interaction.User;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

/// <summary>
/// The selected string values from the menu.
Expand Down Expand Up @@ -283,7 +283,7 @@ public class EntityMenuInteractionContext(EntityMenuInteraction interaction, Gat
public Guild? Guild => Interaction.Guild;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

/// <summary>
/// The selected entity IDs from the menu.
Expand Down Expand Up @@ -312,7 +312,7 @@ public class HttpEntityMenuInteractionContext(EntityMenuInteraction interaction,
public User User => Interaction.User;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

/// <summary>
/// The selected entity IDs from the menu.
Expand Down Expand Up @@ -354,7 +354,7 @@ public class UserMenuInteractionContext(UserMenuInteraction interaction, Gateway
public Guild? Guild => Interaction.Guild;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

/// <summary>
/// The selected users from the menu.
Expand Down Expand Up @@ -383,7 +383,7 @@ public class HttpUserMenuInteractionContext(UserMenuInteraction interaction, Res
public User User => Interaction.User;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

/// <summary>
/// The selected users from the menu.
Expand Down Expand Up @@ -425,7 +425,7 @@ public class RoleMenuInteractionContext(RoleMenuInteraction interaction, Gateway
public Guild? Guild => Interaction.Guild;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

/// <summary>
/// The selected roles from the menu.
Expand Down Expand Up @@ -454,7 +454,7 @@ public class HttpRoleMenuInteractionContext(RoleMenuInteraction interaction, Res
public User User => Interaction.User;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

/// <summary>
/// The selected roles from the menu.
Expand Down Expand Up @@ -496,7 +496,7 @@ public class MentionableMenuInteractionContext(MentionableMenuInteraction intera
public Guild? Guild => Interaction.Guild;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

/// <summary>
/// The selected mentionables (users or roles) from the menu.
Expand Down Expand Up @@ -525,7 +525,7 @@ public class HttpMentionableMenuInteractionContext(MentionableMenuInteraction in
public User User => Interaction.User;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

/// <summary>
/// The selected mentionables (users or roles) from the menu.
Expand Down Expand Up @@ -567,12 +567,12 @@ public class ChannelMenuInteractionContext(ChannelMenuInteraction interaction, G
public Guild? Guild => Interaction.Guild;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => (ITextChannel)Interaction.Channel;

/// <summary>
/// The selected channels from the menu.
/// </summary>
public IReadOnlyList<Channel> SelectedValues => Interaction.Data.SelectedValues;
public IReadOnlyList<IChannel> SelectedValues => Interaction.Data.SelectedValues;

ulong? IGuildContext.GuildId => Interaction.GuildId;
}
Expand All @@ -596,12 +596,12 @@ public class HttpChannelMenuInteractionContext(ChannelMenuInteraction interactio
public User User => Interaction.User;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => (ITextChannel)Interaction.Channel;

/// <summary>
/// The selected channels from the menu.
/// </summary>
public IReadOnlyList<Channel> SelectedValues => Interaction.Data.SelectedValues;
public IReadOnlyList<IChannel> SelectedValues => Interaction.Data.SelectedValues;
}

/// <summary>
Expand Down Expand Up @@ -635,7 +635,7 @@ public class ModalInteractionContext(ModalInteraction interaction, GatewayClient
public Guild? Guild => Interaction.Guild;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

/// <summary>
/// The components submitted with the modal.
Expand All @@ -661,7 +661,7 @@ public class HttpModalInteractionContext(ModalInteraction interaction, RestClien
public User User => Interaction.User;

/// <inheritdoc cref="IChannelContext.Channel" path="/summary" />
public TextChannel Channel => Interaction.Channel;
public ITextChannel Channel => Interaction.Channel;

/// <summary>
/// The components submitted with the modal.
Expand Down
2 changes: 1 addition & 1 deletion NetCord.Services/Contexts/IChannelContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public interface IChannelContext : IContext
/// Channel in which the handled command or interaction was invoked.
/// </summary>
/// <remarks>May be <see langword="null"/> if the channel has not been cached.</remarks>
public TextChannel? Channel { get; }
public ITextChannel? Channel { get; }
}
2 changes: 1 addition & 1 deletion NetCord/ChannelMenuInteraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ public unsafe ChannelMenuInteractionData(JsonModels.JsonInteractionData jsonMode
SelectedValues = selectedValues;
}

public new IReadOnlyList<Channel> SelectedValues { get; }
public new IReadOnlyList<IChannel> SelectedValues { get; }
}
27 changes: 4 additions & 23 deletions NetCord/Channels/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,19 @@

namespace NetCord;

public abstract partial class Channel(JsonChannel jsonModel, RestClient client) : ClientEntity(client), IJsonModel<JsonChannel>, IInteractionChannel
internal abstract partial class Channel(JsonChannel jsonModel, RestClient client) : ClientEntity(client), IJsonModel<JsonChannel>, IInteractionChannel
{
JsonChannel IJsonModel<JsonChannel>.JsonModel => _jsonModel;

private protected JsonChannel _jsonModel = jsonModel;

public override ulong Id => _jsonModel.Id;
public ChannelFlags Flags => _jsonModel.Flags.GetValueOrDefault();

public ChannelFlags? Flags => _jsonModel.Flags;

Permissions IInteractionChannel.Permissions => _jsonModel.Permissions.GetValueOrDefault();

public override string ToString() => $"<#{Id}>";

public override bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null) => Mention.TryFormatChannel(destination, out charsWritten, Id);

public static Channel CreateFromJson(JsonChannel jsonChannel, RestClient client)
{
return jsonChannel.Type switch
{
ChannelType.TextGuildChannel => new TextGuildChannel(jsonChannel, jsonChannel.GuildId.GetValueOrDefault(), client),
ChannelType.DMChannel => new DMChannel(jsonChannel, client),
ChannelType.VoiceGuildChannel => new VoiceGuildChannel(jsonChannel, jsonChannel.GuildId.GetValueOrDefault(), client),
ChannelType.GroupDMChannel => new GroupDMChannel(jsonChannel, client),
ChannelType.CategoryChannel => new CategoryGuildChannel(jsonChannel, jsonChannel.GuildId.GetValueOrDefault(), client),
ChannelType.AnnouncementGuildChannel => new AnnouncementGuildChannel(jsonChannel, jsonChannel.GuildId.GetValueOrDefault(), client),
ChannelType.AnnouncementGuildThread => new AnnouncementGuildThread(jsonChannel, client),
ChannelType.PublicGuildThread => new PublicGuildThread(jsonChannel, client),
ChannelType.PrivateGuildThread => new PrivateGuildThread(jsonChannel, client),
ChannelType.StageGuildChannel => new StageGuildChannel(jsonChannel, jsonChannel.GuildId.GetValueOrDefault(), client),
ChannelType.DirectoryGuildChannel => new DirectoryGuildChannel(jsonChannel, jsonChannel.GuildId.GetValueOrDefault(), client),
ChannelType.ForumGuildChannel => new ForumGuildChannel(jsonChannel, jsonChannel.GuildId.GetValueOrDefault(), client),
ChannelType.MediaForumGuildChannel => new MediaForumGuildChannel(jsonChannel, jsonChannel.GuildId.GetValueOrDefault(), client),
_ => new UnknownChannel(jsonChannel, client),
};
}
}
Loading