UNPKG

imubot

Version:
114 lines (98 loc) 3.46 kB
// Generated by CoffeeScript 1.12.6 (function() { var Response, slice = [].slice; Response = (function() { function Response(bot, message, match) { this.bot = bot; this.message = message; this.match = match; this.envelope = { room: this.message.room, user: this.message.user, message: this.message }; } Response.prototype.send = function() { var strings; strings = 1 <= arguments.length ? slice.call(arguments, 0) : []; return this.runWithMiddleware.apply(this, ["send", { plaintext: true }].concat(slice.call(strings))); }; Response.prototype.emote = function() { var strings; strings = 1 <= arguments.length ? slice.call(arguments, 0) : []; return this.runWithMiddleware.apply(this, ["emote", { plaintext: true }].concat(slice.call(strings))); }; Response.prototype.reply = function() { var strings; strings = 1 <= arguments.length ? slice.call(arguments, 0) : []; return this.runWithMiddleware.apply(this, ["reply", { plaintext: true }].concat(slice.call(strings))); }; Response.prototype.topic = function() { var strings; strings = 1 <= arguments.length ? slice.call(arguments, 0) : []; return this.runWithMiddleware.apply(this, ["topic", { plaintext: true }].concat(slice.call(strings))); }; Response.prototype.play = function() { var strings; strings = 1 <= arguments.length ? slice.call(arguments, 0) : []; return this.runWithMiddleware.apply(this, ["play"].concat(slice.call(strings))); }; Response.prototype.locked = function() { var strings; strings = 1 <= arguments.length ? slice.call(arguments, 0) : []; return this.runWithMiddleware.apply(this, ["locked", { plaintext: true }].concat(slice.call(strings))); }; Response.prototype.runWithMiddleware = function() { var callback, context, copy, methodName, opts, responseMiddlewareDone, runAdapterSend, strings; methodName = arguments[0], opts = arguments[1], strings = 3 <= arguments.length ? slice.call(arguments, 2) : []; callback = void 0; copy = strings.slice(0); if (typeof copy[copy.length - 1] === 'function') { callback = copy.pop(); } context = { response: this, strings: copy, method: methodName }; if (opts.plaintext != null) { context.plaintext = true; } responseMiddlewareDone = function() {}; runAdapterSend = (function(_this) { return function(_, done) { var ref, result; result = context.strings; if (callback != null) { result.push(callback); } (ref = _this.bot.adapter)[methodName].apply(ref, [_this.envelope].concat(slice.call(result))); return done(); }; })(this); return this.bot.middleware.response.execute(context, runAdapterSend, responseMiddlewareDone); }; Response.prototype.random = function(items) { return items[Math.floor(Math.random() * items.length)]; }; Response.prototype.finish = function() { return this.message.finish(); }; Response.prototype.http = function(url, options) { return this.bot.http(url, options); }; return Response; })(); module.exports = Response; }).call(this);