update search to have more useful returns (#1060)

This commit is contained in:
Gus Caplan
2017-01-03 17:49:19 -06:00
committed by Amish Shah
parent 7cbe81e71a
commit d47f9d202b
4 changed files with 14 additions and 8 deletions

View File

@@ -139,9 +139,15 @@ class RESTMethods {
} }
const url = `${Constants.Endpoints[`${type}Search`](target.id)}?${queryString}`; const url = `${Constants.Endpoints[`${type}Search`](target.id)}?${queryString}`;
return this.rest.makeRequest('get', url, true).then(body => 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))) 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) { createChannel(guild, channelName, channelType, overwrites) {

View File

@@ -373,8 +373,8 @@ class Guild {
* content: 'discord.js', * content: 'discord.js',
* before: '2016-11-17' * before: '2016-11-17'
* }).then(res => { * }).then(res => {
* const hit = res[0].find(m => m.hit).content; * const hit = res.messages[0].find(m => m.hit).content;
* console.log(`I found: **${hit}**`); * console.log(`I found: **${hit}**, total results: ${res.totalResults}`);
* }).catch(console.error); * }).catch(console.error);
*/ */
search(options) { search(options) {

View File

@@ -224,8 +224,8 @@ class TextBasedChannel {
* content: 'discord.js', * content: 'discord.js',
* before: '2016-11-17' * before: '2016-11-17'
* }).then(res => { * }).then(res => {
* const hit = res[0].find(m => m.hit).content; * const hit = res.messages[0].find(m => m.hit).content;
* console.log(`I found: **${hit}**`); * console.log(`I found: **${hit}**, total results: ${res.totalResults}`);
* }).catch(console.error); * }).catch(console.error);
*/ */
search(options) { search(options) {

View File

@@ -42,7 +42,7 @@ module.exports = function TransformSearchOptions(options, client) {
if (!(options.during instanceof Date)) options.during = new Date(options.during); if (!(options.during instanceof Date)) options.during = new Date(options.during);
const t = options.during.getTime() - 14200704e5; const t = options.during.getTime() - 14200704e5;
options.minID = long.fromNumber(t).shiftLeft(22).toString(); 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); if (options.channel) options.channel = client.resolver.resolveChannelID(options.channel);