Add utility features for searching.

This commit is contained in:
Paul
2021-07-09 14:23:48 +01:00
parent 4f5976e968
commit cea32a0093
3 changed files with 36 additions and 2 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "revolt.js",
"version": "4.3.3-alpha.12",
"version": "4.3.3-alpha.13",
"main": "dist/index.js",
"repository": "https://gitlab.insrt.uk/revolt/revolt.js",
"author": "Paul Makles <insrt.uk>",
+1 -1
View File
@@ -410,7 +410,7 @@ type Routes =
}
| {
// Search messages in a channel (optionally include users as well).
method: 'GET',
method: 'POST',
route: `/channels/${Id}/search`,
data: {
query: string,
+34
View File
@@ -232,6 +232,40 @@ export default class Channels extends Collection<Channel> {
return res;
}
/**
* Search for messages
* @param id ID of the target channel
* @param params Message searching route data
* @returns The messages
*/
async search(id: string, params?: Omit<Route<'POST', '/channels/id/search'>["data"], 'include_users'>) {
return await this.client.request('POST', `/channels/${id}/search` as '/channels/id/search', { params }) as Message[];
}
/**
* Search for messages including the users that sent them
* @param id ID of the target channel
* @param params Message searching route data
* @returns The messages
*/
async searchWithUsers(id: string, params?: Omit<Route<'POST', '/channels/id/search'>["data"], 'include_users'>, processUsers?: boolean) {
let res = await this.client.request('GET', `/channels/${id}/search` as '/channels/id/search', { params: { ...params, include_users: true } }) as { messages: Message[], users: User[], members: Servers.Member[] };
if (processUsers) {
for (let user of res.users) {
this.client.users.set(user);
}
if (res.members) {
for (let member of res.members) {
this.client.servers.members.set(flattenMember(member));
}
}
}
return res;
}
/**
* Fetch stale messages
* @param id ID of the target channel