Skip to content

Commit

Permalink
[Feature] Update to latest API Changes
Browse files Browse the repository at this point in the history
This includes

- Server Boosting discord/discord-api-docs#960

- remove of _trace on Identify payload discord/discord-api-docs#967

- opt out for presence & typing events discord/discord-api-docs#1016
  • Loading branch information
DevYukine committed Jul 26, 2019
1 parent 69d09c7 commit f53c3f1
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 11 deletions.
11 changes: 2 additions & 9 deletions Spectacles.NET.Gateway/Shard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ private string Token
/// </summary>
private string SessionID { get; set; }

/// <summary>
/// The current Trace of this Shard.
/// </summary>
private string[] Trace { get; set; }

/// <summary>
/// The Sequence the connection closed with.
Expand Down Expand Up @@ -273,19 +269,17 @@ private void _handleMessage(string json)
{
case GatewayEvent.READY:
var readyDispatch = ((JObject) packet.Data).ToObject<ReadyDispatch>();
Trace = readyDispatch.Trace;
SessionID = readyDispatch.SessionID;
_log(LogLevel.DEBUG, $"Ready {Trace[0]} -> {Trace[1]} {readyDispatch.SessionID}");
_log(LogLevel.DEBUG, $"Ready {readyDispatch.SessionID}");
_log(LogLevel.INFO, "Shard Ready");
Identified?.Invoke(this, null);
break;
case GatewayEvent.RESUMED:
{
var resumedDispatch = ((JObject) packet.Data).ToObject<ResumedDispatch>();
Trace = resumedDispatch.Trace;
var replayed = CloseSequence - Sequence;
_log(LogLevel.DEBUG,
$"RESUMED {Trace[0]} -> {Trace[1]} {SessionID} | replayed {replayed} events.");
$"RESUMED {SessionID} | replayed {replayed} events.");
_log(LogLevel.INFO, "Shard resumed connection");
break;
}
Expand Down Expand Up @@ -325,7 +319,6 @@ private void _handleMessage(string json)
case OpCode.HELLO:
_log(LogLevel.DEBUG, $"Received HELLO packet (OP {packet.OpCode}). Initializing keep-alive...");
var helloData = ((JObject) packet.Data).ToObject<HelloPacket>();
Trace = helloData.Trace;
_startHeartbeatTimer(helloData.HeartbeatInterval);

_authenticateAsync();
Expand Down
2 changes: 2 additions & 0 deletions Spectacles.NET.Types/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public enum ChannelType
GUILD_VOICE,
GROUP_DM,
GUILD_CATEGORY,
GUILD_NEWS,
GUILD_STORE
}

/// <summary>
Expand Down
23 changes: 22 additions & 1 deletion Spectacles.NET.Types/Guild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@ public enum ExplicitContentFilterLevel {
ALL_MEMBERS
}

public enum MFALevel {
public enum MFALevel
{
NONE,
ELEVATED
}

public enum PREMIUM_TIER
{
NONE,
TIER_1,
TIER_2,
TIER_3
}

/// <summary>
/// Guilds in Discord represent an isolated collection of users and channels, and are often referred to as "servers" in the UI. <see cref="http://discordapp.com/developers/docs/resources/guild"/>
Expand Down Expand Up @@ -260,5 +269,17 @@ public class Guild
/// </summary>
[JsonProperty("banner")]
public string Banner { get; set; }

/// <summary>
/// premium tier
/// </summary>
[JsonProperty("premium_tier")]
public PREMIUM_TIER PremiumTier { get; set; }

/// <summary>
/// the total number of users currently boosting this server
/// </summary>
[JsonProperty("premium_subscription_count")]
public int? PremiumSubscriberCount { get; set; }
}
}
3 changes: 3 additions & 0 deletions Spectacles.NET.Types/GuildMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class GuildMember
[JsonProperty("joined_at")]
public string JoinedAt { get; set; }

[JsonProperty("premium_since ")]
public string PremiumSince { get; set; }

/// <summary>
/// whether the user is deafened
/// </summary>
Expand Down
6 changes: 5 additions & 1 deletion Spectacles.NET.Types/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ public enum MessageType
CHANNEL_NAME_CHANGE,
CHANNEL_ICON_CHANGE,
CHANNEL_PINNED_MESSAGE,
GUILD_MEMBER_JOIN
GUILD_MEMBER_JOIN,
USER_PREMIUM_GUILD_SUBSCRIPTION,
USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1,
USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2,
USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3
}

public enum MessageActivityType
Expand Down
6 changes: 6 additions & 0 deletions Spectacles.NET.Types/Packets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,12 @@ public class IdentifyPacket
[JsonProperty("large_threshold")]
public int LargeThreshold { get; set; }

/// <summary>
/// enables dispatching of guild subscription events (presence and typing events)
/// </summary>
[JsonProperty("guild_subscriptions")]
public bool? GuildSubscription { get; set; }

/// <summary>
/// used for Guild Sharding
/// </summary>
Expand Down
40 changes: 40 additions & 0 deletions Spectacles.NET.Types/Team.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Newtonsoft.Json;

namespace Spectacles.NET.Types
{
public enum MembershipState
{
INVITED = 1,
ACCEPTED
}

public class TeamMember
{
[JsonProperty("membership_state")]
public MembershipState MembershipState { get; set; }

[JsonProperty("permissions")]
public string[] Permissions { get; set; }

[JsonProperty("team_id")]
public string TeamID { get; set; }

[JsonProperty("user")]
public User User { get; set; }
}

public class Team
{
[JsonProperty("icon")]
public string Icon { get; set; }

[JsonProperty("id")]
public string ID { get; set; }

[JsonProperty("members")]
public TeamMember[] Members { get; set; }

[JsonProperty("owner_user_id")]
public string OwnerUserID { get; set; }
}
}

0 comments on commit f53c3f1

Please sign in to comment.