First commit

This commit is contained in:
EnderIce2
2020-10-25 16:19:43 +02:00
parent 9d78d84acb
commit b91db81473
73 changed files with 7634 additions and 0 deletions

View File

@ -0,0 +1,23 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DiscordRPC.RPC.Payload
{
internal class ClosePayload : IPayload
{
/// <summary>
/// The close code the discord gave us
/// </summary>
[JsonProperty("code")]
public int Code { get; set; }
/// <summary>
/// The close reason discord gave us
/// </summary>
[JsonProperty("message")]
public string Reason { get; set; }
}
}

View File

@ -0,0 +1,129 @@
using DiscordRPC.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DiscordRPC.RPC.Payload
{
/// <summary>
/// The possible commands that can be sent and received by the server.
/// </summary>
internal enum Command
{
/// <summary>
/// event dispatch
/// </summary>
[EnumValue("DISPATCH")]
Dispatch,
/// <summary>
/// Called to set the activity
/// </summary>
[EnumValue("SET_ACTIVITY")]
SetActivity,
/// <summary>
/// used to subscribe to an RPC event
/// </summary>
[EnumValue("SUBSCRIBE")]
Subscribe,
/// <summary>
/// used to unsubscribe from an RPC event
/// </summary>
[EnumValue("UNSUBSCRIBE")]
Unsubscribe,
/// <summary>
/// Used to accept join requests.
/// </summary>
[EnumValue("SEND_ACTIVITY_JOIN_INVITE")]
SendActivityJoinInvite,
/// <summary>
/// Used to reject join requests.
/// </summary>
[EnumValue("CLOSE_ACTIVITY_JOIN_REQUEST")]
CloseActivityJoinRequest,
/// <summary>
/// used to authorize a new client with your app
/// </summary>
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
Authorize,
/// <summary>
/// used to authenticate an existing client with your app
/// </summary>
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
Authenticate,
/// <summary>
/// used to retrieve guild information from the client
/// </summary>
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
GetGuild,
/// <summary>
/// used to retrieve a list of guilds from the client
/// </summary>
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
GetGuilds,
/// <summary>
/// used to retrieve channel information from the client
/// </summary>
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
GetChannel,
/// <summary>
/// used to retrieve a list of channels for a guild from the client
/// </summary>
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
GetChannels,
/// <summary>
/// used to change voice settings of users in voice channels
/// </summary>
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
SetUserVoiceSettings,
/// <summary>
/// used to join or leave a voice channel, group dm, or dm
/// </summary>
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
SelectVoiceChannel,
/// <summary>
/// used to get the current voice channel the client is in
/// </summary>
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
GetSelectedVoiceChannel,
/// <summary>
/// used to join or leave a text channel, group dm, or dm
/// </summary>
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
SelectTextChannel,
/// <summary>
/// used to retrieve the client's voice settings
/// </summary>
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
GetVoiceSettings,
/// <summary>
/// used to set the client's voice settings
/// </summary>
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
SetVoiceSettings,
/// <summary>
/// used to capture a keyboard shortcut entered by the user RPC Events
/// </summary>
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
CaptureShortcut
}
}

View File

@ -0,0 +1,35 @@
using DiscordRPC.Converters;
using Newtonsoft.Json;
namespace DiscordRPC.RPC.Payload
{
/// <summary>
/// Base Payload that is received by both client and server
/// </summary>
internal abstract class IPayload
{
/// <summary>
/// The type of payload
/// </summary>
[JsonProperty("cmd"), JsonConverter(typeof(EnumSnakeCaseConverter))]
public Command Command { get; set; }
/// <summary>
/// A incremental value to help identify payloads
/// </summary>
[JsonProperty("nonce")]
public string Nonce { get; set; }
protected IPayload() { }
protected IPayload(long nonce)
{
Nonce = nonce.ToString();
}
public override string ToString()
{
return "Payload || Command: " + Command.ToString() + ", Nonce: " + (Nonce != null ? Nonce.ToString() : "NULL");
}
}
}

View File

