@@ -2,12 +2,14 @@ | |||||
{ | { | ||||
internal static class CDN | internal static class CDN | ||||
{ | { | ||||
public static string GetApplicationIconUrl(ulong appId, string iconId) | |||||
=> iconId != null ? $"{DiscordConfig.ClientAPIUrl}app-icons/{appId}/{iconId}.jpg" : null; | |||||
public static string GetUserAvatarUrl(ulong userId, string avatarId) | public static string GetUserAvatarUrl(ulong userId, string avatarId) | ||||
=> avatarId != null ? $"{DiscordConfig.ClientAPIUrl}users/{userId}/avatars/{avatarId}.jpg" : null; | |||||
=> avatarId != null ? $"{DiscordConfig.ClientAPIUrl}avatars/{userId}/{avatarId}.jpg" : null; | |||||
public static string GetGuildIconUrl(ulong guildId, string iconId) | public static string GetGuildIconUrl(ulong guildId, string iconId) | ||||
=> iconId != null ? $"{DiscordConfig.ClientAPIUrl}guilds/{guildId}/icons/{iconId}.jpg" : null; | |||||
=> iconId != null ? $"{DiscordConfig.ClientAPIUrl}icons/{guildId}/{iconId}.jpg" : null; | |||||
public static string GetGuildSplashUrl(ulong guildId, string splashId) | public static string GetGuildSplashUrl(ulong guildId, string splashId) | ||||
=> splashId != null ? $"{DiscordConfig.ClientAPIUrl}guilds/{guildId}/splashes/{splashId}.jpg" : null; | |||||
=> splashId != null ? $"{DiscordConfig.ClientAPIUrl}splashes/{guildId}/{splashId}.jpg" : null; | |||||
public static string GetChannelIconUrl(ulong channelId, string iconId) | public static string GetChannelIconUrl(ulong channelId, string iconId) | ||||
=> iconId != null ? $"{DiscordConfig.ClientAPIUrl}channel-icons/{channelId}/{iconId}.jpg" : null; | => iconId != null ? $"{DiscordConfig.ClientAPIUrl}channel-icons/{channelId}/{iconId}.jpg" : null; | ||||
} | } | ||||
@@ -0,0 +1,22 @@ | |||||
using Newtonsoft.Json; | |||||
namespace Discord.API | |||||
{ | |||||
public class Application | |||||
{ | |||||
[JsonProperty("description")] | |||||
public string Description { get; set; } | |||||
[JsonProperty("rpc_origins")] | |||||
public string[] RPCOrigins { get; set; } | |||||
[JsonProperty("name")] | |||||
public string Name { get; set; } | |||||
[JsonProperty("flags"), Int53] | |||||
public ulong Flags { get; set; } | |||||
[JsonProperty("owner")] | |||||
public User Owner { get; set; } | |||||
[JsonProperty("id")] | |||||
public ulong Id { get; set; } | |||||
[JsonProperty("icon")] | |||||
public string Icon { get; set; } | |||||
} | |||||
} |
@@ -351,6 +351,13 @@ namespace Discord.API | |||||
await _sentGatewayMessageEvent.InvokeAsync(opCode).ConfigureAwait(false); | await _sentGatewayMessageEvent.InvokeAsync(opCode).ConfigureAwait(false); | ||||
} | } | ||||
//Application | |||||
public async Task<Application> GetMyApplicationInfoAsync(RequestOptions options = null) | |||||
{ | |||||
return await SendAsync<Application>("GET", "oauth2/applications/@me", options: options).ConfigureAwait(false); | |||||
} | |||||
//Auth | //Auth | ||||
public async Task ValidateTokenAsync(RequestOptions options = null) | public async Task ValidateTokenAsync(RequestOptions options = null) | ||||
{ | { | ||||
@@ -0,0 +1,11 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.API.Rest | |||||
{ | |||||
public class ApplicationInfo | |||||
{ | |||||
} | |||||
} |
@@ -145,12 +145,12 @@ namespace Discord | |||||
protected virtual Task OnLogoutAsync() => Task.CompletedTask; | protected virtual Task OnLogoutAsync() => Task.CompletedTask; | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public async Task<IReadOnlyCollection<IConnection>> GetConnectionsAsync() | |||||
public async Task<IApplication> GetApplicationInfoAsync() | |||||
{ | { | ||||
var models = await ApiClient.GetMyConnectionsAsync().ConfigureAwait(false); | |||||
return models.Select(x => new Connection(x)).ToImmutableArray(); | |||||
var model = await ApiClient.GetMyApplicationInfoAsync().ConfigureAwait(false); | |||||
return new Application(this, model); | |||||
} | } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public virtual async Task<IChannel> GetChannelAsync(ulong id) | public virtual async Task<IChannel> GetChannelAsync(ulong id) | ||||
{ | { | ||||
@@ -185,6 +185,13 @@ namespace Discord | |||||
var models = await ApiClient.GetMyPrivateChannelsAsync().ConfigureAwait(false); | var models = await ApiClient.GetMyPrivateChannelsAsync().ConfigureAwait(false); | ||||
return models.Select(x => new DMChannel(this, new User(x.Recipients.Value[0]), x)).ToImmutableArray(); | return models.Select(x => new DMChannel(this, new User(x.Recipients.Value[0]), x)).ToImmutableArray(); | ||||
} | } | ||||
/// <inheritdoc /> | |||||
public async Task<IReadOnlyCollection<IConnection>> GetConnectionsAsync() | |||||
{ | |||||
var models = await ApiClient.GetMyConnectionsAsync().ConfigureAwait(false); | |||||
return models.Select(x => new Connection(x)).ToImmutableArray(); | |||||
} | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public virtual async Task<IInvite> GetInviteAsync(string inviteIdOrXkcd) | public virtual async Task<IInvite> GetInviteAsync(string inviteIdOrXkcd) | ||||
@@ -0,0 +1,51 @@ | |||||
using System; | |||||
using System.Threading.Tasks; | |||||
using Model = Discord.API.Application; | |||||
namespace Discord | |||||
{ | |||||
internal class Application : SnowflakeEntity, IApplication | |||||
{ | |||||
protected string _iconId; | |||||
public string Name { get; private set; } | |||||
public string Description { get; private set; } | |||||
public string[] RPCOrigins { get; private set; } | |||||
public ulong Flags { get; private set; } | |||||
public override DiscordClient Discord { get; } | |||||
public IUser Owner { get; private set; } | |||||
public string IconUrl => API.CDN.GetApplicationIconUrl(Id, _iconId); | |||||
public Application(DiscordClient discord, Model model) | |||||
: base(model.Id) | |||||
{ | |||||
Discord = discord; | |||||
Update(model, UpdateSource.Creation); | |||||
} | |||||
internal void Update(Model model, UpdateSource source) | |||||
{ | |||||
if (source == UpdateSource.Rest && IsAttached) return; | |||||
Description = model.Description; | |||||
RPCOrigins = model.RPCOrigins; | |||||
Name = model.Name; | |||||
Flags = model.Flags; | |||||
Owner = new User(model.Owner); | |||||
_iconId = model.Icon; | |||||
} | |||||
public async Task UpdateAsync() | |||||
{ | |||||
if (IsAttached) throw new NotSupportedException(); | |||||
var response = await Discord.ApiClient.GetMyApplicationInfoAsync().ConfigureAwait(false); | |||||
if (response.Id != Id) | |||||
throw new InvalidOperationException("Unable to update this object from a different application token."); | |||||
Update(response, UpdateSource.Rest); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,13 @@ | |||||
namespace Discord | |||||
{ | |||||
public interface IApplication : ISnowflakeEntity, IUpdateable | |||||
{ | |||||
string Name { get; } | |||||
string Description { get; } | |||||
string[] RPCOrigins { get; } | |||||
ulong Flags { get; } | |||||
string IconUrl { get; } | |||||
IUser Owner { get; } | |||||
} | |||||
} |
@@ -23,6 +23,8 @@ namespace Discord | |||||
Task ConnectAsync(); | Task ConnectAsync(); | ||||
Task DisconnectAsync(); | Task DisconnectAsync(); | ||||
Task<IApplication> GetApplicationInfoAsync(); | |||||
Task<IChannel> GetChannelAsync(ulong id); | Task<IChannel> GetChannelAsync(ulong id); | ||||
Task<IReadOnlyCollection<IPrivateChannel>> GetPrivateChannelsAsync(); | Task<IReadOnlyCollection<IPrivateChannel>> GetPrivateChannelsAsync(); | ||||