Browse Source

Minor edit to socket client, finished rest implementation

pull/369/head
ObsidianMinor 8 years ago
parent
commit
f84172e30a
5 changed files with 48 additions and 15 deletions
  1. +6
    -0
      src/Discord.Net.Rest/ClientHelper.cs
  2. +3
    -0
      src/Discord.Net.Rest/DiscordRestClient.cs
  3. +26
    -0
      src/Discord.Net.Rest/Entities/Users/RestRelationship.cs
  4. +7
    -15
      src/Discord.Net.Rest/Entities/Users/RestUser.cs
  5. +6
    -0
      src/Discord.Net.WebSocket/DiscordSocketClient.cs

+ 6
- 0
src/Discord.Net.Rest/ClientHelper.cs View File

@@ -128,5 +128,11 @@ namespace Discord.Rest
var models = await client.ApiClient.GetVoiceRegionsAsync().ConfigureAwait(false); var models = await client.ApiClient.GetVoiceRegionsAsync().ConfigureAwait(false);
return models.Select(x => RestVoiceRegion.Create(client, x)).Where(x => x.Id == id).FirstOrDefault(); return models.Select(x => RestVoiceRegion.Create(client, x)).Where(x => x.Id == id).FirstOrDefault();
} }

public static async Task<IReadOnlyCollection<RestRelationship>> GetRelationshipsAsync(BaseDiscordClient client)
{
var models = await client.ApiClient.GetRelationshipsAsync().ConfigureAwait(false);
return models.Select(r => RestRelationship.Create(client, r)).ToImmutableArray();
}
} }
} }

+ 3
- 0
src/Discord.Net.Rest/DiscordRestClient.cs View File

@@ -89,6 +89,9 @@ namespace Discord.Rest
public Task<RestVoiceRegion> GetVoiceRegionAsync(string id) public Task<RestVoiceRegion> GetVoiceRegionAsync(string id)
=> ClientHelper.GetVoiceRegionAsync(this, id); => ClientHelper.GetVoiceRegionAsync(this, id);


public Task<IReadOnlyCollection<RestRelationship>> GetRelationshipsAsync()
=> ClientHelper.GetRelationshipsAsync(this);

//IDiscordClient //IDiscordClient
async Task<IApplication> IDiscordClient.GetApplicationInfoAsync() async Task<IApplication> IDiscordClient.GetApplicationInfoAsync()
=> await GetApplicationInfoAsync().ConfigureAwait(false); => await GetApplicationInfoAsync().ConfigureAwait(false);


+ 26
- 0
src/Discord.Net.Rest/Entities/Users/RestRelationship.cs View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
using Model = Discord.API.Relationship;

namespace Discord.Rest
{
public class RestRelationship : IRelationship
{
public RelationshipType Type { get; internal set; }

public IUser User { get; internal set; }

internal RestRelationship(RelationshipType type, IUser user)
{
Type = type;
User = user;
}

internal static RestRelationship Create(BaseDiscordClient discord, Model model)
{
RestUser user = RestUser.Create(discord, model.User);
return new RestRelationship(model.Type, user);
}
}
}

+ 7
- 15
src/Discord.Net.Rest/Entities/Users/RestUser.cs View File

@@ -53,26 +53,18 @@ namespace Discord.Rest


public override string ToString() => $"{Username}#{Discriminator}"; public override string ToString() => $"{Username}#{Discriminator}";
private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})"; private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})";
public Task AddFriendAsync(RequestOptions options = null)
=> Discord.ApiClient.AddFriendAsync(Id, options);
public Task BlockUserAsync(RequestOptions options = null)
=> Discord.ApiClient.BlockUserAsync(Id, options);
public Task RemoveRelationshipAsync(RequestOptions options = null)
=> Discord.ApiClient.RemoveRelationshipAsync(Id, options);


//IUser //IUser
Task<IDMChannel> IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options) Task<IDMChannel> IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult<IDMChannel>(null); => Task.FromResult<IDMChannel>(null);
async Task<IDMChannel> IUser.CreateDMChannelAsync(RequestOptions options) async Task<IDMChannel> IUser.CreateDMChannelAsync(RequestOptions options)
=> await CreateDMChannelAsync(options).ConfigureAwait(false); => await CreateDMChannelAsync(options).ConfigureAwait(false);

public Task AddFriendAsync(RequestOptions options = null)
{
throw new NotImplementedException();
}

public Task BlockUserAsync(RequestOptions options = null)
{
throw new NotImplementedException();
}

public Task RemoveRelationshipAsync(RequestOptions options = null)
{
throw new NotImplementedException();
}
} }
} }

+ 6
- 0
src/Discord.Net.WebSocket/DiscordSocketClient.cs View File

@@ -272,6 +272,9 @@ namespace Discord.WebSocket
public Task<RestInvite> GetInviteAsync(string inviteId) public Task<RestInvite> GetInviteAsync(string inviteId)
=> ClientHelper.GetInviteAsync(this, inviteId); => ClientHelper.GetInviteAsync(this, inviteId);
public Task<IReadOnlyCollection<SocketRelationship>> GetRelationshipsAsync()
=> Task.FromResult(State.Relationships);

/// <inheritdoc /> /// <inheritdoc />
public SocketUser GetUser(ulong id) public SocketUser GetUser(ulong id)
{ {
@@ -1730,5 +1733,8 @@ namespace Discord.WebSocket
=> await StartAsync().ConfigureAwait(false); => await StartAsync().ConfigureAwait(false);
async Task IDiscordClient.StopAsync() async Task IDiscordClient.StopAsync()
=> await StopAsync().ConfigureAwait(false); => await StopAsync().ConfigureAwait(false);

async Task<IReadOnlyCollection<IRelationship>> IDiscordClient.GetRelationshipsAsync()
=> await GetRelationshipsAsync();
} }
} }

Loading…
Cancel
Save