diff --git a/src/client/rest/RESTMethods.js b/src/client/rest/RESTMethods.js index 8241a4464..166f8c3e3 100644 --- a/src/client/rest/RESTMethods.js +++ b/src/client/rest/RESTMethods.js @@ -5,6 +5,7 @@ const parseEmoji = require('../../util/ParseEmoji'); const User = require('../../structures/User'); const GuildMember = require('../../structures/GuildMember'); +const Message = require('../../structures/Message'); const Role = require('../../structures/Role'); const Invite = require('../../structures/Invite'); const Webhook = require('../../structures/Webhook'); @@ -564,6 +565,14 @@ class RESTMethods { ); } + fetchMeMentions(options) { + if (options.guild) options.guild = options.guild.id ? options.guild.id : options.guild; + return this.rest.makeRequest( + 'get', + Constants.Endpoints.meMentions(options.limit, options.roles, options.everyone, options.guild) + ).then(res => res.body.map(m => new Message(this.rest.client.channels.get(m.channel_id), m, this.rest.client))); + } + addFriend(user) { return this.rest.makeRequest('post', Constants.Endpoints.relationships('@me'), true, { username: user.username, diff --git a/src/structures/ClientUser.js b/src/structures/ClientUser.js index 5aa547300..45de13a6c 100644 --- a/src/structures/ClientUser.js +++ b/src/structures/ClientUser.js @@ -146,6 +146,19 @@ class ClientUser extends User { return this.setPresence({ afk }); } + /** + * Fetches messages that mentioned the client's user + * @param {Object} [options] Options for the fetch + * @param {number} [options.limit=25] Maximum number of mentions to retrieve + * @param {boolean} [options.roles=true] Whether to include role mentions + * @param {boolean} [options.everyone=true] Whether to include everyone/here mentions + * @param {Guild|string} [options.guild] Limit the search to a specific guild + * @returns {Promise} + */ + fetchMentions(options = { limit: 25, roles: true, everyone: true, guild: null }) { + return this.client.rest.methods.fetchMentions(options); + } + /** * Send a friend request * This is only available when using a user account. diff --git a/src/util/Constants.js b/src/util/Constants.js index 93453e6d4..1a9756ad7 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -92,6 +92,8 @@ const Endpoints = exports.Endpoints = { avatar: (userID, avatar) => userID === '1' ? avatar : `${Endpoints.user(userID)}/avatars/${avatar}.jpg`, me: `${API}/users/@me`, meGuild: (guildID) => `${Endpoints.me}/guilds/${guildID}`, + meMentions: (limit, roles, everyone, guildID) => + `users/@me/mentions?limit=${limit}&roles=${roles}&everyone=${everyone}${guildID ? `&guild_id=${guildID}` : ''}`, relationships: (userID) => `${Endpoints.user(userID)}/relationships`, note: (userID) => `${Endpoints.me}/notes/${userID}`,