From d47f9d202b4195a6d26e90e15adc378883adf952 Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Tue, 3 Jan 2017 17:49:19 -0600 Subject: [PATCH] update search to have more useful returns (#1060) --- src/client/rest/RESTMethods.js | 12 +++++++++--- src/structures/Guild.js | 4 ++-- src/structures/interface/TextBasedChannel.js | 4 ++-- src/util/TransformSearchOptions.js | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/client/rest/RESTMethods.js b/src/client/rest/RESTMethods.js index b1b51b4aa..5ecae4610 100644 --- a/src/client/rest/RESTMethods.js +++ b/src/client/rest/RESTMethods.js @@ -139,9 +139,15 @@ class RESTMethods { } const url = `${Constants.Endpoints[`${type}Search`](target.id)}?${queryString}`; - return this.rest.makeRequest('get', url, true).then(body => - body.messages.map(x => x.map(m => new Message(this.client.channels.get(m.channel_id), m, this.client))) - ); + return this.rest.makeRequest('get', url, true).then(body => { + const messages = body.messages.map(x => + x.map(m => new Message(this.client.channels.get(m.channel_id), m, this.client)) + ); + return { + totalResults: body.total_results, + messages, + }; + }); } createChannel(guild, channelName, channelType, overwrites) { diff --git a/src/structures/Guild.js b/src/structures/Guild.js index aa0f717ab..e3c50b00e 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -373,8 +373,8 @@ class Guild { * content: 'discord.js', * before: '2016-11-17' * }).then(res => { - * const hit = res[0].find(m => m.hit).content; - * console.log(`I found: **${hit}**`); + * const hit = res.messages[0].find(m => m.hit).content; + * console.log(`I found: **${hit}**, total results: ${res.totalResults}`); * }).catch(console.error); */ search(options) { diff --git a/src/structures/interface/TextBasedChannel.js b/src/structures/interface/TextBasedChannel.js index dd763d7f0..0daf8600a 100644 --- a/src/structures/interface/TextBasedChannel.js +++ b/src/structures/interface/TextBasedChannel.js @@ -224,8 +224,8 @@ class TextBasedChannel { * content: 'discord.js', * before: '2016-11-17' * }).then(res => { - * const hit = res[0].find(m => m.hit).content; - * console.log(`I found: **${hit}**`); + * const hit = res.messages[0].find(m => m.hit).content; + * console.log(`I found: **${hit}**, total results: ${res.totalResults}`); * }).catch(console.error); */ search(options) { diff --git a/src/util/TransformSearchOptions.js b/src/util/TransformSearchOptions.js index e61056aed..f3e1a6c76 100644 --- a/src/util/TransformSearchOptions.js +++ b/src/util/TransformSearchOptions.js @@ -42,7 +42,7 @@ module.exports = function TransformSearchOptions(options, client) { if (!(options.during instanceof Date)) options.during = new Date(options.during); const t = options.during.getTime() - 14200704e5; options.minID = long.fromNumber(t).shiftLeft(22).toString(); - options.maxID = long.fromNumber(t + 86400000).shift(222).toString(); + options.maxID = long.fromNumber(t + 86400000).shiftLeft(22).toString(); } if (options.channel) options.channel = client.resolver.resolveChannelID(options.channel);