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

System Channel Id ("Welcome new members channel") support, fix #815 #819

Merged
merged 1 commit into from Sep 23, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Discord.Net.Core/Entities/Guilds/GuildProperties.cs
Expand Up @@ -60,6 +60,14 @@ public class GuildProperties
/// </summary>
public Optional<ulong?> AfkChannelId { get; set; }
/// <summary>
/// The ITextChannel where System messages should be sent.
/// </summary>
public Optional<ITextChannel> SystemChannel { get; set; }
/// <summary>
/// The ID of the ITextChannel where System messages should be sent.
/// </summary>
public Optional<ulong?> SystemChannelId { get; set; }
/// <summary>
/// The owner of this guild.
/// </summary>
public Optional<IUser> Owner { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions src/Discord.Net.Core/Entities/Guilds/IGuild.cs
Expand Up @@ -36,6 +36,8 @@ public interface IGuild : IDeletable, ISnowflakeEntity
ulong DefaultChannelId { get; }
/// <summary> Gets the id of the embed channel for this guild if set, or null if not. </summary>
ulong? EmbedChannelId { get; }
/// <summary> Gets the id of the channel where randomized welcome messages are sent, or null if not. </summary>
ulong? SystemChannelId { get; }
/// <summary> Gets the id of the user that created this guild. </summary>
ulong OwnerId { get; }
/// <summary> Gets the id of the region hosting this guild's voice channels. </summary>
Expand Down Expand Up @@ -84,6 +86,7 @@ public interface IGuild : IDeletable, ISnowflakeEntity
Task<IReadOnlyCollection<IVoiceChannel>> GetVoiceChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
Task<IVoiceChannel> GetVoiceChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
Task<IVoiceChannel> GetAFKChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
Task<ITextChannel> GetSystemChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
Task<ITextChannel> GetDefaultChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
Task<IGuildChannel> GetEmbedChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
/// <summary> Creates a new text channel. </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Discord.Net.Rest/API/Common/Guild.cs
Expand Up @@ -25,6 +25,8 @@ internal class Guild
public bool EmbedEnabled { get; set; }
[JsonProperty("embed_channel_id")]
public ulong? EmbedChannelId { get; set; }
[JsonProperty("system_channel_id")]
public ulong? SystemChannelId { get; set; }
[JsonProperty("verification_level")]
public VerificationLevel VerificationLevel { get; set; }
[JsonProperty("voice_states")]
Expand Down
2 changes: 2 additions & 0 deletions src/Discord.Net.Rest/API/Rest/ModifyGuildParams.cs
Expand Up @@ -18,6 +18,8 @@ internal class ModifyGuildParams
public Optional<DefaultMessageNotifications> DefaultMessageNotifications { get; set; }
[JsonProperty("afk_timeout")]
public Optional<int> AfkTimeout { get; set; }
[JsonProperty("system_channel_id")]
public Optional<ulong?> SystemChannelId { get; set; }
[JsonProperty("icon")]
public Optional<Image?> Icon { get; set; }
[JsonProperty("splash")]
Expand Down
6 changes: 6 additions & 0 deletions src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
Expand Up @@ -26,6 +26,7 @@ internal static class GuildHelper
{
AfkChannelId = args.AfkChannelId,
AfkTimeout = args.AfkTimeout,
SystemChannelId = args.SystemChannelId,
DefaultMessageNotifications = args.DefaultMessageNotifications,
Icon = args.Icon.IsSpecified ? args.Icon.Value?.ToModel() : Optional.Create<ImageModel?>(),
Name = args.Name,
Expand All @@ -39,6 +40,11 @@ internal static class GuildHelper
else if (args.AfkChannelId.IsSpecified)
apiArgs.AfkChannelId = args.AfkChannelId.Value;

if (args.SystemChannel.IsSpecified)
apiArgs.SystemChannelId = args.SystemChannel.Value.Id;
else if (args.SystemChannelId.IsSpecified)
apiArgs.SystemChannelId = args.SystemChannelId.Value;

if (args.Owner.IsSpecified)
apiArgs.OwnerId = args.Owner.Value.Id;
else if (args.OwnerId.IsSpecified)
Expand Down
19 changes: 19 additions & 0 deletions src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
Expand Up @@ -26,6 +26,7 @@ public class RestGuild : RestEntity<ulong>, IGuild, IUpdateable

public ulong? AFKChannelId { get; private set; }
public ulong? EmbedChannelId { get; private set; }
public ulong? SystemChannelId { get; private set; }
public ulong OwnerId { get; private set; }
public string VoiceRegionId { get; private set; }
public string IconId { get; private set; }
Expand Down Expand Up @@ -58,6 +59,7 @@ internal void Update(Model model)
{
AFKChannelId = model.AFKChannelId;
EmbedChannelId = model.EmbedChannelId;
SystemChannelId = model.SystemChannelId;
AFKTimeout = model.AFKTimeout;
IsEmbeddable = model.EmbedEnabled;
IconId = model.Icon;
Expand Down Expand Up @@ -201,6 +203,16 @@ public async Task<RestGuildChannel> GetEmbedChannelAsync(RequestOptions options
return await GuildHelper.GetChannelAsync(this, Discord, embedId.Value, options).ConfigureAwait(false);
return null;
}
public async Task<RestTextChannel> GetSystemChannelAsync(RequestOptions options = null)
{
var systemId = SystemChannelId;
if (systemId.HasValue)
{
var channel = await GuildHelper.GetChannelAsync(this, Discord, systemId.Value, options).ConfigureAwait(false);
return channel as RestTextChannel;
}
return null;
}
public Task<RestTextChannel> CreateTextChannelAsync(string name, RequestOptions options = null)
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options);
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null)
Expand Down Expand Up @@ -320,6 +332,13 @@ async Task<IGuildChannel> IGuild.GetEmbedChannelAsync(CacheMode mode, RequestOpt
else
return null;
}
async Task<ITextChannel> IGuild.GetSystemChannelAsync(CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return await GetSystemChannelAsync(options).ConfigureAwait(false);
else
return null;
}
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, RequestOptions options)
=> await CreateTextChannelAsync(name, options).ConfigureAwait(false);
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, RequestOptions options)
Expand Down
13 changes: 13 additions & 0 deletions src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs
Expand Up @@ -47,6 +47,7 @@ public class SocketGuild : SocketEntity<ulong>, IGuild

