mirror of
https://github.com/discordjs/discord.js.git
synced 2026-05-23 12:00:09 +00:00
Compare commits
18 Commits
@discordjs
...
v8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
780cbadd79 | ||
|
|
af0663e915 | ||
|
|
07fbf8df56 | ||
|
|
72be5e6498 | ||
|
|
2b1fcf168c | ||
|
|
d0e38c721d | ||
|
|
972558f030 | ||
|
|
015eb9c546 | ||
|
|
76dd4f74da | ||
|
|
c00d209014 | ||
|
|
d22ca969db | ||
|
|
ba0c8c45fc | ||
|
|
3bc6ea455d | ||
|
|
53ecaab12a | ||
|
|
34323c869e | ||
|
|
d96f5d1e30 | ||
|
|
4139401f1b | ||
|
|
e3c7fd70e1 |
@@ -55,9 +55,9 @@ author = u'hydrabolt'
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '8.0.0'
|
||||
version = '8.2.0'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '8.0.0'
|
||||
release = '8.2.0'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
|
||||
@@ -122,7 +122,7 @@ sendTTSMessage(content, `callback`)
|
||||
sendFile(attachment, name, content, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.sendFile(channel, attachment, name, content, callbasck)``
|
||||
| **Shortcut of** ``client.sendFile(channel, attachment, name, content, callback)``
|
||||
| **See** client.sendFile_
|
||||
|
||||
startTyping(`callback`)
|
||||
@@ -177,4 +177,4 @@ hasRole(role)
|
||||
.. _client.startTyping : ./docs_client.html#starttyping-channel-callback
|
||||
.. _client.stopTyping : ./docs_client.html#stoptyping-channel-callback
|
||||
.. _client.getChannelLogs : ./docs_client.html#getchannellogs-channel-limit-options-callback
|
||||
.. _client.getMessage : ./docs_client.html#getmessage-channel-messageid-callback
|
||||
.. _client.getMessage : ./docs_client.html#getmessage-channel-messageid-callback
|
||||
|
||||
@@ -8,6 +8,8 @@ looking for something low level, check out `discord.io`_.
|
||||
|
||||
if you're having problems, check out the `troubleshooting guide`_.
|
||||
|
||||
If you're looking for docs for discord.js 9.0.0 and above, try visiting `the new docs site`_.
|
||||
|
||||
Feel free to make any contributions you want, whether it be through creating an issue, giving a suggestion or making a pull request!
|
||||
|
||||
.. note:: This documentation is still a work-in-progress, apologies if something isn't yet documented!
|
||||
@@ -64,3 +66,4 @@ Feel free to make any contributions you want, whether it be through creating an
|
||||
.. _Discord : https://discordapp.com/
|
||||
.. _troubleshooting guide : troubleshooting.html
|
||||
.. _discord.io : https://github.com/izy521/discord.io
|
||||
.. _the new docs site : http://hydrabolt.github.io/discord.js
|
||||
@@ -802,13 +802,13 @@ var Client = (function (_EventEmitter) {
|
||||
// def createChannel
|
||||
|
||||
Client.prototype.createChannel = function createChannel(server, name) {
|
||||
var type = arguments.length <= 2 || arguments[2] === undefined ? "text" : arguments[2];
|
||||
var type = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
|
||||
var callback = arguments.length <= 3 || arguments[3] === undefined ? function () /*err, channel*/{} : arguments[3];
|
||||
|
||||
if (typeof type === "function") {
|
||||
// options is the callback
|
||||
callback = type;
|
||||
type = "text";
|
||||
type = 0;
|
||||
}
|
||||
|
||||
return this.internal.createChannel(server, name, type).then(dataCallback(callback), errorCallback(callback));
|
||||
@@ -1191,6 +1191,63 @@ var Client = (function (_EventEmitter) {
|
||||
return this.internal.removeFriend(user).then(dataCallback(callback), errorCallback(callback));
|
||||
};
|
||||
|
||||
Client.prototype.getServerWebhooks = function getServerWebhooks(guild) {
|
||||
var callback = arguments.length <= 1 || arguments[1] === undefined ? function () /*err, {}*/{} : arguments[1];
|
||||
|
||||
return this.internal.getServerWebhooks(guild).then(dataCallback(callback), errorCallback(callback));
|
||||
};
|
||||
|
||||
Client.prototype.getChannelWebhooks = function getChannelWebhooks(channel) {
|
||||
var callback = arguments.length <= 1 || arguments[1] === undefined ? function () /*err, {}*/{} : arguments[1];
|
||||
|
||||
return this.internal.getChannelWebhooks(channel).then(dataCallback(callback), errorCallback(callback));
|
||||
};
|
||||
|
||||
Client.prototype.sendWebhookMessage = function sendWebhookMessage(webhook, content) {
|
||||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
||||
var callback = arguments.length <= 3 || arguments[3] === undefined ? function () /*err, {}*/{} : arguments[3];
|
||||
|
||||
if (typeof options === "function") {
|
||||
// options is the callback
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
return this.internal.sendWebhookMessage(webhook, content, options).then(dataCallback(callback), errorCallback(callback));
|
||||
};
|
||||
|
||||
Client.prototype.editWebhook = function editWebhook(webhook) {
|
||||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
|
||||
var callback = arguments.length <= 2 || arguments[2] === undefined ? function () /*err, {}*/{} : arguments[2];
|
||||
|
||||
if (typeof options === "function") {
|
||||
// options is the callback
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
return this.internal.editWebhook(webhook, options).then(dataCallback(callback), errorCallback(callback));
|
||||
};
|
||||
|
||||
Client.prototype.createWebhook = function createWebhook(webhook) {
|
||||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
|
||||
var callback = arguments.length <= 2 || arguments[2] === undefined ? function () /*err, {}*/{} : arguments[2];
|
||||
|
||||
if (typeof options === "function") {
|
||||
// options is the callback
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
return this.internal.createWebhook(webhook, options).then(dataCallback(callback), errorCallback(callback));
|
||||
};
|
||||
|
||||
Client.prototype.deleteWebhook = function deleteWebhook(webhook) {
|
||||
var callback = arguments.length <= 1 || arguments[1] === undefined ? function () /*err, {}*/{} : arguments[1];
|
||||
|
||||
return this.internal.createWebhook(webhook).then(dataCallback(callback), errorCallback(callback));
|
||||
};
|
||||
|
||||
// def getOAuthApplication
|
||||
|
||||
Client.prototype.getOAuthApplication = function getOAuthApplication(appID) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -84,6 +84,10 @@ var _StructuresInvite = require("../../Structures/Invite");
|
||||
|
||||
var _StructuresInvite2 = _interopRequireDefault(_StructuresInvite);
|
||||
|
||||
var _StructuresWebhook = require("../../Structures/Webhook");
|
||||
|
||||
var _StructuresWebhook2 = _interopRequireDefault(_StructuresWebhook);
|
||||
|
||||
var _VoiceVoiceConnection = require("../../Voice/VoiceConnection");
|
||||
|
||||
var _VoiceVoiceConnection2 = _interopRequireDefault(_VoiceVoiceConnection);
|
||||
@@ -308,6 +312,27 @@ var Resolver = (function () {
|
||||
return null;
|
||||
};
|
||||
|
||||
Resolver.prototype.resolveWebhook = function resolveWebhook(resource) {
|
||||
/*
|
||||
accepts a Webhook
|
||||
*/
|
||||
if (resource instanceof _StructuresWebhook2["default"]) {
|
||||
return Promise.resolve(resource);
|
||||
}
|
||||
if (resource instanceof String || typeof resource === "string") {
|
||||
var server = this.internal.servers.find(function (s) {
|
||||
return s.webhooks.has("id", resource);
|
||||
});
|
||||
if (server) {
|
||||
return Promise.resolve(server.webhooks.get("id", resource));
|
||||
}
|
||||
}
|
||||
|
||||
var error = new Error("Could not resolve webhook");
|
||||
error.resource = resource;
|
||||
return Promise.reject(error);
|
||||
};
|
||||
|
||||
Resolver.prototype.resolveMessage = function resolveMessage(resource) {
|
||||
// accepts a Message, PMChannel & TextChannel
|
||||
|
||||
@@ -362,7 +387,7 @@ var Resolver = (function () {
|
||||
|
||||
var pmchat = _ref5;
|
||||
|
||||
if (pmchat.recipient.equals(resource)) {
|
||||
if (pmchat.recipients.length === 1 && pmchat.recipient && pmchat.recipient.equals(resource)) {
|
||||
return Promise.resolve(pmchat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ exports.__esModule = true;
|
||||
var Constants = {};
|
||||
|
||||
var API = Constants.API = "https://discordapp.com/api";
|
||||
exports.API = API;
|
||||
var CDN = Constants.CDN = "https://cdn.discordapp.com";
|
||||
|
||||
exports.CDN = CDN;
|
||||
var Endpoints = Constants.Endpoints = {
|
||||
// general endpoints
|
||||
LOGIN: API + "/auth/login",
|
||||
@@ -64,6 +66,9 @@ var Endpoints = Constants.Endpoints = {
|
||||
SERVER_CHANNELS: function SERVER_CHANNELS(serverID) {
|
||||
return Endpoints.SERVER(serverID) + "/channels";
|
||||
},
|
||||
SERVER_WEBHOOKS: function SERVER_WEBHOOKS(serverID) {
|
||||
return Endpoints.SERVER(serverID) + "/webhooks";
|
||||
},
|
||||
|
||||
// channels
|
||||
CHANNELS: API + "/channels",
|
||||
@@ -91,12 +96,31 @@ var Endpoints = Constants.Endpoints = {
|
||||
CHANNEL_PIN: function CHANNEL_PIN(channelID, messageID) {
|
||||
return Endpoints.CHANNEL_PINS(channelID) + "/" + messageID;
|
||||
},
|
||||
CHANNEL_WEBHOOKS: function CHANNEL_WEBHOOKS(channelID) {
|
||||
return Endpoints.CHANNEL(channelID) + "/webhooks";
|
||||
},
|
||||
|
||||
// webhooks
|
||||
WEBHOOKS: API + "/webhooks",
|
||||
WEBHOOK: function WEBHOOK(webhookID) {
|
||||
return Endpoints.WEBHOOKS + "/" + webhookID;
|
||||
},
|
||||
WEBHOOK_WITH_TOKEN: function WEBHOOK_WITH_TOKEN(webhookID, webhookToken) {
|
||||
return Endpoints.WEBHOOKS + "/" + webhookToken;
|
||||
},
|
||||
WEBHOOK_MESSAGE: function WEBHOOK_MESSAGE(webhookID, webhookToken) {
|
||||
return Endpoints.WEBHOOK(webhookID) + "/" + webhookToken;
|
||||
},
|
||||
WEBHOOK_MESSAGE_SLACK: function WEBHOOK_MESSAGE_SLACK(webhookID, webhookToken) {
|
||||
return Endpoints.WEBHOOK_MESSAGE(webhookID, webhookToken) + "/slack";
|
||||
},
|
||||
|
||||
// friends
|
||||
FRIENDS: API + "/users/@me/relationships"
|
||||
};
|
||||
|
||||
Constants.Permissions = {
|
||||
exports.Endpoints = Endpoints;
|
||||
var Permissions = Constants.Permissions = {
|
||||
// general
|
||||
createInstantInvite: 1 << 0,
|
||||
kickMembers: 1 << 1,
|
||||
@@ -128,15 +152,18 @@ Constants.Permissions = {
|
||||
|
||||
};
|
||||
|
||||
Constants.PacketType = {
|
||||
exports.Permissions = Permissions;
|
||||
var PacketType = Constants.PacketType = {
|
||||
CHANNEL_CREATE: "CHANNEL_CREATE",
|
||||
CHANNEL_DELETE: "CHANNEL_DELETE",
|
||||
CHANNEL_UPDATE: "CHANNEL_UPDATE",
|
||||
MESSAGE_CREATE: "MESSAGE_CREATE",
|
||||
MESSAGE_DELETE: "MESSAGE_DELETE",
|
||||
MESSAGE_DELETE_BULK: "MESSAGE_DELETE_BULK",
|
||||
MESSAGE_UPDATE: "MESSAGE_UPDATE",
|
||||
PRESENCE_UPDATE: "PRESENCE_UPDATE",
|
||||
READY: "READY",
|
||||
RESUME: "RESUME",
|
||||
SERVER_BAN_ADD: "GUILD_BAN_ADD",
|
||||
SERVER_BAN_REMOVE: "GUILD_BAN_REMOVE",
|
||||
SERVER_CREATE: "GUILD_CREATE",
|
||||
@@ -148,6 +175,7 @@ Constants.PacketType = {
|
||||
SERVER_ROLE_CREATE: "GUILD_ROLE_CREATE",
|
||||
SERVER_ROLE_DELETE: "GUILD_ROLE_DELETE",
|
||||
SERVER_ROLE_UPDATE: "GUILD_ROLE_UPDATE",
|
||||
SERVER_SYNC: "GUILD_SYNC",
|
||||
SERVER_UPDATE: "GUILD_UPDATE",
|
||||
TYPING: "TYPING_START",
|
||||
USER_UPDATE: "USER_UPDATE",
|
||||
@@ -157,5 +185,5 @@ Constants.PacketType = {
|
||||
FRIEND_REMOVE: "RELATIONSHIP_REMOVE"
|
||||
};
|
||||
|
||||
exports.PacketType = PacketType;
|
||||
exports["default"] = Constants;
|
||||
module.exports = exports["default"];
|
||||
|
||||
@@ -39,12 +39,14 @@ var Message = (function (_Equality) {
|
||||
_classCallCheck(this, Message);
|
||||
|
||||
_Equality.call(this);
|
||||
this.type = data.type;
|
||||
this.channel = channel;
|
||||
this.server = channel.server;
|
||||
this.client = client;
|
||||
this.nonce = data.nonce;
|
||||
this.attachments = data.attachments;
|
||||
this.tts = data.tts;
|
||||
this.pinned = data.pinned;
|
||||
this.embeds = data.embeds;
|
||||
this.timestamp = Date.parse(data.timestamp);
|
||||
this.everyoneMentioned = data.mention_everyone !== undefined ? data.mention_everyone : data.everyoneMentioned;
|
||||
@@ -62,6 +64,23 @@ var Message = (function (_Equality) {
|
||||
}
|
||||
|
||||
this.content = data.content;
|
||||
if (!this.type) {} else if (this.type === 1) {
|
||||
this.content = this.author.mention() + " added <@" + data.mentions[0].id + ">.";
|
||||
} else if (this.type === 2) {
|
||||
if (this.author.id === data.mentions[0].id) {
|
||||
this.content = this.author.mention() + " left the group.";
|
||||
} else {
|
||||
this.content = this.author.mention() + " removed <@" + data.mentions[0].id + ">.";
|
||||
}
|
||||
} else if (this.type === 3) {
|
||||
this.content = this.author.mention() + " started a call.";
|
||||
} else if (this.type === 4) {
|
||||
this.content = this.author.mention() + " changed the channel name: " + data.content;
|
||||
} else if (this.type === 5) {
|
||||
this.content = this.author.mention() + " changed the channel icon.";
|
||||
} else if (this.type === 6) {
|
||||
this.content = this.author.mention() + " pinned a message to this channel. See all the pins.";
|
||||
}
|
||||
|
||||
var mentionData = client.internal.resolver.resolveMentions(data.content, channel);
|
||||
this.cleanContent = mentionData[1];
|
||||
|
||||
@@ -28,18 +28,28 @@ var PMChannel = (function (_Channel) {
|
||||
_inherits(PMChannel, _Channel);
|
||||
|
||||
function PMChannel(data, client) {
|
||||
var _this = this;
|
||||
|
||||
_classCallCheck(this, PMChannel);
|
||||
|
||||
_Channel.call(this, data, client);
|
||||
|
||||
this.type = data.type || "text";
|
||||
this.type = data.type;
|
||||
this.lastMessageID = data.last_message_id || data.lastMessageID;
|
||||
this.messages = new _UtilCache2["default"]("id", client.options.maxCachedMessages);
|
||||
this.recipient = this.client.internal.users.add(new _User2["default"](data.recipient, this.client));
|
||||
if (data.recipients instanceof _UtilCache2["default"]) {
|
||||
this.recipients = data.recipients;
|
||||
} else {
|
||||
this.recipients = new _UtilCache2["default"]();
|
||||
data.recipients.forEach(function (recipient) {
|
||||
_this.recipients.add(_this.client.internal.users.add(new _User2["default"](recipient, _this.client)));
|
||||
});
|
||||
}
|
||||
this.name = data.name !== undefined ? data.name : this.name;
|
||||
this.owner = data.owner || this.client.internal.users.get("id", data.owner_id);
|
||||
this.icon = data.icon !== undefined ? data.icon : this.icon;
|
||||
}
|
||||
|
||||
/* warning! may return null */
|
||||
|
||||
PMChannel.prototype.toString = function toString() {
|
||||
return this.recipient.toString();
|
||||
};
|
||||
@@ -105,6 +115,13 @@ var PMChannel = (function (_Channel) {
|
||||
};
|
||||
|
||||
_createClass(PMChannel, [{
|
||||
key: "recipient",
|
||||
get: function get() {
|
||||
return this.recipients[0];
|
||||
}
|
||||
|
||||
/* warning! may return null */
|
||||
}, {
|
||||
key: "lastMessage",
|
||||
get: function get() {
|
||||
return this.messages.get("id", this.lastMessageID);
|
||||
|
||||
@@ -134,7 +134,7 @@ var Server = (function (_Equality) {
|
||||
});
|
||||
} else {
|
||||
data.channels.forEach(function (dataChannel) {
|
||||
if (dataChannel.type === "text") {
|
||||
if (dataChannel.type === 0) {
|
||||
_this.channels.add(client.internal.channels.add(new _TextChannel2["default"](dataChannel, client, _this)));
|
||||
} else {
|
||||
_this.channels.add(client.internal.channels.add(new _VoiceChannel2["default"](dataChannel, client, _this)));
|
||||
@@ -166,36 +166,40 @@ var Server = (function (_Equality) {
|
||||
}
|
||||
|
||||
if (data.voice_states) {
|
||||
for (var _iterator2 = data.voice_states, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||
var _ref2;
|
||||
if (this.client.options.bot) {
|
||||
for (var _iterator2 = data.voice_states, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||
var _ref2;
|
||||
|
||||
if (_isArray2) {
|
||||
if (_i2 >= _iterator2.length) break;
|
||||
_ref2 = _iterator2[_i2++];
|
||||
} else {
|
||||
_i2 = _iterator2.next();
|
||||
if (_i2.done) break;
|
||||
_ref2 = _i2.value;
|
||||
}
|
||||
|
||||
var voiceState = _ref2;
|
||||
|
||||
var _user = this.members.get("id", voiceState.user_id);
|
||||
if (_user) {
|
||||
this.memberMap[_user.id] = this.memberMap[_user.id] || {};
|
||||
this.memberMap[_user.id].mute = voiceState.mute || this.memberMap[_user.id].mute;
|
||||
this.memberMap[_user.id].selfMute = voiceState.self_mute === undefined ? this.memberMap[_user.id].selfMute : voiceState.self_mute;
|
||||
this.memberMap[_user.id].deaf = voiceState.deaf || this.memberMap[_user.id].deaf;
|
||||
this.memberMap[_user.id].selfDeaf = voiceState.self_deaf === undefined ? this.memberMap[_user.id].selfDeaf : voiceState.self_deaf;
|
||||
var channel = this.channels.get("id", voiceState.channel_id);
|
||||
if (channel) {
|
||||
this.eventVoiceJoin(_user, channel);
|
||||
if (_isArray2) {
|
||||
if (_i2 >= _iterator2.length) break;
|
||||
_ref2 = _iterator2[_i2++];
|
||||
} else {
|
||||
this.client.emit("warn", "channel doesn't exist even though READY expects them to");
|
||||
_i2 = _iterator2.next();
|
||||
if (_i2.done) break;
|
||||
_ref2 = _i2.value;
|
||||
}
|
||||
|
||||
var voiceState = _ref2;
|
||||
|
||||
var _user = this.members.get("id", voiceState.user_id);
|
||||
if (_user) {
|
||||
this.memberMap[_user.id] = this.memberMap[_user.id] || {};
|
||||
this.memberMap[_user.id].mute = voiceState.mute || this.memberMap[_user.id].mute;
|
||||
this.memberMap[_user.id].selfMute = voiceState.self_mute === undefined ? this.memberMap[_user.id].selfMute : voiceState.self_mute;
|
||||
this.memberMap[_user.id].deaf = voiceState.deaf || this.memberMap[_user.id].deaf;
|
||||
this.memberMap[_user.id].selfDeaf = voiceState.self_deaf === undefined ? this.memberMap[_user.id].selfDeaf : voiceState.self_deaf;
|
||||
var channel = this.channels.get("id", voiceState.channel_id);
|
||||
if (channel) {
|
||||
this.eventVoiceJoin(_user, channel);
|
||||
} else {
|
||||
this.client.emit("warn", "channel doesn't exist even though READY expects them to");
|
||||
}
|
||||
} else {
|
||||
this.client.emit("warn", "user doesn't exist even though READY expects them to");
|
||||
}
|
||||
} else {
|
||||
this.client.emit("warn", "user doesn't exist even though READY expects them to");
|
||||
}
|
||||
} else {
|
||||
this.pendingVoiceStates = data.voice_states;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -322,7 +326,7 @@ var Server = (function (_Equality) {
|
||||
};
|
||||
|
||||
Server.prototype.eventVoiceLeave = function eventVoiceLeave(user) {
|
||||
for (var _iterator4 = this.channels.getAll("type", "voice"), _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
|
||||
for (var _iterator4 = this.channels.getAll("type", 2), _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
|
||||
var _ref4;
|
||||
|
||||
if (_isArray4) {
|
||||
@@ -446,6 +450,20 @@ var Server = (function (_Equality) {
|
||||
};
|
||||
|
||||
_createClass(Server, [{
|
||||
key: "webhooks",
|
||||
get: function get() {
|
||||
return this.channels.map(function (c) {
|
||||
return c.webhooks;
|
||||
}).reduce(function (previousChannel, currentChannel) {
|
||||
if (currentChannel) {
|
||||
currentChannel.forEach(function (webhook) {
|
||||
previousChannel.add(webhook);
|
||||
});
|
||||
}
|
||||
return previousChannel;
|
||||
}, new _UtilCache2["default"]("id"));
|
||||
}
|
||||
}, {
|
||||
key: "createdAt",
|
||||
get: function get() {
|
||||
return new Date(+this.id / 4194304 + 1420070400000);
|
||||
|
||||
@@ -30,6 +30,7 @@ var TextChannel = (function (_ServerChannel) {
|
||||
|
||||
this.topic = data.topic;
|
||||
this.lastMessageID = data.last_message_id || data.lastMessageID;
|
||||
this.webhooks = new _UtilCache2["default"]("id");
|
||||
this.messages = new _UtilCache2["default"]("id", client.options.maxCachedMessages);
|
||||
}
|
||||
|
||||
|
||||
69
lib/Structures/Webhook.js
Normal file
69
lib/Structures/Webhook.js
Normal file
@@ -0,0 +1,69 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var _Constants = require("../Constants");
|
||||
|
||||
/* example data
|
||||
{
|
||||
id: '164585980739846145'
|
||||
name: 'wlfSS',
|
||||
roles: [ '135829612780322816' ],
|
||||
require_colons: false,
|
||||
managed: true,
|
||||
}
|
||||
*/
|
||||
|
||||
var Webhook = (function () {
|
||||
function Webhook(data, server, channel, user) {
|
||||
_classCallCheck(this, Webhook);
|
||||
|
||||
this.server = server;
|
||||
this.channel = channel;
|
||||
this.id = data.id;
|
||||
this.user = user || data.user;
|
||||
this.name = data.name;
|
||||
this.avatar = data.avatar;
|
||||
this.token = data.token;
|
||||
}
|
||||
|
||||
Webhook.prototype.toObject = function toObject() {
|
||||
var keys = ['id', 'name', 'avatar', 'token'],
|
||||
obj = {};
|
||||
|
||||
for (var _iterator = keys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var k = _ref;
|
||||
|
||||
obj[k] = this[k];
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
_createClass(Webhook, [{
|
||||
key: "getURL",
|
||||
get: function get() {
|
||||
return "https://canary.discordapp.com/api/webhooks/" + this.channel.id + "/" + this.token.id;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Webhook;
|
||||
})();
|
||||
|
||||
exports["default"] = Webhook;
|
||||
module.exports = exports["default"];
|
||||
@@ -124,11 +124,11 @@ var AudioEncoder = (function () {
|
||||
});
|
||||
};
|
||||
|
||||
AudioEncoder.prototype.encodeArbitraryFFmpeg = function encodeArbitraryFFmpeg(ffmpegOptions, volume) {
|
||||
AudioEncoder.prototype.encodeArbitraryFFmpeg = function encodeArbitraryFFmpeg(ffmpegOptions, options) {
|
||||
var _this3 = this;
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
_this3.volume = new _VolumeTransformer2["default"](volume);
|
||||
_this3.volume = new _VolumeTransformer2["default"](options.volume);
|
||||
|
||||
var command = _this3.getCommand();
|
||||
|
||||
@@ -136,8 +136,8 @@ var AudioEncoder = (function () {
|
||||
if (!command) return reject(new Error('FFMPEG not found. Make sure it is installed and in path.'));
|
||||
|
||||
// add options discord.js needs
|
||||
var options = ffmpegOptions.concat(['-f', 's16le', '-ar', '48000', '-ac', 2, 'pipe:1']);
|
||||
var enc = _child_process2["default"].spawn(command, options);
|
||||
ffmpegOptions = ffmpegOptions.concat(['-f', 's16le', '-ar', '48000', '-ac', 2, 'pipe:1']);
|
||||
var enc = _child_process2["default"].spawn(command, ffmpegOptions);
|
||||
|
||||
_this3.hookEncodingProcess(resolve, reject, enc);
|
||||
});
|
||||
|
||||
@@ -276,12 +276,12 @@ var VoiceConnection = (function (_EventEmitter) {
|
||||
}
|
||||
options.volume = options.volume !== undefined ? options.volume : this.getVolume();
|
||||
return new Promise(function (resolve, reject) {
|
||||
_this.encoder.encodeFile(stream, options)["catch"](error).then(function (data) {
|
||||
_this.encoder.encodeFile(stream, options).then(function (data) {
|
||||
self.streamProc = data.proc;
|
||||
var intent = self.playStream(data.stream, 2);
|
||||
resolve(intent);
|
||||
callback(null, intent);
|
||||
});
|
||||
})["catch"](error);
|
||||
function error() {
|
||||
var e = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
|
||||
|
||||
@@ -308,13 +308,13 @@ var VoiceConnection = (function (_EventEmitter) {
|
||||
}
|
||||
options.volume = options.volume !== undefined ? options.volume : this.getVolume();
|
||||
return new Promise(function (resolve, reject) {
|
||||
_this2.encoder.encodeStream(stream, options)["catch"](error).then(function (data) {
|
||||
_this2.encoder.encodeStream(stream, options).then(function (data) {
|
||||
self.streamProc = data.proc;
|
||||
self.instream = data.instream;
|
||||
var intent = self.playStream(data.stream);
|
||||
resolve(intent);
|
||||
callback(null, intent);
|
||||
});
|
||||
})["catch"](error);
|
||||
function error() {
|
||||
var e = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
|
||||
|
||||
@@ -324,29 +324,32 @@ var VoiceConnection = (function (_EventEmitter) {
|
||||
});
|
||||
};
|
||||
|
||||
VoiceConnection.prototype.playArbitraryFFmpeg = function playArbitraryFFmpeg(ffmpegOptions, volume) {
|
||||
VoiceConnection.prototype.playArbitraryFFmpeg = function playArbitraryFFmpeg(ffmpegOptions, options) {
|
||||
var _this3 = this;
|
||||
|
||||
var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, str) {} : arguments[2];
|
||||
|
||||
var self = this;
|
||||
self.stopPlaying();
|
||||
if (typeof volume === "function") {
|
||||
// volume is the callback
|
||||
callback = volume;
|
||||
}
|
||||
if (!ffmpegOptions instanceof Array) {
|
||||
ffmpegOptions = [];
|
||||
}
|
||||
var volume = volume !== undefined ? volume : this.getVolume();
|
||||
if (typeof options === "function") {
|
||||
// options is the callback
|
||||
callback = options;
|
||||
}
|
||||
if (typeof options !== "object") {
|
||||
options = {};
|
||||
}
|
||||
options.volume = options.volume !== undefined ? options.volume : this.getVolume();
|
||||
return new Promise(function (resolve, reject) {
|
||||
_this3.encoder.encodeArbitraryFFmpeg(ffmpegOptions, volume)["catch"](error).then(function (data) {
|
||||
_this3.encoder.encodeArbitraryFFmpeg(ffmpegOptions, options).then(function (data) {
|
||||
self.streamProc = data.proc;
|
||||
self.instream = data.instream;
|
||||
var intent = self.playStream(data.stream);
|
||||
resolve(intent);
|
||||
callback(null, intent);
|
||||
});
|
||||
})["catch"](error);
|
||||
function error() {
|
||||
var e = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
|
||||
|
||||
|
||||
@@ -86,6 +86,10 @@ var _StructuresVoiceChannel = require("./Structures/VoiceChannel");
|
||||
|
||||
var _StructuresVoiceChannel2 = _interopRequireDefault(_StructuresVoiceChannel);
|
||||
|
||||
var _StructuresWebhook = require("./Structures/Webhook");
|
||||
|
||||
var _StructuresWebhook2 = _interopRequireDefault(_StructuresWebhook);
|
||||
|
||||
var _Constants = require("./Constants");
|
||||
|
||||
var _Constants2 = _interopRequireDefault(_Constants);
|
||||
@@ -108,6 +112,7 @@ exports["default"] = {
|
||||
TextChannel: _StructuresTextChannel2["default"],
|
||||
User: _StructuresUser2["default"],
|
||||
VoiceChannel: _StructuresVoiceChannel2["default"],
|
||||
Webhook: _StructuresWebhook2["default"],
|
||||
Constants: _Constants2["default"],
|
||||
Cache: _UtilCacheJs2["default"]
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "discord.js",
|
||||
"version": "8.1.0",
|
||||
"version": "8.2.0",
|
||||
"description": "A way to interface with the Discord API",
|
||||
"main": "./entrypoint.js",
|
||||
"scripts": {
|
||||
@@ -25,7 +25,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/hydrabolt/discord.js#readme",
|
||||
"dependencies": {
|
||||
"superagent": "^2.1.0",
|
||||
"superagent": "^2.3.0",
|
||||
"unpipe": "^1.0.0",
|
||||
"ws": "^1.1.1"
|
||||
},
|
||||
@@ -40,7 +40,7 @@
|
||||
"mocha": "^2.4.5"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"node-opus": "^0.2.1",
|
||||
"node-opus": "^0.2.2",
|
||||
"tweetnacl": "^0.14.3"
|
||||
},
|
||||
"engines": {
|
||||
|
||||
@@ -877,11 +877,11 @@ export default class Client extends EventEmitter {
|
||||
}
|
||||
|
||||
// def createChannel
|
||||
createChannel(server, name, type = "text", callback = (/*err, channel*/) => { }) {
|
||||
createChannel(server, name, type = 0, callback = (/*err, channel*/) => { }) {
|
||||
if (typeof type === "function") {
|
||||
// options is the callback
|
||||
callback = type;
|
||||
type = "text";
|
||||
type = 0;
|
||||
}
|
||||
|
||||
return this.internal.createChannel(server, name, type)
|
||||
@@ -1177,6 +1177,54 @@ export default class Client extends EventEmitter {
|
||||
.then(dataCallback(callback), errorCallback(callback));
|
||||
}
|
||||
|
||||
getServerWebhooks(guild, callback = (/*err, {}*/) => {}) {
|
||||
return this.internal.getServerWebhooks(guild)
|
||||
.then(dataCallback(callback), errorCallback(callback));
|
||||
}
|
||||
|
||||
getChannelWebhooks(channel, callback = (/*err, {}*/) => {}) {
|
||||
return this.internal.getChannelWebhooks(channel)
|
||||
.then(dataCallback(callback), errorCallback(callback));
|
||||
}
|
||||
|
||||
sendWebhookMessage(webhook, content, options = {}, callback = (/*err, {}*/) => {}) {
|
||||
if (typeof options === "function") {
|
||||
// options is the callback
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
return this.internal.sendWebhookMessage(webhook, content, options)
|
||||
.then(dataCallback(callback), errorCallback(callback));
|
||||
}
|
||||
|
||||
editWebhook(webhook, options = {}, callback = (/*err, {}*/) => {}) {
|
||||
if (typeof options === "function") {
|
||||
// options is the callback
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
return this.internal.editWebhook(webhook, options)
|
||||
.then(dataCallback(callback), errorCallback(callback));
|
||||
}
|
||||
|
||||
createWebhook(webhook, options = {}, callback = (/*err, {}*/) => {}) {
|
||||
if (typeof options === "function") {
|
||||
// options is the callback
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
return this.internal.createWebhook(webhook, options)
|
||||
.then(dataCallback(callback), errorCallback(callback));
|
||||
}
|
||||
|
||||
deleteWebhook(webhook, callback = (/*err, {}*/) => {}) {
|
||||
return this.internal.createWebhook(webhook)
|
||||
.then(dataCallback(callback), errorCallback(callback));
|
||||
}
|
||||
|
||||
// def getOAuthApplication
|
||||
getOAuthApplication(appID, callback = (/*err, bans*/) => { }) {
|
||||
if (typeof appID === "function") {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -43,6 +43,7 @@ import Role from "../../Structures/Role";
|
||||
import Server from "../../Structures/Server";
|
||||
import Message from "../../Structures/Message";
|
||||
import Invite from "../../Structures/Invite";
|
||||
import Webhook from "../../Structures/Webhook";
|
||||
import VoiceConnection from "../../Voice/VoiceConnection";
|
||||
|
||||
export default class Resolver {
|
||||
@@ -211,6 +212,25 @@ export default class Resolver {
|
||||
return null;
|
||||
}
|
||||
|
||||
resolveWebhook(resource) {
|
||||
/*
|
||||
accepts a Webhook
|
||||
*/
|
||||
if (resource instanceof Webhook) {
|
||||
return Promise.resolve(resource);
|
||||
}
|
||||
if (resource instanceof String || typeof resource === "string") {
|
||||
let server = this.internal.servers.find(s => s.webhooks.has("id", resource));
|
||||
if (server) {
|
||||
return Promise.resolve(server.webhooks.get("id", resource));
|
||||
}
|
||||
}
|
||||
|
||||
var error = new Error("Could not resolve webhook");
|
||||
error.resource = resource;
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
resolveMessage(resource) {
|
||||
// accepts a Message, PMChannel & TextChannel
|
||||
|
||||
@@ -252,7 +272,7 @@ export default class Resolver {
|
||||
if (resource instanceof User) {
|
||||
// see if a PM exists
|
||||
for (var pmchat of this.internal.private_channels) {
|
||||
if (pmchat.recipient.equals(resource)) {
|
||||
if (pmchat.recipients.length === 1 && pmchat.recipient && pmchat.recipient.equals(resource)) {
|
||||
return Promise.resolve(pmchat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
const Constants = {};
|
||||
|
||||
const API = Constants.API = "https://discordapp.com/api";
|
||||
const CDN = Constants.CDN = "https://cdn.discordapp.com";
|
||||
export const API = Constants.API = "https://discordapp.com/api";
|
||||
export const CDN = Constants.CDN = "https://cdn.discordapp.com";
|
||||
|
||||
const Endpoints = Constants.Endpoints = {
|
||||
export const Endpoints = Constants.Endpoints = {
|
||||
// general endpoints
|
||||
LOGIN: `${API}/auth/login`,
|
||||
LOGOUT: `${API}/auth/logout`,
|
||||
@@ -33,6 +33,7 @@ const Endpoints = Constants.Endpoints = {
|
||||
SERVER_INTEGRATIONS: (serverID) => `${Endpoints.SERVER(serverID) }/integrations`,
|
||||
SERVER_MEMBERS: (serverID) => `${Endpoints.SERVER(serverID) }/members`,
|
||||
SERVER_CHANNELS: (serverID) => `${Endpoints.SERVER(serverID) }/channels`,
|
||||
SERVER_WEBHOOKS: (serverID) => `${Endpoints.SERVER(serverID) }/webhooks`,
|
||||
|
||||
// channels
|
||||
CHANNELS: `${API}/channels`,
|
||||
@@ -44,12 +45,21 @@ const Endpoints = Constants.Endpoints = {
|
||||
CHANNEL_MESSAGE: (channelID, messageID) => `${Endpoints.CHANNEL_MESSAGES(channelID)}/${messageID}`,
|
||||
CHANNEL_PINS: (channelID) => `${Endpoints.CHANNEL(channelID) }/pins`,
|
||||
CHANNEL_PIN: (channelID, messageID) => `${Endpoints.CHANNEL_PINS(channelID) }/${messageID}`,
|
||||
CHANNEL_WEBHOOKS: (channelID) => `${Endpoints.CHANNEL(channelID) }/webhooks`,
|
||||
|
||||
// webhooks
|
||||
WEBHOOKS: `${API}/webhooks`,
|
||||
WEBHOOK: (webhookID) => `${Endpoints.WEBHOOKS}/${webhookID}`,
|
||||
WEBHOOK_WITH_TOKEN: (webhookID, webhookToken) => `${Endpoints.WEBHOOKS}/${webhookToken}`,
|
||||
WEBHOOK_MESSAGE: (webhookID, webhookToken) => `${Endpoints.WEBHOOK(webhookID)}/${webhookToken}`,
|
||||
WEBHOOK_MESSAGE_SLACK: (webhookID, webhookToken) => `${Endpoints.WEBHOOK_MESSAGE(webhookID, webhookToken)}/slack`,
|
||||
|
||||
|
||||
// friends
|
||||
FRIENDS: `${API}/users/@me/relationships`
|
||||
};
|
||||
|
||||
Constants.Permissions = {
|
||||
export const Permissions = Constants.Permissions = {
|
||||
// general
|
||||
createInstantInvite: 1 << 0,
|
||||
kickMembers: 1 << 1,
|
||||
@@ -81,15 +91,17 @@ Constants.Permissions = {
|
||||
|
||||
};
|
||||
|
||||
Constants.PacketType = {
|
||||
export const PacketType = Constants.PacketType = {
|
||||
CHANNEL_CREATE : "CHANNEL_CREATE",
|
||||
CHANNEL_DELETE : "CHANNEL_DELETE",
|
||||
CHANNEL_UPDATE : "CHANNEL_UPDATE",
|
||||
MESSAGE_CREATE : "MESSAGE_CREATE",
|
||||
MESSAGE_DELETE : "MESSAGE_DELETE",
|
||||
MESSAGE_DELETE_BULK : "MESSAGE_DELETE_BULK",
|
||||
MESSAGE_UPDATE : "MESSAGE_UPDATE",
|
||||
PRESENCE_UPDATE : "PRESENCE_UPDATE",
|
||||
READY : "READY",
|
||||
RESUME : "RESUME",
|
||||
SERVER_BAN_ADD : "GUILD_BAN_ADD",
|
||||
SERVER_BAN_REMOVE: "GUILD_BAN_REMOVE",
|
||||
SERVER_CREATE : "GUILD_CREATE",
|
||||
@@ -101,6 +113,7 @@ Constants.PacketType = {
|
||||
SERVER_ROLE_CREATE : "GUILD_ROLE_CREATE",
|
||||
SERVER_ROLE_DELETE : "GUILD_ROLE_DELETE",
|
||||
SERVER_ROLE_UPDATE : "GUILD_ROLE_UPDATE",
|
||||
SERVER_SYNC : "GUILD_SYNC",
|
||||
SERVER_UPDATE : "GUILD_UPDATE",
|
||||
TYPING : "TYPING_START",
|
||||
USER_UPDATE : "USER_UPDATE",
|
||||
|
||||
@@ -14,12 +14,14 @@ import Equality from "../Util/Equality";
|
||||
export default class Message extends Equality{
|
||||
constructor(data, channel, client) {
|
||||
super();
|
||||
this.type = data.type;
|
||||
this.channel = channel;
|
||||
this.server = channel.server;
|
||||
this.client = client;
|
||||
this.nonce = data.nonce;
|
||||
this.attachments = data.attachments;
|
||||
this.tts = data.tts;
|
||||
this.pinned = data.pinned;
|
||||
this.embeds = data.embeds;
|
||||
this.timestamp = Date.parse(data.timestamp);
|
||||
this.everyoneMentioned = data.mention_everyone !== undefined ? data.mention_everyone : data.everyoneMentioned;
|
||||
@@ -37,6 +39,24 @@ export default class Message extends Equality{
|
||||
}
|
||||
|
||||
this.content = data.content;
|
||||
if(!this.type) {
|
||||
} else if(this.type === 1) {
|
||||
this.content = this.author.mention() + " added <@" + data.mentions[0].id + ">.";
|
||||
} else if(this.type === 2) {
|
||||
if(this.author.id === data.mentions[0].id) {
|
||||
this.content = this.author.mention() + " left the group.";
|
||||
} else {
|
||||
this.content = this.author.mention() + " removed <@" + data.mentions[0].id + ">.";
|
||||
}
|
||||
} else if(this.type === 3) {
|
||||
this.content = this.author.mention() + " started a call.";
|
||||
} else if(this.type === 4) {
|
||||
this.content = this.author.mention() + " changed the channel name: " + data.content;
|
||||
} else if(this.type === 5) {
|
||||
this.content = this.author.mention() + " changed the channel icon.";
|
||||
} else if(this.type === 6) {
|
||||
this.content = this.author.mention() + " pinned a message to this channel. See all the pins.";
|
||||
}
|
||||
|
||||
var mentionData = client.internal.resolver.resolveMentions(data.content, channel);
|
||||
this.cleanContent = mentionData[1];
|
||||
|
||||
@@ -9,10 +9,24 @@ export default class PMChannel extends Channel {
|
||||
constructor(data, client){
|
||||
super(data, client);
|
||||
|
||||
this.type = data.type || "text";
|
||||
this.type = data.type;
|
||||
this.lastMessageID = data.last_message_id || data.lastMessageID;
|
||||
this.messages = new Cache("id", client.options.maxCachedMessages);
|
||||
this.recipient = this.client.internal.users.add(new User(data.recipient, this.client));
|
||||
if(data.recipients instanceof Cache) {
|
||||
this.recipients = data.recipients;
|
||||
} else {
|
||||
this.recipients = new Cache();
|
||||
data.recipients.forEach((recipient) => {
|
||||
this.recipients.add(this.client.internal.users.add(new User(recipient, this.client)));
|
||||
});
|
||||
}
|
||||
this.name = data.name !== undefined ? data.name : this.name;
|
||||
this.owner = data.owner || this.client.internal.users.get("id", data.owner_id);
|
||||
this.icon = data.icon !== undefined ? data.icon : this.icon;
|
||||
}
|
||||
|
||||
get recipient() {
|
||||
return this.recipients[0];
|
||||
}
|
||||
|
||||
/* warning! may return null */
|
||||
|
||||
@@ -88,7 +88,7 @@ export default class Server extends Equality {
|
||||
data.channels.forEach((channel) => this.channels.add(channel));
|
||||
} else {
|
||||
data.channels.forEach((dataChannel) => {
|
||||
if (dataChannel.type === "text") {
|
||||
if (dataChannel.type === 0) {
|
||||
this.channels.add(client.internal.channels.add(new TextChannel(dataChannel, client, this)));
|
||||
} else {
|
||||
this.channels.add(client.internal.channels.add(new VoiceChannel(dataChannel, client, this)));
|
||||
@@ -107,27 +107,44 @@ export default class Server extends Equality {
|
||||
}
|
||||
|
||||
if (data.voice_states) {
|
||||
for (var voiceState of data.voice_states) {
|
||||
let user = this.members.get("id", voiceState.user_id);
|
||||
if (user) {
|
||||
this.memberMap[user.id] = this.memberMap[user.id] || {};
|
||||
this.memberMap[user.id].mute = voiceState.mute || this.memberMap[user.id].mute;
|
||||
this.memberMap[user.id].selfMute = voiceState.self_mute === undefined ? this.memberMap[user.id].selfMute : voiceState.self_mute;
|
||||
this.memberMap[user.id].deaf = voiceState.deaf || this.memberMap[user.id].deaf;
|
||||
this.memberMap[user.id].selfDeaf = voiceState.self_deaf === undefined ? this.memberMap[user.id].selfDeaf : voiceState.self_deaf;
|
||||
let channel = this.channels.get("id", voiceState.channel_id);
|
||||
if (channel) {
|
||||
this.eventVoiceJoin(user, channel);
|
||||
if(this.client.options.bot) {
|
||||
for (var voiceState of data.voice_states) {
|
||||
let user = this.members.get("id", voiceState.user_id);
|
||||
if (user) {
|
||||
this.memberMap[user.id] = this.memberMap[user.id] || {};
|
||||
this.memberMap[user.id].mute = voiceState.mute || this.memberMap[user.id].mute;
|
||||
this.memberMap[user.id].selfMute = voiceState.self_mute === undefined ? this.memberMap[user.id].selfMute : voiceState.self_mute;
|
||||
this.memberMap[user.id].deaf = voiceState.deaf || this.memberMap[user.id].deaf;
|
||||
this.memberMap[user.id].selfDeaf = voiceState.self_deaf === undefined ? this.memberMap[user.id].selfDeaf : voiceState.self_deaf;
|
||||
let channel = this.channels.get("id", voiceState.channel_id);
|
||||
if (channel) {
|
||||
this.eventVoiceJoin(user, channel);
|
||||
} else {
|
||||
this.client.emit("warn", "channel doesn't exist even though READY expects them to");
|
||||
}
|
||||
} else {
|
||||
this.client.emit("warn", "channel doesn't exist even though READY expects them to");
|
||||
this.client.emit("warn", "user doesn't exist even though READY expects them to");
|
||||
}
|
||||
} else {
|
||||
this.client.emit("warn", "user doesn't exist even though READY expects them to");
|
||||
}
|
||||
} else {
|
||||
this.pendingVoiceStates = data.voice_states;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get webhooks() {
|
||||
return this.channels
|
||||
.map(c => c.webhooks)
|
||||
.reduce((previousChannel, currentChannel) => {
|
||||
if (currentChannel) {
|
||||
currentChannel.forEach(webhook => {
|
||||
previousChannel.add(webhook);
|
||||
})
|
||||
}
|
||||
return previousChannel;
|
||||
}, new Cache("id"));
|
||||
}
|
||||
|
||||
get createdAt() {
|
||||
return new Date((+this.id / 4194304) + 1420070400000);
|
||||
}
|
||||
@@ -258,7 +275,7 @@ export default class Server extends Equality {
|
||||
}
|
||||
|
||||
eventVoiceLeave(user) {
|
||||
for (let chan of this.channels.getAll("type", "voice")) {
|
||||
for (let chan of this.channels.getAll("type", 2)) {
|
||||
if (chan.members.has("id", user.id)) {
|
||||
chan.members.remove(user);
|
||||
user.voiceChannel = null;
|
||||
|
||||
@@ -10,6 +10,7 @@ export default class TextChannel extends ServerChannel{
|
||||
|
||||
this.topic = data.topic;
|
||||
this.lastMessageID = data.last_message_id || data.lastMessageID;
|
||||
this.webhooks = new Cache("id");
|
||||
this.messages = new Cache("id", client.options.maxCachedMessages);
|
||||
}
|
||||
|
||||
|
||||
39
src/Structures/Webhook.js
Normal file
39
src/Structures/Webhook.js
Normal file
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
|
||||
import {Endpoints} from "../Constants";
|
||||
/* example data
|
||||
{
|
||||
id: '164585980739846145'
|
||||
name: 'wlfSS',
|
||||
roles: [ '135829612780322816' ],
|
||||
require_colons: false,
|
||||
managed: true,
|
||||
}
|
||||
*/
|
||||
|
||||
export default class Webhook {
|
||||
constructor(data, server, channel, user) {
|
||||
this.server = server;
|
||||
this.channel = channel;
|
||||
this.id = data.id;
|
||||
this.user = user || data.user;
|
||||
this.name = data.name;
|
||||
this.avatar = data.avatar;
|
||||
this.token = data.token
|
||||
}
|
||||
|
||||
get getURL() {
|
||||
return `https://canary.discordapp.com/api/webhooks/${this.channel.id}/${this.token.id}`;
|
||||
}
|
||||
|
||||
toObject() {
|
||||
let keys = ['id', 'name', 'avatar', 'token'],
|
||||
obj = {};
|
||||
|
||||
for (let k of keys) {
|
||||
obj[k] = this[k];
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -107,9 +107,9 @@ export default class AudioEncoder {
|
||||
});
|
||||
}
|
||||
|
||||
encodeArbitraryFFmpeg(ffmpegOptions, volume) {
|
||||
encodeArbitraryFFmpeg(ffmpegOptions, options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.volume = new VolumeTransformer(volume);
|
||||
this.volume = new VolumeTransformer(options.volume);
|
||||
|
||||
var command = this.getCommand();
|
||||
|
||||
@@ -117,13 +117,13 @@ export default class AudioEncoder {
|
||||
if (!command) return reject(new Error('FFMPEG not found. Make sure it is installed and in path.'));
|
||||
|
||||
// add options discord.js needs
|
||||
var options = ffmpegOptions.concat([
|
||||
ffmpegOptions = ffmpegOptions.concat([
|
||||
'-f', 's16le',
|
||||
'-ar', '48000',
|
||||
'-ac', 2,
|
||||
'pipe:1'
|
||||
]);
|
||||
var enc = cpoc.spawn(command, options);
|
||||
var enc = cpoc.spawn(command, ffmpegOptions);
|
||||
|
||||
this.hookEncodingProcess(resolve, reject, enc);
|
||||
});
|
||||
|
||||
@@ -238,14 +238,14 @@ export default class VoiceConnection extends EventEmitter {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.encoder
|
||||
.encodeFile(stream, options)
|
||||
.catch(error)
|
||||
.then(data => {
|
||||
self.streamProc = data.proc;
|
||||
var intent = self.playStream(data.stream, 2);
|
||||
resolve(intent);
|
||||
callback(null, intent);
|
||||
|
||||
});
|
||||
})
|
||||
.catch(error);
|
||||
function error(e = true) {
|
||||
reject(e);
|
||||
callback(e);
|
||||
@@ -267,15 +267,14 @@ export default class VoiceConnection extends EventEmitter {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.encoder
|
||||
.encodeStream(stream, options)
|
||||
.catch(error)
|
||||
.then(data => {
|
||||
self.streamProc = data.proc;
|
||||
self.instream = data.instream;
|
||||
var intent = self.playStream(data.stream);
|
||||
resolve(intent);
|
||||
callback(null, intent);
|
||||
|
||||
});
|
||||
})
|
||||
.catch(error);
|
||||
function error(e = true) {
|
||||
reject(e);
|
||||
callback(e);
|
||||
@@ -283,28 +282,31 @@ export default class VoiceConnection extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
playArbitraryFFmpeg(ffmpegOptions, volume, callback = function (err, str) { }) {
|
||||
playArbitraryFFmpeg(ffmpegOptions, options, callback = function (err, str) { }) {
|
||||
var self = this;
|
||||
self.stopPlaying();
|
||||
if (typeof volume === "function") {
|
||||
// volume is the callback
|
||||
callback = volume;
|
||||
}
|
||||
if (!ffmpegOptions instanceof Array) {
|
||||
ffmpegOptions = [];
|
||||
}
|
||||
var volume = volume !== undefined ? volume : this.getVolume();
|
||||
if (typeof options === "function") {
|
||||
// options is the callback
|
||||
callback = options;
|
||||
}
|
||||
if (typeof options !== "object") {
|
||||
options = {};
|
||||
}
|
||||
options.volume = options.volume !== undefined ? options.volume : this.getVolume();
|
||||
return new Promise((resolve, reject) => {
|
||||
this.encoder
|
||||
.encodeArbitraryFFmpeg(ffmpegOptions, volume)
|
||||
.catch(error)
|
||||
.encodeArbitraryFFmpeg(ffmpegOptions, options)
|
||||
.then(data => {
|
||||
self.streamProc = data.proc;
|
||||
self.instream = data.instream;
|
||||
var intent = self.playStream(data.stream);
|
||||
resolve(intent);
|
||||
callback(null, intent);
|
||||
});
|
||||
})
|
||||
.catch(error);
|
||||
function error(e = true) {
|
||||
reject(e);
|
||||
callback(e);
|
||||
|
||||
@@ -43,6 +43,7 @@ import ServerChannel from "./Structures/ServerChannel";
|
||||
import TextChannel from "./Structures/TextChannel";
|
||||
import User from "./Structures/User";
|
||||
import VoiceChannel from "./Structures/VoiceChannel";
|
||||
import Webhook from "./Structures/Webhook";
|
||||
import Constants from "./Constants";
|
||||
import Cache from "./Util/Cache.js";
|
||||
|
||||
@@ -60,6 +61,7 @@ export default {
|
||||
TextChannel,
|
||||
User,
|
||||
VoiceChannel,
|
||||
Webhook,
|
||||
Constants,
|
||||
Cache
|
||||
};
|
||||
|
||||
42661
web-dist/discord.8.2.0.js
Normal file
42661
web-dist/discord.8.2.0.js
Normal file
File diff suppressed because one or more lines are too long
21
web-dist/discord.min.8.2.0.js
Normal file
21
web-dist/discord.min.8.2.0.js
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user