mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Updated to docs format v3, adds support for interfaces
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -4,7 +4,7 @@ let parse;
|
||||
|
||||
const customDocs = require('../custom/index');
|
||||
|
||||
const GEN_VERSION = 2;
|
||||
const GEN_VERSION = 3;
|
||||
|
||||
try {
|
||||
fs = require('fs-extra');
|
||||
@@ -20,7 +20,7 @@ console.log('Starting...');
|
||||
let json = '';
|
||||
|
||||
const stream = parse({
|
||||
src: ['./src/*.js', './src/*/*.js'],
|
||||
src: ['./src/*.js', './src/*/*.js', './src/**/*.js'],
|
||||
});
|
||||
|
||||
const cwd = (`${process.cwd()}\\`).replace(/\\/g, '/');
|
||||
@@ -36,6 +36,7 @@ function cleanPaths() {
|
||||
function clean() {
|
||||
const cleaned = {
|
||||
classes: {},
|
||||
interfaces: {},
|
||||
};
|
||||
for (const item of json) {
|
||||
if (item.kind === 'class') {
|
||||
@@ -45,10 +46,19 @@ function clean() {
|
||||
properties: [],
|
||||
events: [],
|
||||
};
|
||||
} else if (item.kind === 'interface') {
|
||||
cleaned.interfaces[item.longname] = {
|
||||
meta: item,
|
||||
functions: [],
|
||||
properties: [],
|
||||
events: [],
|
||||
};
|
||||
} else if (item.kind === 'member') {
|
||||
cleaned.classes[item.memberof].properties.push(item);
|
||||
const obj = cleaned.classes[item.memberof] || cleaned.interfaces[item.memberof];
|
||||
obj.properties.push(item);
|
||||
} else if (item.kind === 'function' && item.memberof) {
|
||||
cleaned.classes[item.memberof].functions.push(item);
|
||||
const obj = cleaned.classes[item.memberof] || cleaned.interfaces[item.memberof];
|
||||
obj.functions.push(item);
|
||||
}
|
||||
}
|
||||
json = cleaned;
|
||||
@@ -58,7 +68,6 @@ function next() {
|
||||
json = JSON.parse(json);
|
||||
cleanPaths();
|
||||
console.log('parsed inline code');
|
||||
console.log(json);
|
||||
clean();
|
||||
json = {
|
||||
meta: {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"description": "A way to interface with the Discord API",
|
||||
"main": "./src/index",
|
||||
"scripts": {
|
||||
"test": "node test/random",
|
||||
"test": "eslint src/ && node test/random",
|
||||
"docs": "node docs/gen/index.js"
|
||||
},
|
||||
"repository": {
|
||||
|
||||
@@ -5,6 +5,7 @@ const TextBasedChannel = require('./interface/TextBasedChannel');
|
||||
/**
|
||||
* Represents a Server Text Channel on Discord.
|
||||
* @extends {GuildChannel}
|
||||
* @implements {TextBasedChannel}
|
||||
*/
|
||||
class TextChannel extends GuildChannel {
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ const TextBasedChannel = require('./interface/TextBasedChannel');
|
||||
|
||||
/**
|
||||
* Represents a User on Discord.
|
||||
* @implements {TextBasedChannel}
|
||||
*/
|
||||
class User {
|
||||
constructor(client, data) {
|
||||
@@ -99,6 +100,10 @@ class User {
|
||||
|
||||
return base;
|
||||
}
|
||||
|
||||
sendMessage() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
TextBasedChannel.applyToClass(User);
|
||||
|
||||
@@ -1,12 +1,43 @@
|
||||
function sendMessage(content, options = {}) {
|
||||
return this.client.rest.methods.sendMessage(this, content, options.tts);
|
||||
/**
|
||||
* Interface for classes that have text-channel-like features
|
||||
* @interface
|
||||
*/
|
||||
class TextBasedChannel {
|
||||
/**
|
||||
* Send a message to this channel
|
||||
* @param {String} content the content to send
|
||||
* @param {MessageOptions} [options={}] the options to provide
|
||||
* @returns {Promise<Message>}
|
||||
* @example
|
||||
* // send a message
|
||||
* channel.sendMessage('hello!')
|
||||
* .then(message => console.log(`Sent message: ${message.content}`))
|
||||
* .catch(console.log);
|
||||
*/
|
||||
sendMessage(content, options = {}) {
|
||||
return this.client.rest.methods.sendMessage(this, content, options.tts);
|
||||
}
|
||||
/**
|
||||
* Send a text-to-speech message to this channel
|
||||
* @param {String} content the content to send
|
||||
* @returns {Promise<Message>}
|
||||
* @example
|
||||
* // send a TTS message
|
||||
* channel.sendTTSMessage('hello!')
|
||||
* .then(message => console.log(`Sent tts message: ${message.content}`))
|
||||
* .catch(console.log);
|
||||
*/
|
||||
sendTTSMessage(content) {
|
||||
return this.client.rest.methods.sendMessage(this, content, true);
|
||||
}
|
||||
}
|
||||
|
||||
function sendTTSMessage(content) {
|
||||
return this.client.rest.methods.sendMessage(this, content, true);
|
||||
function applyProp(structure, prop) {
|
||||
structure.prototype[prop] = TextBasedChannel.prototype[prop];
|
||||
}
|
||||
|
||||
exports.applyToClass = structure => {
|
||||
structure.prototype.sendMessage = sendMessage;
|
||||
structure.prototype.sendTTSMessage = sendTTSMessage;
|
||||
for (const prop of ['sendMessage', 'sendTTSMessage']) {
|
||||
applyProp(structure, prop);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user