Skip to content

Commit

Permalink
Add fields for nitro boosts... \n(why not expose who's nitro haha dis…
Browse files Browse the repository at this point in the history
…cord amirite >:0 )
  • Loading branch information
Naamloos committed Jun 5, 2019
1 parent 30fa2e5 commit 44a862c
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 0 deletions.
12 changes: 12 additions & 0 deletions DSharpPlus.Test/TestBotCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 21,18 @@ public class TestBotCommands : BaseCommandModule

private ulong testMsgId = 0;

[Command("boost")]
public async Task BoostAsync(CommandContext ctx)
{
await ctx.RespondAsync($"Tier: {ctx.Guild.PremiumTier.ToString()}, Boosters: {ctx.Guild.PremiumSubscriptionCount}");
}

[Command("boost")]
public async Task BoostAsync(CommandContext ctx, DiscordMember mbr)
{
await ctx.RespondAsync($"Boosting since: {mbr.PremiumSince?.ToString() ?? "Not boosting"}");
}

[Command("test1")]
public async Task Test1Async(CommandContext ctx)
{
Expand Down
5 changes: 5 additions & 0 deletions DSharpPlus/DiscordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 1137,8 @@ internal async Task OnGuildCreateEventAsync(DiscordGuild guild, JArray rawMember
guild.IsLarge = eventGuild.IsLarge;
guild.MemberCount = Math.Max(eventGuild.MemberCount, guild._members.Count);
guild.IsUnavailable = eventGuild.IsUnavailable;
guild.PremiumSubscriptionCount = eventGuild.PremiumSubscriptionCount;
guild.PremiumTier = eventGuild.PremiumTier;
foreach (var kvp in eventGuild._voiceStates) guild._voiceStates[kvp.Key] = kvp.Value;

foreach (var xc in guild._channels.Values)
Expand Down Expand Up @@ -2383,6 2385,7 @@ internal void UpdateCachedGuild(DiscordGuild newGuild, JArray rawMembers)
old.Username = xu.Username;
old.Discriminator = xu.Discriminator;
old.AvatarHash = xu.AvatarHash;
old.PremiumType = xu.PremiumType;
return old;
});

Expand Down Expand Up @@ -2412,6 2415,8 @@ internal void UpdateCachedGuild(DiscordGuild newGuild, JArray rawMembers)
guild.SplashHash = newGuild.SplashHash;
guild.VerificationLevel = newGuild.VerificationLevel;
guild.ExplicitContentFilter = newGuild.ExplicitContentFilter;
guild.PremiumTier = newGuild.PremiumTier;
guild.PremiumSubscriptionCount = newGuild.PremiumSubscriptionCount;

// fields not sent for update:
// - guild.Channels
Expand Down
31 changes: 31 additions & 0 deletions DSharpPlus/Entities/DiscordGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 264,37 @@ public DiscordRole EveryoneRole
public bool IsOwner
=> this.OwnerId == this.Discord.CurrentUser.Id;

/// <summary>
/// Gets vanity URL code for this guild, when applicable.
/// </summary>
[JsonProperty("vanity_url_code")]
public string VanityUrlCode { get; internal set; }

/// <summary>
/// Gets guild description, when applicable.
/// </summary>
[JsonProperty("description")]
public string Description { get; internal set; }

/// <summary>
/// Gets guild banner hash, when applicable.
/// </summary>
[JsonProperty("banner")]
public string Banner { get; internal set; }

/// <summary>
/// Gets this guild's premium tier (Nitro boosting).
/// </summary>
[JsonProperty("premium_tier")]
public PremiumTier PremiumTier { get; internal set; }

/// <summary>
/// Gets the amount of members that boosted this guild.
/// </summary>
[JsonProperty("premium_subscription_count")]
public int PremiumSubscriptionCount { get; internal set; }
// Seriously discord?

// I need to work on this
//
// /// <summary>
Expand Down
7 changes: 7 additions & 0 deletions DSharpPlus/Entities/DiscordMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 37,7 @@ internal DiscordMember(TransportMember mbr)
this.IsMuted = mbr.IsMuted;
this.JoinedAt = mbr.JoinedAt;
this.Nickname = mbr.Nickname;
this.PremiumSince = mbr.PremiumSince;

this._role_ids = mbr.Roles ?? new List<ulong>();
this._role_ids_lazy = new Lazy<IReadOnlyList<ulong>>(() => new ReadOnlyCollection<ulong>(this._role_ids));
Expand Down Expand Up @@ -95,6 96,12 @@ public DiscordColor Color
[JsonProperty("joined_at", NullValueHandling = NullValueHandling.Ignore)]
public DateTimeOffset JoinedAt { get; internal set; }

/// <summary>
/// Date the user started boosting this server
/// </summary>
[JsonProperty("premium_since", NullValueHandling = NullValueHandling.Ignore)]
public DateTimeOffset? PremiumSince { get; internal set; }

/// <summary>
/// If the user is deafened
/// </summary>
Expand Down
33 changes: 33 additions & 0 deletions DSharpPlus/Enums/PremiumTier.cs
Original file line number Diff line number Diff line change
@@ -0,0 1,33 @@
namespace DSharpPlus
{
/// <summary>
/// Represents a server's premium tier.
/// </summary>
public enum PremiumTier : int
{
/// <summary>
/// Indicates that this server was not boosted.
/// </summary>
None = 0,

/// <summary>
/// Indicates that this server was boosted two times.
/// </summary>
Tier_1 = 1,

/// <summary>
/// Indicates that this server was boosted ten times.
/// </summary>
Tier_2 = 2,

/// <summary>
/// Indicates that this server was boosted fifty times.
/// </summary>
Tier_3 = 3,

/// <summary>
/// Indicates an unknown premium tier.
/// </summary>
Unknown = int.MaxValue
}
}
3 changes: 3 additions & 0 deletions DSharpPlus/Net/Abstractions/TransportMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 23,8 @@ internal class TransportMember

[JsonProperty("mute", NullValueHandling = NullValueHandling.Ignore)]
public bool IsMuted { get; internal set; }

[JsonProperty("premium_since", NullValueHandling = NullValueHandling.Ignore)]
public DateTime? PremiumSince { get; internal set; }
}
}

0 comments on commit 44a862c

Please sign in to comment.