mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
Clean up some webhook stuff
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -296,6 +296,14 @@ class Guild {
|
|||||||
return this.client.rest.methods.getGuildInvites(this);
|
return this.client.rest.methods.getGuildInvites(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch all webhooks for the guild.
|
||||||
|
* @returns {Collection<Webhook>}
|
||||||
|
*/
|
||||||
|
fetchWebhooks() {
|
||||||
|
return this.client.rest.methods.fetchGuildWebhooks(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a single guild member from a user.
|
* Fetch a single guild member from a user.
|
||||||
* @param {UserResolvable} user The user to fetch the member for
|
* @param {UserResolvable} user The user to fetch the member for
|
||||||
@@ -622,14 +630,6 @@ class Guild {
|
|||||||
return this.client.rest.methods.deleteGuild(this);
|
return this.client.rest.methods.deleteGuild(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch all webhooks for the guild.
|
|
||||||
* @returns {Collection<Webhook>}
|
|
||||||
*/
|
|
||||||
fetchWebhooks() {
|
|
||||||
return this.client.rest.methods.fetchGuildWebhooks(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether this Guild equals another Guild. It compares all properties, so for most operations
|
* Whether this Guild equals another Guild. It compares all properties, so for most operations
|
||||||
* it is advisable to just compare `guild.id === guild2.id` as it is much faster and is often
|
* it is advisable to just compare `guild.id === guild2.id` as it is much faster and is often
|
||||||
|
|||||||
@@ -56,10 +56,10 @@ class TextChannel extends GuildChannel {
|
|||||||
get typingCount() { return; }
|
get typingCount() { return; }
|
||||||
createCollector() { return; }
|
createCollector() { return; }
|
||||||
awaitMessages() { return; }
|
awaitMessages() { return; }
|
||||||
bulkDelete() { return; }
|
|
||||||
fetchWebhook() { return; }
|
fetchWebhook() { return; }
|
||||||
fetchWebhooks() { return; }
|
fetchWebhooks() { return; }
|
||||||
createWebhook() { return; }
|
createWebhook() { return; }
|
||||||
|
bulkDelete() { return; }
|
||||||
_cacheMessage() { return; }
|
_cacheMessage() { return; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const escapeMarkdown = require('../util/EscapeMarkdown');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Webhook
|
* Represents a Webhook
|
||||||
@@ -49,13 +50,13 @@ class Webhook {
|
|||||||
* The guild the Webhook belongs to
|
* The guild the Webhook belongs to
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.guild_id = data.guild_id;
|
this.guildID = data.guild_id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The channel the Webhook belongs to
|
* The channel the Webhook belongs to
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.channel_id = data.channel_id;
|
this.channelID = data.channel_id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The owner of the Webhook
|
* The owner of the Webhook
|
||||||
@@ -144,18 +145,10 @@ class Webhook {
|
|||||||
if (!options.split.prepend) options.split.prepend = `\`\`\`${lang ? lang : ''}\n`;
|
if (!options.split.prepend) options.split.prepend = `\`\`\`${lang ? lang : ''}\n`;
|
||||||
if (!options.split.append) options.split.append = '\n```';
|
if (!options.split.append) options.split.append = '\n```';
|
||||||
}
|
}
|
||||||
content = this.client.resolver.resolveString(content).replace(/```/g, '`\u200b``');
|
content = escapeMarkdown(this.client.resolver.resolveString(content), true);
|
||||||
return this.sendMessage(`\`\`\`${lang ? lang : ''}\n${content}\n\`\`\``, options);
|
return this.sendMessage(`\`\`\`${lang ? lang : ''}\n${content}\n\`\`\``, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete the Webhook
|
|
||||||
* @returns {Promise}
|
|
||||||
*/
|
|
||||||
delete() {
|
|
||||||
return this.client.rest.methods.deleteChannelWebhook(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit the Webhook.
|
* Edit the Webhook.
|
||||||
* @param {string} name The new name for the Webhook
|
* @param {string} name The new name for the Webhook
|
||||||
@@ -179,6 +172,14 @@ class Webhook {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the Webhook
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
delete() {
|
||||||
|
return this.client.rest.methods.deleteChannelWebhook(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Webhook;
|
module.exports = Webhook;
|
||||||
|
|||||||
@@ -310,24 +310,12 @@ class TextBasedChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bulk delete a given Collection or Array of messages in one go. Returns the deleted messages after.
|
* Fetch a webhook by ID
|
||||||
* Only OAuth Bot accounts may use this method.
|
* @param {string} id The id of the webhook.
|
||||||
* @param {Collection<string, Message>|Message[]} messages The messages to delete
|
* @returns {Promise<Webhook>}
|
||||||
* @returns {Collection<string, Message>}
|
|
||||||
*/
|
*/
|
||||||
bulkDelete(messages) {
|
fetchWebhook(id) {
|
||||||
if (messages instanceof Collection) messages = messages.array();
|
return this.client.rest.methods.fetchWebhook(id);
|
||||||
if (!(messages instanceof Array)) return Promise.reject(new TypeError('Messages must be an Array or Collection.'));
|
|
||||||
const messageIDs = messages.map(m => m.id);
|
|
||||||
return this.client.rest.methods.bulkDeleteMessages(this, messageIDs);
|
|
||||||
}
|
|
||||||
|
|
||||||
_cacheMessage(message) {
|
|
||||||
const maxSize = this.client.options.messageCacheMaxSize;
|
|
||||||
if (maxSize === 0) return null;
|
|
||||||
if (this.messages.size >= maxSize && maxSize > 0) this.messages.delete(this.messages.firstKey());
|
|
||||||
this.messages.set(message.id, message);
|
|
||||||
return message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -338,15 +326,6 @@ class TextBasedChannel {
|
|||||||
return this.client.rest.methods.fetchChannelWebhooks(this);
|
return this.client.rest.methods.fetchChannelWebhooks(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch a webhook by ID
|
|
||||||
* @param {string} id The id of the webhook.
|
|
||||||
* @returns {Promise<Webhook>}
|
|
||||||
*/
|
|
||||||
fetchWebhook(id) {
|
|
||||||
return this.client.rest.methods.fetchWebhook(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a webhook for the channel.
|
* Create a webhook for the channel.
|
||||||
* @param {string} name The name of the webhook.
|
* @param {string} name The name of the webhook.
|
||||||
@@ -372,6 +351,27 @@ class TextBasedChannel {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bulk delete a given Collection or Array of messages in one go. Returns the deleted messages after.
|
||||||
|
* Only OAuth Bot accounts may use this method.
|
||||||
|
* @param {Collection<string, Message>|Message[]} messages The messages to delete
|
||||||
|
* @returns {Collection<string, Message>}
|
||||||
|
*/
|
||||||
|
bulkDelete(messages) {
|
||||||
|
if (messages instanceof Collection) messages = messages.array();
|
||||||
|
if (!(messages instanceof Array)) return Promise.reject(new TypeError('Messages must be an Array or Collection.'));
|
||||||
|
const messageIDs = messages.map(m => m.id);
|
||||||
|
return this.client.rest.methods.bulkDeleteMessages(this, messageIDs);
|
||||||
|
}
|
||||||
|
|
||||||
|
_cacheMessage(message) {
|
||||||
|
const maxSize = this.client.options.messageCacheMaxSize;
|
||||||
|
if (maxSize === 0) return null;
|
||||||
|
if (this.messages.size >= maxSize && maxSize > 0) this.messages.delete(this.messages.firstKey());
|
||||||
|
this.messages.set(message.id, message);
|
||||||
|
return message;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.applyToClass = (structure, full = false) => {
|
exports.applyToClass = (structure, full = false) => {
|
||||||
@@ -388,8 +388,8 @@ exports.applyToClass = (structure, full = false) => {
|
|||||||
props.push('fetchPinnedMessages');
|
props.push('fetchPinnedMessages');
|
||||||
props.push('createCollector');
|
props.push('createCollector');
|
||||||
props.push('awaitMessages');
|
props.push('awaitMessages');
|
||||||
props.push('fetchWebhooks');
|
|
||||||
props.push('fetchWebhook');
|
props.push('fetchWebhook');
|
||||||
|
props.push('fetchWebhooks');
|
||||||
props.push('createWebhook');
|
props.push('createWebhook');
|
||||||
}
|
}
|
||||||
for (const prop of props) applyProp(structure, prop);
|
for (const prop of props) applyProp(structure, prop);
|
||||||
|
|||||||
Reference in New Issue
Block a user