[Feature] add missing invite guild properties & welcome screen support (#2510)
* added models * working getter for welcome screen * <see langword="null"/> * more changes * modify welcome screen support * fix some typos & remove `using` added by VS * Working-ish state * Resolve some reviews * change access modifier * forgot to add docs * revert to InviteGuild & extend it * resolve some reviews * Apply suggestions from code review Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com> Co-authored-by: Cenk Ergen <57065323+Cenngo@users.noreply.github.com> Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com>
This commit is contained in:
@@ -1251,5 +1251,21 @@ namespace Discord
|
||||
/// </returns>
|
||||
Task<IReadOnlyCollection<IApplicationCommand>> BulkOverwriteApplicationCommandsAsync(ApplicationCommandProperties[] properties,
|
||||
RequestOptions options = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the welcome screen of the guild. Returns <see langword="null"/> if the welcome channel is not set.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous creation operation. The task result contains a <see cref="WelcomeScreen"/>.
|
||||
/// </returns>
|
||||
Task<WelcomeScreen> GetWelcomeScreenAsync(RequestOptions options = null);
|
||||
|
||||
/// <summary>
|
||||
/// Modifies the welcome screen of the guild. Returns <see langword="null"/> if welcome screen is removed.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous creation operation. The task result contains a <see cref="WelcomeScreen"/>.
|
||||
/// </returns>
|
||||
Task<WelcomeScreen> ModifyWelcomeScreenAsync(bool enabled, WelcomeScreenChannelProperties[] channels, string description = null, RequestOptions options = null);
|
||||
}
|
||||
}
|
||||
|
||||
24
src/Discord.Net.Core/Entities/Guilds/WelcomeScreen.cs
Normal file
24
src/Discord.Net.Core/Entities/Guilds/WelcomeScreen.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace Discord;
|
||||
|
||||
public class WelcomeScreen
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the server description shown in the welcome screen. <see langword="null"/> if not set.
|
||||
/// </summary>
|
||||
public string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the channels shown in the welcome screen, up to 5 channels.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<WelcomeScreenChannel> Channels { get; }
|
||||
|
||||
internal WelcomeScreen(string description, IReadOnlyCollection<WelcomeScreenChannel> channels)
|
||||
{
|
||||
Description = description;
|
||||
|
||||
Channels = channels.ToImmutableArray();
|
||||
}
|
||||
}
|
||||
41
src/Discord.Net.Core/Entities/Guilds/WelcomeScreenChannel.cs
Normal file
41
src/Discord.Net.Core/Entities/Guilds/WelcomeScreenChannel.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
|
||||
namespace Discord;
|
||||
|
||||
public class WelcomeScreenChannel : ISnowflakeEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the channel's id.
|
||||
/// </summary>
|
||||
public ulong Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the description shown for the channel.
|
||||
/// </summary>
|
||||
public string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the emoji for this channel. <see cref="Emoji"/> if it is unicode emoji, <see cref="Emote"/> if it is a custom one and <see langword="null"/> if none is set.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If the emoji is <see cref="Emote"/> only the <see cref="Emote.Id"/> will be populated.
|
||||
/// Use <see cref="IGuild.GetEmoteAsync"/> to get the emoji.
|
||||
/// </remarks>
|
||||
public IEmote Emoji { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||
|
||||
internal WelcomeScreenChannel(ulong id, string description, string emojiName = null, ulong? emoteId = null)
|
||||
{
|
||||
Id = id;
|
||||
Description = description;
|
||||
|
||||
if (emoteId.HasValue && emoteId.Value != 0)
|
||||
Emoji = new Emote(emoteId.Value, emojiName, false);
|
||||
else if (emojiName != null)
|
||||
Emoji = new Emoji(emojiName);
|
||||
else
|
||||
Emoji = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Discord;
|
||||
|
||||
public class WelcomeScreenChannelProperties : ISnowflakeEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the channel's id.
|
||||
/// </summary>
|
||||
public ulong Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the description shown for the channel.
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the emoji for this channel. <see cref="Emoji"/> if it is unicode emoji, <see cref="Emote"/> if it is a custom one and <see langword="null"/> if none is set.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If the emoji is <see cref="Emote"/> only the <see cref="Emote.Id"/> will be populated.
|
||||
/// Use <see cref="IGuild.GetEmoteAsync"/> to get the emoji.
|
||||
/// </remarks>
|
||||
public IEmote Emoji { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="WelcomeScreenChannelProperties"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Id if a channel.</param>
|
||||
/// <param name="description">Description for the channel in the welcome screen.</param>
|
||||
/// <param name="emoji">The emoji for the channel in the welcome screen.</param>
|
||||
public WelcomeScreenChannelProperties(ulong id, string description, IEmote emoji = null)
|
||||
{
|
||||
Id = id;
|
||||
Description = description;
|
||||
Emoji = emoji;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="WelcomeScreenChannelProperties"/>.
|
||||
/// </summary>
|
||||
public WelcomeScreenChannelProperties() { }
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="WelcomeScreenChannelProperties"/>.
|
||||
/// </summary>
|
||||
/// <param name="channel">A welcome screen channel to modify.</param>
|
||||
/// <returns>A new instance of <see cref="WelcomeScreenChannelProperties"/>.</returns>
|
||||
public static WelcomeScreenChannelProperties FromWelcomeScreenChannel(WelcomeScreenChannel channel)
|
||||
=> new (channel.Id, channel.Description, channel.Emoji);
|
||||
}
|
||||
@@ -60,6 +60,7 @@ namespace Discord
|
||||
/// A guild object representing the guild that the invite points to.
|
||||
/// </returns>
|
||||
IGuild Guild { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of the guild this invite is linked to.
|
||||
/// </summary>
|
||||
|
||||
156
src/Discord.Net.Core/Entities/Invites/InviteGuild.cs
Normal file
156
src/Discord.Net.Core/Entities/Invites/InviteGuild.cs
Normal file
@@ -0,0 +1,156 @@
|
||||
using System;
|
||||
|
||||
namespace Discord;
|
||||
|
||||
public class InviteGuild : ISnowflakeEntity
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ulong Id { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of this guild.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A string containing the name of this guild.
|
||||
/// </returns>
|
||||
public string Name { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the description for the guild.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The description for the guild; <see langword="null" /> if none is set.
|
||||
/// </returns>
|
||||
public string Description { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of this guild's splash image.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// An identifier for the splash image; <see langword="null" /> if none is set.
|
||||
/// </returns>
|
||||
public string SplashId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the URL of this guild's splash image.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A URL pointing to the guild's splash image; <see langword="null" /> if none is set.
|
||||
/// </returns>
|
||||
public string SplashUrl => CDN.GetGuildSplashUrl(Id, SplashId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the identifier for this guilds banner image.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// An identifier for the banner image; <see langword="null" /> if none is set.
|
||||
/// </returns>
|
||||
public string BannerId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the URL of this guild's banner image.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A URL pointing to the guild's banner image; <see langword="null" /> if none is set.
|
||||
/// </returns>
|
||||
public string BannerUrl => CDN.GetGuildBannerUrl(Id, BannerId, ImageFormat.Auto);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the features for this guild.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A flags enum containing all the features for the guild.
|
||||
/// </returns>
|
||||
public GuildFeatures Features { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of this guild's icon.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// An identifier for the splash image; <see langword="null" /> if none is set.
|
||||
/// </returns>
|
||||
public string IconId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the URL of this guild's icon.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A URL pointing to the guild's icon; <see langword="null" /> if none is set.
|
||||
/// </returns>
|
||||
public string IconUrl => CDN.GetGuildIconUrl(Id, IconId);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Gets the level of requirements a user must fulfill before being allowed to post messages in this guild.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The level of requirements.
|
||||
/// </returns>
|
||||
public VerificationLevel VerificationLevel { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code for this guild's vanity invite URL.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A string containing the vanity invite code for this guild; <see langword="null" /> if none is set.
|
||||
/// </returns>
|
||||
public string VanityURLCode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of premium subscribers of this guild.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is the number of users who have boosted this guild.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// The number of premium subscribers of this guild;
|
||||
/// </returns>
|
||||
public int PremiumSubscriptionCount { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the NSFW level of this guild.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The NSFW level of this guild.
|
||||
/// </returns>
|
||||
public NsfwLevel NsfwLevel { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Welcome Screen of this guild
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The welcome screen of this guild. <see langword="null" /> if none is set.
|
||||
/// </returns>
|
||||
public WelcomeScreen WelcomeScreen { get; private set; }
|
||||
|
||||
internal InviteGuild(
|
||||
ulong id,
|
||||
string name,
|
||||
string description,
|
||||
string splashId,
|
||||
string bannerId,
|
||||
GuildFeatures features,
|
||||
string iconId,
|
||||
VerificationLevel verificationLevel,
|
||||
string vanityURLCode,
|
||||
int premiumSubscriptionCount,
|
||||
NsfwLevel nsfwLevel,
|
||||
WelcomeScreen welcomeScreen)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
Description = description;
|
||||
SplashId = splashId;
|
||||
BannerId = bannerId;
|
||||
Features = features;
|
||||
IconId = iconId;
|
||||
VerificationLevel = verificationLevel;
|
||||
VanityURLCode = vanityURLCode;
|
||||
PremiumSubscriptionCount = premiumSubscriptionCount;
|
||||
NsfwLevel = nsfwLevel;
|
||||
WelcomeScreen = welcomeScreen;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user