[Feature] Guild Onboarding support (#2616)
* api models * moar models * complete models * modelsss * forgot to push * oh lol forgot this too * api & rest guild method * revert VS being VS & formatting to file scoped namespace * socket entities * yup * fix xml doc * changes
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using Model = Discord.API.GuildOnboarding;
|
||||
|
||||
namespace Discord.WebSocket;
|
||||
|
||||
/// <inheritdoc />
|
||||
public class SocketGuildOnboarding : IGuildOnboarding
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public ulong GuildId { get; private set; }
|
||||
|
||||
/// <inheritdoc cref="IGuildOnboarding.Guild"/>
|
||||
public SocketGuild Guild { get; private set; }
|
||||
|
||||
/// <inheritdoc cref="IGuildOnboarding.Prompts"/>
|
||||
public IReadOnlyCollection<SocketGuildOnboardingPrompt> Prompts { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<ulong> DefaultChannelIds { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets channels members get opted in automatically.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<SocketGuildChannel> DefaultChannels { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsEnabled { get; private set; }
|
||||
|
||||
internal SocketGuildOnboarding(DiscordSocketClient discord, Model model, SocketGuild guild)
|
||||
{
|
||||
GuildId = model.GuildId;
|
||||
Guild = guild;
|
||||
IsEnabled = model.Enabled;
|
||||
|
||||
DefaultChannelIds = model.DefaultChannelIds;
|
||||
|
||||
DefaultChannels = model.DefaultChannelIds.Select(guild.GetChannel).ToImmutableArray();
|
||||
Prompts = model.Prompts.Select(x => new SocketGuildOnboardingPrompt(discord, x.Id, x, guild)).ToImmutableArray();
|
||||
|
||||
}
|
||||
|
||||
#region IGuildOnboarding
|
||||
|
||||
/// <inheritdoc />
|
||||
IGuild IGuildOnboarding.Guild => Guild;
|
||||
|
||||
/// <inheritdoc />
|
||||
IReadOnlyCollection<IGuildOnboardingPrompt> IGuildOnboarding.Prompts => Prompts;
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
|
||||
using Model = Discord.API.GuildOnboardingPrompt;
|
||||
|
||||
namespace Discord.WebSocket;
|
||||
|
||||
|
||||
/// <inheritdoc cref="IGuildOnboardingPrompt"/>
|
||||
public class SocketGuildOnboardingPrompt : SocketEntity<ulong>, IGuildOnboardingPrompt
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||
|
||||
/// <inheritdoc cref="IGuildOnboardingPrompt.Options"/>
|
||||
public IReadOnlyCollection<SocketGuildOnboardingPromptOption> Options { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Title { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsSingleSelect { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsRequired { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsInOnboarding { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public GuildOnboardingPromptType Type { get; private set; }
|
||||
|
||||
internal SocketGuildOnboardingPrompt(DiscordSocketClient discord, ulong id, Model model, SocketGuild guild) : base(discord, id)
|
||||
{
|
||||
Title = model.Title;
|
||||
IsSingleSelect = model.IsSingleSelect;
|
||||
IsInOnboarding = model.IsInOnboarding;
|
||||
IsRequired = model.IsRequired;
|
||||
Type = model.Type;
|
||||
|
||||
Options = model.Options.Select(option => new SocketGuildOnboardingPromptOption(discord, option.Id, option, guild)).ToImmutableArray();
|
||||
}
|
||||
|
||||
#region IGuildOnboardingPrompt
|
||||
|
||||
/// <inheritdoc />
|
||||
IReadOnlyCollection<IGuildOnboardingPromptOption> IGuildOnboardingPrompt.Options => Options;
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
|
||||
using Model = Discord.API.GuildOnboardingPromptOption;
|
||||
|
||||
namespace Discord.WebSocket;
|
||||
|
||||
/// <inheritdoc cref="IGuildOnboardingPromptOption"/>
|
||||
public class SocketGuildOnboardingPromptOption : SocketEntity<ulong>, IGuildOnboardingPromptOption
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<ulong> ChannelIds { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets channels a member is added to when the option is selected.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<SocketGuildChannel> Channels { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<ulong> RoleIds { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets roles assigned to a member when the option is selected.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<SocketRole> Roles { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEmote Emoji { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Title { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Description { get; private set; }
|
||||
|
||||
internal SocketGuildOnboardingPromptOption(DiscordSocketClient discord, ulong id, Model model, SocketGuild guild) : base(discord, id)
|
||||
{
|
||||
ChannelIds = model.ChannelIds.ToImmutableArray();
|
||||
RoleIds = model.RoleIds.ToImmutableArray();
|
||||
Title = model.Title;
|
||||
Description = model.Description.IsSpecified ? model.Description.Value : null;
|
||||
|
||||
if (model.Emoji.Id.HasValue)
|
||||
{
|
||||
Emoji = new Emote(model.Emoji.Id.Value, model.Emoji.Name, model.Emoji.Animated ?? false);
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(model.Emoji.Name))
|
||||
{
|
||||
Emoji = new Emoji(model.Emoji.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
Emoji = null;
|
||||
}
|
||||
|
||||
Roles = model.RoleIds.Select(guild.GetRole).ToImmutableArray();
|
||||
Channels = model.ChannelIds.Select(guild.GetChannel).ToImmutableArray();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using Discord.API.Gateway;
|
||||
using Discord.Audio;
|
||||
using Discord.Rest;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
@@ -11,6 +12,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using AutoModRuleModel = Discord.API.AutoModerationRule;
|
||||
using ChannelModel = Discord.API.Channel;
|
||||
using EmojiUpdateModel = Discord.API.Gateway.GuildEmojiUpdateEvent;
|
||||
@@ -1908,6 +1910,18 @@ namespace Discord.WebSocket
|
||||
|
||||
#endregion
|
||||
|
||||
#region Onboarding
|
||||
|
||||
/// <inheritdoc cref="IGuild.GetOnboardingAsync"/>
|
||||
public async Task<SocketGuildOnboarding> GetOnboardingAsync(RequestOptions options = null)
|
||||
{
|
||||
var model = await GuildHelper.GetGuildOnboardingAsync(this, Discord, options);
|
||||
|
||||
return new SocketGuildOnboarding(Discord, model, this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IGuild
|
||||
/// <inheritdoc />
|
||||
ulong? IGuild.AFKChannelId => AFKChannelId;
|
||||
@@ -2166,6 +2180,10 @@ namespace Discord.WebSocket
|
||||
async Task<IAutoModRule> IGuild.CreateAutoModRuleAsync(Action<AutoModRuleProperties> props, RequestOptions options)
|
||||
=> await CreateAutoModRuleAsync(props, options).ConfigureAwait(false);
|
||||
|
||||
/// <inheritdoc/>
|
||||
async Task<IGuildOnboarding> IGuild.GetOnboardingAsync(RequestOptions options)
|
||||
=> await GetOnboardingAsync(options);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user