mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 17:43:30 +01:00
Internal API Request Rewrite (#1490)
* start rewrite * converted guilds * more changes * convert GuildMember * convert User and remove friend methods which kill people * convert more stuff * even more stuff * make things nicer * speed and fixes and stuff * almost finished * fix * Update Client.js * uwu * Update RESTMethods.js * message editing * fix router * fix issue with references * message delete reason * move message sending * fix dm * message splitting * NO MORE REST METHODS * Update Client.js * Update WebhookClient.js * remove all those endpoints from the constants * Update ClientUser.js * Update ClientUser.js * fixes * Update ClientUser.js * complaiancy * all sort of fixes * merge master (#1) * Fix Permissions now that member is deprecated (#1491) * removing more deprecation leftovers (#1492) * Fix MessageCollectors * Fix awaitMessages (#1493) * Fix MessageCollector#cleanup * Fix MessageCollector#postCheck * Add max option back for safety * Update Invite.js (#1496) * guild setPosition missing docs (#1498) * missing docs * update return docs * indent * switched .invites for the apirouter and invite.js * make multiple options an object * Update ClientUser.js * fix nicks * Update WebhookClient.js
This commit is contained in:
63
src/structures/shared/Search.js
Normal file
63
src/structures/shared/Search.js
Normal file
@@ -0,0 +1,63 @@
|
||||
const long = require('long');
|
||||
|
||||
module.exports = function search(target, options) {
|
||||
if (typeof options === 'string') options = { content: options };
|
||||
if (options.before) {
|
||||
if (!(options.before instanceof Date)) options.before = new Date(options.before);
|
||||
options.maxID = long.fromNumber(options.before.getTime() - 14200704e5).shiftLeft(22).toString();
|
||||
}
|
||||
if (options.after) {
|
||||
if (!(options.after instanceof Date)) options.after = new Date(options.after);
|
||||
options.minID = long.fromNumber(options.after.getTime() - 14200704e5).shiftLeft(22).toString();
|
||||
}
|
||||
if (options.during) {
|
||||
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).shiftLeft(22).toString();
|
||||
}
|
||||
if (options.channel) options.channel = target.client.resolver.resolveChannelID(options.channel);
|
||||
if (options.author) options.author = target.client.resolver.resolveUserID(options.author);
|
||||
if (options.mentions) options.mentions = target.client.resolver.resolveUserID(options.options.mentions);
|
||||
options = {
|
||||
content: options.content,
|
||||
max_id: options.maxID,
|
||||
min_id: options.minID,
|
||||
has: options.has,
|
||||
channel_id: options.channel,
|
||||
author_id: options.author,
|
||||
author_type: options.authorType,
|
||||
context_size: options.contextSize,
|
||||
sort_by: options.sortBy,
|
||||
sort_order: options.sortOrder,
|
||||
limit: options.limit,
|
||||
offset: options.offset,
|
||||
mentions: options.mentions,
|
||||
mentions_everyone: options.mentionsEveryone,
|
||||
link_hostname: options.linkHostname,
|
||||
embed_provider: options.embedProvider,
|
||||
embed_type: options.embedType,
|
||||
attachment_filename: options.attachmentFilename,
|
||||
attachment_extension: options.attachmentExtension,
|
||||
};
|
||||
|
||||
// Lazy load these because some of them use util
|
||||
const Channel = require('../Channel');
|
||||
const Guild = require('../Guild');
|
||||
const Message = require('../Message');
|
||||
|
||||
if (!(target instanceof Channel || target instanceof Guild)) {
|
||||
throw new TypeError('Target must be a TextChannel, DMChannel, GroupDMChannel, or Guild.');
|
||||
}
|
||||
|
||||
let endpoint = target.client.api[target instanceof Channel ? 'channels' : 'guilds'](target.id).messages().search;
|
||||
return endpoint.get({ query: options }).then(body => {
|
||||
const messages = body.messages.map(x =>
|
||||
x.map(m => new Message(target.client.channels.get(m.channel_id), m, target.client))
|
||||
);
|
||||
return {
|
||||
totalResults: body.total_results,
|
||||
messages,
|
||||
};
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user