mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Clean up docgen code and some reaction stuff
This commit is contained in:
@@ -21,7 +21,6 @@ const DocumentedEvent = require('./DocumentedEvent');
|
||||
*/
|
||||
|
||||
class DocumentedClass extends DocumentedItem {
|
||||
|
||||
constructor(docParent, data) {
|
||||
super(docParent, data);
|
||||
this.props = new Map();
|
||||
@@ -70,9 +69,7 @@ class DocumentedClass extends DocumentedItem {
|
||||
extends: augments,
|
||||
access,
|
||||
};
|
||||
if (this.classConstructor) {
|
||||
serialized.classConstructor = this.classConstructor.serialize();
|
||||
}
|
||||
if (this.classConstructor) serialized.classConstructor = this.classConstructor.serialize();
|
||||
serialized.methods = Array.from(this.methods.values()).map(m => m.serialize());
|
||||
serialized.properties = Array.from(this.props.values()).map(p => p.serialize());
|
||||
serialized.events = Array.from(this.events.values()).map(e => e.serialize());
|
||||
|
||||
@@ -17,14 +17,11 @@ const DocumentedParam = require('./DocumentedParam');
|
||||
*/
|
||||
|
||||
class DocumentedConstructor extends DocumentedItem {
|
||||
|
||||
registerMetaInfo(data) {
|
||||
super.registerMetaInfo(data);
|
||||
this.directData = data;
|
||||
const newParams = [];
|
||||
for (const param of data.params) {
|
||||
newParams.push(new DocumentedParam(this, param));
|
||||
}
|
||||
for (const param of data.params) newParams.push(new DocumentedParam(this, param));
|
||||
this.directData.params = newParams;
|
||||
}
|
||||
|
||||
@@ -40,7 +37,6 @@ class DocumentedConstructor extends DocumentedItem {
|
||||
params: params.map(p => p.serialize()),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = DocumentedConstructor;
|
||||
|
||||
@@ -50,15 +50,12 @@ const DocumentedParam = require('./DocumentedParam');
|
||||
*/
|
||||
|
||||
class DocumentedEvent extends DocumentedItem {
|
||||
|
||||
registerMetaInfo(data) {
|
||||
this.directData = data;
|
||||
this.directData.meta = new DocumentedItemMeta(this, data.meta);
|
||||
const newParams = [];
|
||||
data.params = data.params || [];
|
||||
for (const param of data.params) {
|
||||
newParams.push(new DocumentedParam(this, param));
|
||||
}
|
||||
for (const param of data.params) newParams.push(new DocumentedParam(this, param));
|
||||
this.directData.params = newParams;
|
||||
}
|
||||
|
||||
@@ -74,7 +71,6 @@ class DocumentedEvent extends DocumentedItem {
|
||||
params: params.map(p => p.serialize()),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = DocumentedEvent;
|
||||
|
||||
@@ -50,7 +50,6 @@ const DocumentedParam = require('./DocumentedParam');
|
||||
*/
|
||||
|
||||
class DocumentedFunction extends DocumentedItem {
|
||||
|
||||
registerMetaInfo(data) {
|
||||
super.registerMetaInfo(data);
|
||||
this.directData = data;
|
||||
@@ -59,9 +58,7 @@ class DocumentedFunction extends DocumentedItem {
|
||||
names: ['void'],
|
||||
});
|
||||
const newParams = [];
|
||||
for (const param of data.params) {
|
||||
newParams.push(new DocumentedParam(this, param));
|
||||
}
|
||||
for (const param of data.params) newParams.push(new DocumentedParam(this, param));
|
||||
this.directData.params = newParams;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const cwd = (`${process.cwd()}\\`).replace(/\\/g, '/');
|
||||
const backToForward = /\\/g;
|
||||
|
||||
const DocumentedItem = require('./DocumentedItem');
|
||||
|
||||
const cwd = `${process.cwd()}\\`.replace(/\\/g, '/');
|
||||
const backToForward = /\\/g;
|
||||
|
||||
/*
|
||||
{ lineno: 7,
|
||||
filename: 'VoiceChannel.js',
|
||||
@@ -10,7 +10,6 @@ const DocumentedItem = require('./DocumentedItem');
|
||||
*/
|
||||
|
||||
class DocumentedItemMeta extends DocumentedItem {
|
||||
|
||||
registerMetaInfo(data) {
|
||||
super.registerMetaInfo(data);
|
||||
this.directData.line = data.lineno;
|
||||
@@ -23,7 +22,6 @@ class DocumentedItemMeta extends DocumentedItem {
|
||||
const { line, file, path } = this.directData;
|
||||
return { line, file, path };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = DocumentedItemMeta;
|
||||
|
||||
@@ -21,7 +21,6 @@ const DocumentedParam = require('./DocumentedParam');
|
||||
*/
|
||||
|
||||
class DocumentedMember extends DocumentedItem {
|
||||
|
||||
registerMetaInfo(data) {
|
||||
super.registerMetaInfo(data);
|
||||
this.directData = data;
|
||||
@@ -52,7 +51,6 @@ class DocumentedMember extends DocumentedItem {
|
||||
props: properties.map(p => p.serialize()),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = DocumentedMember;
|
||||
|
||||
@@ -14,7 +14,6 @@ const DocumentedVarType = require('./DocumentedVarType');
|
||||
*/
|
||||
|
||||
class DocumentedParam extends DocumentedItem {
|
||||
|
||||
registerMetaInfo(data) {
|
||||
super.registerMetaInfo(data);
|
||||
this.directData = data;
|
||||
|
||||
@@ -19,11 +19,6 @@ const DocumentedParam = require('./DocumentedParam');
|
||||
*/
|
||||
|
||||
class DocumentedTypeDef extends DocumentedItem {
|
||||
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
}
|
||||
|
||||
registerMetaInfo(data) {
|
||||
super.registerMetaInfo(data);
|
||||
this.props = new Map();
|
||||
@@ -31,9 +26,7 @@ class DocumentedTypeDef extends DocumentedItem {
|
||||
this.directData.meta = new DocumentedItemMeta(this, data.meta);
|
||||
this.directData.type = new DocumentedVarType(this, data.type);
|
||||
data.properties = data.properties || [];
|
||||
for (const prop of data.properties) {
|
||||
this.props.set(prop.name, new DocumentedParam(this, prop));
|
||||
}
|
||||
for (const prop of data.properties) this.props.set(prop.name, new DocumentedParam(this, prop));
|
||||
}
|
||||
|
||||
serialize() {
|
||||
@@ -50,7 +43,6 @@ class DocumentedTypeDef extends DocumentedItem {
|
||||
serialized.properties = Array.from(this.props.values()).map(p => p.serialize());
|
||||
return serialized;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = DocumentedTypeDef;
|
||||
|
||||
@@ -11,10 +11,24 @@ const DocumentedItem = require('./DocumentedItem');
|
||||
const regex = /([\w]+)([^\w]+)/;
|
||||
const regexG = /([\w]+)([^\w]+)/g;
|
||||
|
||||
function splitVarName(str) {
|
||||
if (str === '*') {
|
||||
return ['*', ''];
|
||||
class DocumentedVarType extends DocumentedItem {
|
||||
registerMetaInfo(data) {
|
||||
super.registerMetaInfo(data);
|
||||
this.directData = data;
|
||||
}
|
||||
|
||||
serialize() {
|
||||
super.serialize();
|
||||
const names = [];
|
||||
for (const name of this.directData.names) names.push(splitVarName(name));
|
||||
return {
|
||||
types: names,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function splitVarName(str) {
|
||||
if (str === '*') return ['*', ''];
|
||||
const matches = str.match(regexG);
|
||||
const output = [];
|
||||
if (matches) {
|
||||
@@ -28,23 +42,4 @@ function splitVarName(str) {
|
||||
return output;
|
||||
}
|
||||
|
||||
class DocumentedVarType extends DocumentedItem {
|
||||
|
||||
registerMetaInfo(data) {
|
||||
super.registerMetaInfo(data);
|
||||
this.directData = data;
|
||||
}
|
||||
|
||||
serialize() {
|
||||
super.serialize();
|
||||
const names = [];
|
||||
for (const name of this.directData.names) {
|
||||
names.push(splitVarName(name));
|
||||
}
|
||||
return {
|
||||
types: names,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DocumentedVarType;
|
||||
|
||||
@@ -164,40 +164,6 @@ class Message {
|
||||
}
|
||||
}
|
||||
|
||||
_addReaction(emoji, user) {
|
||||
const emojiID = emoji.id ? `${emoji.name}:${emoji.id}` : emoji.name;
|
||||
let reaction;
|
||||
if (this.reactions.has(emojiID)) {
|
||||
reaction = this.reactions.get(emojiID);
|
||||
if (!reaction.me) reaction.me = user.id === this.client.user.id;
|
||||
} else {
|
||||
reaction = new MessageReaction(this, emoji, 0, user.id === this.client.user.id);
|
||||
this.reactions.set(emojiID, reaction);
|
||||
}
|
||||
if (!reaction.users.has(user.id)) {
|
||||
reaction.users.set(user.id, user);
|
||||
reaction.count++;
|
||||
return reaction;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
_removeReaction(emoji, user) {
|
||||
const emojiID = emoji.id || emoji;
|
||||
if (this.reactions.has(emojiID)) {
|
||||
const reaction = this.reactions.get(emojiID);
|
||||
if (reaction.users.has(user.id)) {
|
||||
reaction.users.delete(user.id);
|
||||
reaction.count--;
|
||||
if (user.id === this.client.user.id) {
|
||||
reaction.me = false;
|
||||
}
|
||||
return reaction;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
patch(data) { // eslint-disable-line complexity
|
||||
if (data.author) {
|
||||
this.author = this.client.users.get(data.author.id);
|
||||
@@ -323,18 +289,6 @@ class Message {
|
||||
});
|
||||
}
|
||||
|
||||
addReaction(emoji) {
|
||||
if (emoji.identifier) {
|
||||
emoji = emoji.identifier;
|
||||
} else if (typeof emoji === 'string') {
|
||||
if (!emoji.includes('%')) emoji = encodeURIComponent(emoji);
|
||||
} else {
|
||||
return Promise.reject(`Emoji must be a string or an Emoji/ReactionEmoji`);
|
||||
}
|
||||
|
||||
return this.client.rest.methods.addMessageReaction(this.channel.id, this.id, emoji);
|
||||
}
|
||||
|
||||
/**
|
||||
* An array of cached versions of the message, including the current version.
|
||||
* Sorted from latest (first) to oldest (last).
|
||||
@@ -427,6 +381,23 @@ class Message {
|
||||
return this.client.rest.methods.unpinMessage(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a reaction to the message
|
||||
* @param {Emoji|ReactionEmoji|string} emoji Emoji to react with
|
||||
* @returns {Promise<MessageReaction>}
|
||||
*/
|
||||
addReaction(emoji) {
|
||||
if (emoji.identifier) {
|
||||
emoji = emoji.identifier;
|
||||
} else if (typeof emoji === 'string') {
|
||||
if (!emoji.includes('%')) emoji = encodeURIComponent(emoji);
|
||||
} else {
|
||||
return Promise.reject('The emoji must be a string or an Emoji/ReactionEmoji.');
|
||||
}
|
||||
|
||||
return this.client.rest.methods.addMessageReaction(this.channel.id, this.id, emoji);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the message
|
||||
* @param {number} [timeout=0] How long to wait to delete the message in milliseconds
|
||||
@@ -513,6 +484,40 @@ class Message {
|
||||
toString() {
|
||||
return this.content;
|
||||
}
|
||||
|
||||
_addReaction(emoji, user) {
|
||||
const emojiID = emoji.id ? `${emoji.name}:${emoji.id}` : emoji.name;
|
||||
let reaction;
|
||||
if (this.reactions.has(emojiID)) {
|
||||
reaction = this.reactions.get(emojiID);
|
||||
if (!reaction.me) reaction.me = user.id === this.client.user.id;
|
||||
} else {
|
||||
reaction = new MessageReaction(this, emoji, 0, user.id === this.client.user.id);
|
||||
this.reactions.set(emojiID, reaction);
|
||||
}
|
||||
if (!reaction.users.has(user.id)) {
|
||||
reaction.users.set(user.id, user);
|
||||
reaction.count++;
|
||||
return reaction;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
_removeReaction(emoji, user) {
|
||||
const emojiID = emoji.id || emoji;
|
||||
if (this.reactions.has(emojiID)) {
|
||||
const reaction = this.reactions.get(emojiID);
|
||||
if (reaction.users.has(user.id)) {
|
||||
reaction.users.delete(user.id);
|
||||
reaction.count--;
|
||||
if (user.id === this.client.user.id) {
|
||||
reaction.me = false;
|
||||
}
|
||||
return reaction;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Message;
|
||||
|
||||
Reference in New Issue
Block a user