@ -0,0 +1,53 @@
using DiscordRPC.Converters;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace DiscordRPC.RPC.Payload
{
/// <summary>
/// The payload that is sent by the client to discord for events such as setting the rich presence.
/// <para>
/// SetPrecense
/// </para>
/// </summary>
internal class ArgumentPayload : IPayload
{
/// <summary>
/// The data the server sent too us
/// </summary>
[JsonProperty("args", NullValueHandling = NullValueHandling.Ignore)]
public JObject Arguments { get; set; }
public ArgumentPayload() : base() { Arguments = null; }
public ArgumentPayload(long nonce) : base(nonce) { Arguments = null; }
public ArgumentPayload(object args, long nonce) : base(nonce)
{
SetObject(args);
}
/// <summary>
/// Sets the obejct stored within the data.
/// </summary>
/// <param name="obj"></param>
public void SetObject(object obj)
{
Arguments = JObject.FromObject(obj);
}
/// <summary>
/// Gets the object stored within the Data
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public T GetObject<T>()
{
return Arguments.ToObject<T>();
}
public override string ToString()
{
return "Argument " + base.ToString();
}
}
}

View File

@ -0,0 +1,57 @@
using DiscordRPC.Converters;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace DiscordRPC.RPC.Payload
{
/// <summary>
/// Used for Discord IPC Events
/// </summary>
internal class EventPayload : IPayload
{
/// <summary>
/// The data the server sent too us
/// </summary>
[JsonProperty("data", NullValueHandling = NullValueHandling.Ignore)]
public JObject Data { get; set; }
/// <summary>
/// The type of event the server sent
/// </summary>
[JsonProperty("evt"), JsonConverter(typeof(EnumSnakeCaseConverter))]
public ServerEvent? Event { get; set; }
/// <summary>
/// Creates a payload with empty data
/// </summary>
public EventPayload() : base() { Data = null; }
/// <summary>
/// Creates a payload with empty data and a set nonce
/// </summary>
/// <param name="nonce"></param>
public EventPayload(long nonce) : base(nonce) { Data = null; }
/// <summary>
/// Gets the object stored within the Data
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public T GetObject<T>()
{
if (Data == null) return default(T);
return Data.ToObject<T>();
}
/// <summary>
/// Converts the object into a human readable string
/// </summary>
/// <returns></returns>
public override string ToString()
{
return "Event " + base.ToString() + ", Event: " + (Event.HasValue ? Event.ToString() : "N/A");
}
}
}

View File

@ -0,0 +1,95 @@
using DiscordRPC.Converters;
using System;
using System.Runtime.Serialization;
namespace DiscordRPC.RPC.Payload
{
/// <summary>
/// See https://discordapp.com/developers/docs/topics/rpc#rpc-server-payloads-rpc-events for documentation
/// </summary>
internal enum ServerEvent
{
/// <summary>
/// Sent when the server is ready to accept messages
/// </summary>
[EnumValue("READY")]
Ready,
/// <summary>
/// Sent when something bad has happened
/// </summary>
[EnumValue("ERROR")]
Error,
/// <summary>
/// Join Event
/// </summary>
[EnumValue("ACTIVITY_JOIN")]
ActivityJoin,
/// <summary>
/// Spectate Event
/// </summary>
[EnumValue("ACTIVITY_SPECTATE")]
ActivitySpectate,
/// <summary>
/// Request Event
/// </summary>
[EnumValue("ACTIVITY_JOIN_REQUEST")]
ActivityJoinRequest,
#if INCLUDE_FULL_RPC
//Old things that are obsolete
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
[EnumValue("GUILD_STATUS")]
GuildStatus,
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
[EnumValue("GUILD_CREATE")]
GuildCreate,
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
[EnumValue("CHANNEL_CREATE")]
ChannelCreate,
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
[EnumValue("VOICE_CHANNEL_SELECT")]
VoiceChannelSelect,
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
[EnumValue("VOICE_STATE_CREATED")]
VoiceStateCreated,
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
[EnumValue("VOICE_STATE_UPDATED")]
VoiceStateUpdated,
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
[EnumValue("VOICE_STATE_DELETE")]
VoiceStateDelete,
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
[EnumValue("VOICE_SETTINGS_UPDATE")]
VoiceSettingsUpdate,
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
[EnumValue("VOICE_CONNECTION_STATUS")]
VoiceConnectionStatus,
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
[EnumValue("SPEAKING_START")]
SpeakingStart,
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
[EnumValue("SPEAKING_STOP")]
SpeakingStop,
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
[EnumValue("MESSAGE_CREATE")]
MessageCreate,
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
[EnumValue("MESSAGE_UPDATE")]
MessageUpdate,
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
[EnumValue("MESSAGE_DELETE")]
MessageDelete,
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
[EnumValue("NOTIFICATION_CREATE")]
NotificationCreate,
[Obsolete("This value is appart of the RPC API and is not supported by this library.", true)]
[EnumValue("CAPTURE_SHORTCUT_CHANGE")]
CaptureShortcutChange
#endif
}
}