@ -12,6 +12,7 @@ function poll(bot) {
|
||||
}
|
||||
bot.emit('update', response.result);
|
||||
|
||||
if (bot._stop) return null;
|
||||
return poll(bot);
|
||||
});
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ function webhook(options, bot) {
|
||||
|
||||
return bot.api.setWebhook(options.url).then(function () {
|
||||
|
||||
_http2['default'].createServer(options.server, function (req, res) {
|
||||
bot._webhookServer = _http2['default'].createServer(options.server, function (req, res) {
|
||||
return (0, _fetch.getBody)(req).then(function (data) {
|
||||
bot.emit('update', _qs2['default'].parse(data).result);
|
||||
|
||||
|
@ -182,6 +182,22 @@ var Bot = (function (_EventEmitter) {
|
||||
value: function send(message) {
|
||||
return message.send(this)['catch'](console.error);
|
||||
}
|
||||
}, {
|
||||
key: 'stop',
|
||||
|
||||
/**
|
||||
* Stops the bot, deattaching all listeners and polling
|
||||
*/
|
||||
value: function stop() {
|
||||
this._stop = true;
|
||||
|
||||
if (this._webhookServer) {
|
||||
this._webhookServer.close();
|
||||
}
|
||||
|
||||
this.removeListener('update', this._update);
|
||||
this._events = {};
|
||||
}
|
||||
}, {
|
||||
key: '_update',
|
||||
|
||||
@ -202,8 +218,6 @@ var Bot = (function (_EventEmitter) {
|
||||
this.update.offset += 1;
|
||||
}
|
||||
|
||||
console.log(update);
|
||||
|
||||
update.forEach(function (res) {
|
||||
var marked3$0 = [getAnswer].map(regeneratorRuntime.mark);
|
||||
|
||||
|
Reference in New Issue
Block a user