From 68fd2ee9dd016fdab75ff98f369b84c4dc3c4670 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 30 Aug 2015 21:51:02 +0100 Subject: [PATCH] 3.1.4 - finalised message queueing --- README.md | 34 ++++++++++++++++++++++++++++++++++ lib/Client.js | 4 ++-- package.json | 2 +- src/Client.js | 4 ++-- test/bot.1.js | 2 +- 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f62b29c2e..c0a68bdaa 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,40 @@ Here is a list of other Discord APIs: --- +### Changes in 3.1.4 + +No, not π. But instead, pseduo-synchronous messaging was added! This means that +you can tell your Client to make a queue of "actions" per channel, and it will +work through them one by one. This is a really useful tool if you need to send +messages in a specific order without callback hell. + +It also allows you to store responses - such as created messages - in the returned +promise - named action. Example: + +```js +var mybot = new Discord.Client({ + queue : true //enable queueing, disabled by default +}); + +mybot.on("message", function(msg){ + + mybot.sendMessage(msg.channel, "this is message 1"); + var action = mybot.sendMessage(msg.channel, "this is message 2"); + mybot.sendMessage(msg.channel, "this is message 3").then(rmv); + + function rmv(){ + if(!action.error){ + mybot.deleteMessage(action.message); + } + } + +}); +``` + +This is still in development, and will see many more enhancements in future. + +--- + ### Links **[Documentation](https://github.com/discord-js/discord.js/wiki/Documentation)** diff --git a/lib/Client.js b/lib/Client.js index 059d09628..1c2bb688f 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -19,7 +19,7 @@ var WebSocket = require("ws"); var fs = require("fs"); var defaultOptions = { - queue: [] + queue: false }; var Client = (function () { @@ -35,7 +35,7 @@ var Client = (function () { further efforts will be made to connect. */ this.options = options; - this.options.queue = this.options.queue || []; + this.options.queue = this.options.queue; this.token = token; this.state = 0; this.websocket = null; diff --git a/package.json b/package.json index fd5043bcc..e5d2a0a8e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.1.3", + "version": "3.1.4", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { diff --git a/src/Client.js b/src/Client.js index 3d6523b78..31a16fdd9 100644 --- a/src/Client.js +++ b/src/Client.js @@ -13,7 +13,7 @@ var WebSocket = require("ws"); var fs = require("fs"); var defaultOptions = { - queue: [] + queue: false } class Client { @@ -25,7 +25,7 @@ class Client { further efforts will be made to connect. */ this.options = options; - this.options.queue = this.options.queue || []; + this.options.queue = this.options.queue; this.token = token; this.state = 0; this.websocket = null; diff --git a/test/bot.1.js b/test/bot.1.js index 2805bdc78..e9b9f9c9a 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -1,6 +1,6 @@ var Discord = require("../"); var mybot = new Discord.Client({ - queue: ["send"] + queue: true }); var fs = require("fs");