mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 12:03:31 +01:00
started working on bug fixes and test scripts
This commit is contained in:
@@ -242,7 +242,7 @@ var InternalClient = (function () {
|
|||||||
return _superagent2["default"].post(_Constants.Endpoints.SERVERS).set("authorization", this.token).send({ name: name, region: region }).end().then(function (res) {
|
return _superagent2["default"].post(_Constants.Endpoints.SERVERS).set("authorization", this.token).send({ name: name, region: region }).end().then(function (res) {
|
||||||
// valid server, wait until it is cached
|
// valid server, wait until it is cached
|
||||||
return waitFor(function () {
|
return waitFor(function () {
|
||||||
return _this4.servers.get("id", res.body.guild.id);
|
return _this4.servers.get("id", res.body.id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -521,8 +521,9 @@ var InternalClient = (function () {
|
|||||||
var channel;
|
var channel;
|
||||||
if (res.body.type === "text") {
|
if (res.body.type === "text") {
|
||||||
channel = new _StructuresTextChannel2["default"](res.body, _this16.client, server);
|
channel = new _StructuresTextChannel2["default"](res.body, _this16.client, server);
|
||||||
|
} else {
|
||||||
|
channel = new _StructuresVoiceChannel2["default"](res.body, _this16.client, server);
|
||||||
}
|
}
|
||||||
channel = new _StructuresVoiceChannel2["default"](res.body, _this16.client, server);
|
|
||||||
return server.channels.add(_this16.channels.add(channel));
|
return server.channels.add(_this16.channels.add(channel));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -1011,7 +1012,6 @@ var InternalClient = (function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.websocket.onmessage = function (e) {
|
this.websocket.onmessage = function (e) {
|
||||||
|
|
||||||
if (e.type === "Binary") {
|
if (e.type === "Binary") {
|
||||||
if (!zlib) zlib = require("zlib");
|
if (!zlib) zlib = require("zlib");
|
||||||
e.data = zlib.inflateSync(e.data).toString();
|
e.data = zlib.inflateSync(e.data).toString();
|
||||||
@@ -1027,7 +1027,6 @@ var InternalClient = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
client.emit("raw", packet);
|
client.emit("raw", packet);
|
||||||
|
|
||||||
switch (packet.t) {
|
switch (packet.t) {
|
||||||
|
|
||||||
case _Constants.PacketType.READY:
|
case _Constants.PacketType.READY:
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ var Cache = (function (_Array) {
|
|||||||
return found;
|
return found;
|
||||||
};
|
};
|
||||||
|
|
||||||
Cache.prototype.has = function has(key, value) {
|
Cache.prototype.has = function has(object) {
|
||||||
return !!this.get(key, value);
|
return !!this.get(this.discrim, object[this.discrim]);
|
||||||
};
|
};
|
||||||
|
|
||||||
Cache.prototype.getAll = function getAll(key, value) {
|
Cache.prototype.getAll = function getAll(key, value) {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "discord.js",
|
"name": "discord.js",
|
||||||
"version": "5.0.1",
|
"version": "5.0.2",
|
||||||
"description": "A way to interface with the Discord API",
|
"description": "A way to interface with the Discord API",
|
||||||
"main": "./entrypoint.js",
|
"main": "./entrypoint.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node ./test/bot.js"
|
"test": "eslint *.js lib test && node test/lib-test.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -31,11 +31,13 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-preset-es2015": "^6.1.18",
|
"babel-preset-es2015": "^6.1.18",
|
||||||
"babel-preset-es2015-loose": "^6.1.2",
|
"babel-preset-es2015-loose": "^6.1.2",
|
||||||
|
"colors": "^1.1.2",
|
||||||
"grunt": "~0.4.5",
|
"grunt": "~0.4.5",
|
||||||
"grunt-babel": "<6.0.0",
|
"grunt-babel": "<6.0.0",
|
||||||
"grunt-browserify": "^4.0.0",
|
"grunt-browserify": "^4.0.0",
|
||||||
"grunt-contrib-uglify": "^0.9.2",
|
"grunt-contrib-uglify": "^0.9.2",
|
||||||
"load-grunt-tasks": "^3.2.0"
|
"load-grunt-tasks": "^3.2.0",
|
||||||
|
"mocha": "^2.3.4"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"node-opus": "^0.1.11"
|
"node-opus": "^0.1.11"
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ export default class InternalClient {
|
|||||||
.end()
|
.end()
|
||||||
.then(res => {
|
.then(res => {
|
||||||
// valid server, wait until it is cached
|
// valid server, wait until it is cached
|
||||||
return waitFor(() => this.servers.get("id", res.body.guild.id));
|
return waitFor(() => this.servers.get("id", res.body.id));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -447,8 +447,9 @@ export default class InternalClient {
|
|||||||
var channel;
|
var channel;
|
||||||
if (res.body.type === "text") {
|
if (res.body.type === "text") {
|
||||||
channel = new TextChannel(res.body, this.client, server);
|
channel = new TextChannel(res.body, this.client, server);
|
||||||
|
}else{
|
||||||
|
channel = new VoiceChannel(res.body, this.client, server);
|
||||||
}
|
}
|
||||||
channel = new VoiceChannel(res.body, this.client, server);
|
|
||||||
return server.channels.add(this.channels.add(channel));
|
return server.channels.add(this.channels.add(channel));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -941,7 +942,6 @@ export default class InternalClient {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.websocket.onmessage = e => {
|
this.websocket.onmessage = e => {
|
||||||
|
|
||||||
if (e.type === "Binary") {
|
if (e.type === "Binary") {
|
||||||
if (!zlib) zlib = require("zlib");
|
if (!zlib) zlib = require("zlib");
|
||||||
e.data = zlib.inflateSync(e.data).toString();
|
e.data = zlib.inflateSync(e.data).toString();
|
||||||
@@ -957,7 +957,6 @@ export default class InternalClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
client.emit("raw", packet);
|
client.emit("raw", packet);
|
||||||
|
|
||||||
switch (packet.t) {
|
switch (packet.t) {
|
||||||
|
|
||||||
case PacketType.READY:
|
case PacketType.READY:
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ export default class Cache extends Array {
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
has(key, value) {
|
has(object) {
|
||||||
return !!this.get(key, value);
|
return !!this.get(this.discrim, object[this.discrim]);
|
||||||
}
|
}
|
||||||
|
|
||||||
getAll(key, value) {
|
getAll(key, value) {
|
||||||
|
|||||||
163
test/lib-test.js
Normal file
163
test/lib-test.js
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
/* global describe */
|
||||||
|
/* global process */
|
||||||
|
|
||||||
|
var Discord = require("../");
|
||||||
|
var client = new Discord.Client();
|
||||||
|
var colors = require("colors");
|
||||||
|
|
||||||
|
var passes = 0, fails = 0;
|
||||||
|
|
||||||
|
function section(s) {
|
||||||
|
console.log("\n " + s.yellow);
|
||||||
|
}
|
||||||
|
|
||||||
|
function pass(msg) {
|
||||||
|
console.log(" ✓ ".green + msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
function err(msg) {
|
||||||
|
console.log(" ✗ ".red + msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Beginning Lib Test".yellow);
|
||||||
|
|
||||||
|
section("Logging In");
|
||||||
|
|
||||||
|
client.on("ready", () => {
|
||||||
|
pass("received ready");
|
||||||
|
|
||||||
|
makeServer();
|
||||||
|
})
|
||||||
|
|
||||||
|
client.login(process.env["ds_email"], process.env["ds_password"]).then(token => {
|
||||||
|
|
||||||
|
if (!token || token.length < 1) {
|
||||||
|
err("bad token");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pass("valid login token");
|
||||||
|
|
||||||
|
}).catch(e => err("error logging in: " + e));
|
||||||
|
|
||||||
|
var server, channel, message;
|
||||||
|
|
||||||
|
function makeServer() {
|
||||||
|
|
||||||
|
section("Server Creation");
|
||||||
|
client.createServer("test", "london").then(srv => {
|
||||||
|
|
||||||
|
if (!srv) {
|
||||||
|
err("server not passed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (srv.name !== "test" || srv.region !== "london") {
|
||||||
|
err("invalid server name/region");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!srv.members.has(client.user)) {
|
||||||
|
console.log(srv.members);
|
||||||
|
err("client not included in members list");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pass("created server");
|
||||||
|
pass("valid server name & region");
|
||||||
|
pass("client included in server members");
|
||||||
|
|
||||||
|
server = srv;
|
||||||
|
|
||||||
|
makeChannel();
|
||||||
|
|
||||||
|
}).catch(e => {
|
||||||
|
err("couldn't create server: " + e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeChannel() {
|
||||||
|
section("Channel Creation");
|
||||||
|
|
||||||
|
client.createChannel(server, "testchannel", "text").then(chann => {
|
||||||
|
|
||||||
|
if (!chann) {
|
||||||
|
err("channel not passed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chann.name !== "testchannel" || chann.type !== "text") {
|
||||||
|
err("invalid channel name/type");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pass("channel created");
|
||||||
|
pass("valid channel name & type");
|
||||||
|
|
||||||
|
channel = chann;
|
||||||
|
|
||||||
|
editChannel();
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function editChannel() {
|
||||||
|
section("Channel Editting");
|
||||||
|
|
||||||
|
client.setChannelNameAndTopic(channel, "testing", "a testing channel - temporary").then(() => {
|
||||||
|
|
||||||
|
if (channel.name !== "testing" || channel.topic !== "a testing channel - temporary") {
|
||||||
|
err("channel not updated");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pass("channel name and topic updated");
|
||||||
|
|
||||||
|
sendMsg();
|
||||||
|
|
||||||
|
}).catch(e => {
|
||||||
|
err("error editting channel: " + e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendMsg() {
|
||||||
|
section("Message Creation");
|
||||||
|
|
||||||
|
client.sendMessage(channel, "test message!", { tts: true }).then(msg => {
|
||||||
|
|
||||||
|
if (!msg) {
|
||||||
|
err("message not passed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.content !== "test message!" || !msg.sender.equals(client.user) || !msg.channel.equals(channel)) {
|
||||||
|
err("invalid content, sender or channel assigned to message");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!msg.tts) {
|
||||||
|
err("message wasn't TTS on response, even though on request it was");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pass("message successfully created");
|
||||||
|
pass("correct parameters in message");
|
||||||
|
|
||||||
|
message = msg;
|
||||||
|
|
||||||
|
editMsg();
|
||||||
|
|
||||||
|
}).catch(e => {
|
||||||
|
err("error sending message: " + e)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function editMsg() {
|
||||||
|
|
||||||
|
section("Message Manipulation");
|
||||||
|
|
||||||
|
client.updateMessage(message, client.user + channel + server).then(msg => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user