Browse Source

Added RelativeDirection for DownloadMessages

tags/docs-0.9
RogueException 9 years ago
parent
commit
ce247278da
3 changed files with 12 additions and 10 deletions
  1. +2
    -2
      src/Discord.Net/API/Endpoints.cs
  2. +5
    -4
      src/Discord.Net/DiscordAPIClient.cs
  3. +5
    -4
      src/Discord.Net/DiscordClient.Messages.cs

+ 2
- 2
src/Discord.Net/API/Endpoints.cs View File

@@ -16,8 +16,8 @@
public static string ChannelInvites(string channelId) => $"channels/{channelId}/invites";
public static string ChannelMessages(string channelId) => $"channels/{channelId}/messages";
public static string ChannelMessages(string channelId, int limit) => $"channels/{channelId}/messages?limit={limit}";
public static string ChannelMessages(string channelId, int limit, string beforeId) => $"channels/{channelId}/messages?limit={limit}&before={beforeId}";
public static string ChannelMessage(string channelId, string msgId) => $"channels/{channelId}/messages/{msgId}";
public static string ChannelMessages(string channelId, int limit, string relativeId, string relativeDir) => $"channels/{channelId}/messages?limit={limit}&{relativeDir}={relativeId}";
public static string ChannelMessage(string channelId, string msgId) => $"channels/{channelId}/messages/{msgId}";
public static string ChannelMessageAck(string channelId, string msgId) => $"channels/{channelId}/messages/{msgId}/ack";
public static string ChannelPermission(string channelId, string userOrRoleId) => $"channels/{channelId}/permissions/{userOrRoleId}";
public static string ChannelTyping(string channelId) => $"channels/{channelId}/typing";


+ 5
- 4
src/Discord.Net/DiscordAPIClient.cs View File

@@ -1,5 +1,4 @@
using Discord.API;
using Discord.Net;
using Discord.Net.Rest;
using System;
using System.Collections.Generic;
@@ -9,6 +8,8 @@ using System.Threading.Tasks;

namespace Discord
{
public enum RelativeDirection { Before, After }

/// <summary> A lightweight wrapper around the Discord API. </summary>
public class DiscordAPIClient
{
@@ -92,12 +93,12 @@ namespace Discord
var request = new ReorderChannelsRequest(channels);
return _rest.Patch(Endpoints.ServerChannels(serverId), request);
}
public Task<GetMessagesResponse> GetMessages(string channelId, int count, string beforeMessageId = null)
public Task<GetMessagesResponse> GetMessages(string channelId, int count, string relativeMessageId = null, RelativeDirection relativeDir = RelativeDirection.Before)
{
if (channelId == null) throw new ArgumentNullException(nameof(channelId));

if (beforeMessageId != null)
return _rest.Get<GetMessagesResponse>(Endpoints.ChannelMessages(channelId, count, beforeMessageId));
if (relativeMessageId != null)
return _rest.Get<GetMessagesResponse>(Endpoints.ChannelMessages(channelId, count, relativeMessageId, relativeDir == RelativeDirection.Before ? "before" : "after"));
else
return _rest.Get<GetMessagesResponse>(Endpoints.ChannelMessages(channelId, count));
}


+ 5
- 4
src/Discord.Net/DiscordClient.Messages.cs View File

@@ -215,8 +215,9 @@ namespace Discord
catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
}

/// <summary> Downloads last count messages from the server, starting at beforeMessageId if it's provided. </summary>
public async Task<Message[]> DownloadMessages(Channel channel, int count, string beforeMessageId = null, bool cache = true)

/// <summary> Downloads last count messages from the server, returning all messages before or after relativeMessageId, if it's provided. </summary>
public async Task<Message[]> DownloadMessages(Channel channel, int count, string relativeMessageId = null, RelativeDirection relativeDir = RelativeDirection.Before, bool cache = true)
{
if (channel == null) throw new ArgumentNullException(nameof(channel));
if (count < 0) throw new ArgumentNullException(nameof(count));
@@ -227,8 +228,8 @@ namespace Discord
{
try
{
var msgs = await _api.GetMessages(channel.Id, count, beforeMessageId).ConfigureAwait(false);
return msgs.Select(x =>
var msgs = await _api.GetMessages(channel.Id, count, relativeMessageId, relativeDir).ConfigureAwait(false);
var result = msgs.Select(x =>
{
Message msg = null;
if (cache)


Loading…
Cancel
Save