internal ulong? AFKChannelId { get; private set; }
internal ulong? EmbedChannelId { get; private set; }
internal ulong? SystemChannelId { get; private set; }
public ulong OwnerId { get; private set; }
public SocketGuildUser Owner => GetUser(OwnerId);
public string VoiceRegionId { get; private set; }
Expand Down Expand Up @@ -81,6 +82,14 @@ public SocketGuildChannel EmbedChannel
return id.HasValue ? GetChannel(id.Value) : null;
}
}
public SocketTextChannel SystemChannel
{
get
{
var id = SystemChannelId;
return id.HasValue ? GetTextChannel(id.Value) : null;
}
}
public IReadOnlyCollection<SocketTextChannel> TextChannels
=> Channels.Select(x => x as SocketTextChannel).Where(x => x != null).ToImmutableArray();
public IReadOnlyCollection<SocketVoiceChannel> VoiceChannels
Expand Down Expand Up @@ -191,6 +200,7 @@ internal void Update(ClientState state, Model model)
{
AFKChannelId = model.AFKChannelId;
EmbedChannelId = model.EmbedChannelId;
SystemChannelId = model.SystemChannelId;
AFKTimeout = model.AFKTimeout;
IsEmbeddable = model.EmbedEnabled;
IconId = model.Icon;
Expand Down Expand Up @@ -607,6 +617,7 @@ internal async Task RepopulateAudioStreamsAsync()
bool IGuild.Available => true;
ulong IGuild.DefaultChannelId => DefaultChannel?.Id ?? 0;
ulong? IGuild.EmbedChannelId => EmbedChannelId;
ulong? IGuild.SystemChannelId => SystemChannelId;
IRole IGuild.EveryoneRole => EveryoneRole;
IReadOnlyCollection<IRole> IGuild.Roles => Roles;

Expand All @@ -631,6 +642,8 @@ Task<ITextChannel> IGuild.GetDefaultChannelAsync(CacheMode mode, RequestOptions
=> Task.FromResult<ITextChannel>(DefaultChannel);
Task<IGuildChannel> IGuild.GetEmbedChannelAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult<IGuildChannel>(EmbedChannel);
Task<ITextChannel> IGuild.GetSystemChannelAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult<ITextChannel>(SystemChannel);
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, RequestOptions options)
=> await CreateTextChannelAsync(name, options).ConfigureAwait(false);
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, RequestOptions options)
Expand Down