Skip to content

Commit

Permalink
yippee (#3021)
Browse files Browse the repository at this point in the history
  • Loading branch information
Misha-133 authored Oct 22, 2024
1 parent dfe679c commit 8b92969
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Discord.Net.Core/Entities/Channels/IChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ namespace Discord
/// </summary>
public interface IChannel : ISnowflakeEntity
{
/// <summary>
/// Get the type of this channel.
/// </summary>
ChannelType ChannelType { get; }

/// <summary>
/// Gets the name of this channel.
/// </summary>
Expand Down
10 changes: 9 additions & 1 deletion src/Discord.Net.Rest/Entities/Channels/RestChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ namespace Discord.Rest
public class RestChannel : RestEntity<ulong>, IChannel, IUpdateable
{
#region RestChannel

/// <inheritdoc />
public ChannelType ChannelType { get; internal set; }

/// <inheritdoc />
public virtual DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);

Expand Down Expand Up @@ -68,7 +72,11 @@ internal static IRestPrivateChannel CreatePrivate(BaseDiscordClient discord, Mod
_ => throw new InvalidOperationException($"Unexpected channel type: {model.Type}"),
};
}
internal virtual void Update(Model model) { }

internal virtual void Update(Model model)
{
ChannelType = model.Type;
}

/// <inheritdoc />
public virtual Task UpdateAsync(RequestOptions options = null) => Task.Delay(0);
Expand Down
2 changes: 2 additions & 0 deletions src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ internal RestDMChannel(BaseDiscordClient discord, ulong id, ulong? recipientId)
}
internal override void Update(Model model)
{
base.Update(model);

if(model.Recipients.IsSpecified)
Recipient?.Update(model.Recipients.Value[0]);
}
Expand Down
1 change: 1 addition & 0 deletions src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ internal RestGroupChannel(BaseDiscordClient discord, ulong id)
}
internal override void Update(Model model)
{
base.Update(model);
if (model.Name.IsSpecified)
Name = model.Name.Value;
if (model.Icon.IsSpecified)
Expand Down
1 change: 1 addition & 0 deletions src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ internal static RestGuildChannel Create(BaseDiscordClient discord, IGuild guild,
}
internal override void Update(Model model)
{
base.Update(model);
Name = model.Name.Value;

if (model.Position.IsSpecified)
Expand Down
9 changes: 8 additions & 1 deletion src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ namespace Discord.WebSocket
public abstract class SocketChannel : SocketEntity<ulong>, IChannel
{
#region SocketChannel
/// <inheritdoc />
public ChannelType ChannelType { get; internal set; }

/// <summary>
/// Gets when the channel is created.
/// </summary>
Expand All @@ -38,7 +41,11 @@ internal static ISocketPrivateChannel CreatePrivate(DiscordSocketClient discord,
_ => throw new InvalidOperationException($"Unexpected channel type: {model.Type}"),
};
}
internal abstract void Update(ClientState state, Model model);

internal virtual void Update(ClientState state, Model model)
{
ChannelType = model.Type;
}
#endregion

#region User
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ internal static SocketDMChannel Create(DiscordSocketClient discord, ClientState
internal override void Update(ClientState state, Model model)
{
Recipient.Update(state, model.Recipients.Value[0]);
base.Update(state, model);
}
internal static SocketDMChannel Create(DiscordSocketClient discord, ClientState state, ulong channelId, API.User recipient)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ internal static SocketGroupChannel Create(DiscordSocketClient discord, ClientSta
}
internal override void Update(ClientState state, Model model)
{
base.Update(state, model);
if (model.Name.IsSpecified)
Name = model.Name.Value;
if (model.Icon.IsSpecified)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ internal static SocketGuildChannel Create(SocketGuild guild, ClientState state,
/// <inheritdoc />
internal override void Update(ClientState state, Model model)
{
base.Update(state, model);
Name = model.Name.Value;
Position = model.Position.GetValueOrDefault(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Discord
{
internal sealed class MockedCategoryChannel : ICategoryChannel
{
public ChannelType ChannelType => ChannelType.Category;
public int Position => throw new NotImplementedException();

public IGuild Guild => throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Discord
{
internal sealed class MockedDMChannel : IDMChannel
{
public ChannelType ChannelType => ChannelType.DM;
public IUser Recipient => throw new NotImplementedException();

public IReadOnlyCollection<IUser> Recipients => throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Discord
{
internal sealed class MockedGroupChannel : IGroupChannel
{
public ChannelType ChannelType => ChannelType.Group;
public IReadOnlyCollection<IUser> Recipients => throw new NotImplementedException();

public string Name => throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Discord
/// </summary>
internal sealed class MockedInvalidChannel : IChannel
{
public ChannelType ChannelType => ChannelType.Text;
public string Name => throw new NotImplementedException();

public DateTimeOffset CreatedAt => throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Discord
{
internal sealed class MockedTextChannel : ITextChannel
{
public ChannelType ChannelType => ChannelType.Text;
public bool IsNsfw => throw new NotImplementedException();

public int DefaultSlowModeInterval => throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace Discord
{
internal sealed class MockedVoiceChannel : IVoiceChannel
{
public ChannelType ChannelType => ChannelType.Voice;

public int DefaultSlowModeInterval => throw new NotImplementedException();

public int Bitrate => throw new NotImplementedException();
Expand Down

0 comments on commit 8b92969

Please sign in to comment.