@ -5,6 +5,7 @@ export default function poll(bot) {
|
||||
}
|
||||
bot.emit('update', response.result);
|
||||
|
||||
if (bot._stop) return null;
|
||||
return poll(bot);
|
||||
});
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ export default function webhook(options = {}, bot) {
|
||||
|
||||
return bot.api.setWebhook(options.url).then(() => {
|
||||
|
||||
https.createServer(options.server, (req, res) => {
|
||||
bot._webhookServer = https.createServer(options.server, (req, res) => {
|
||||
return getBody(req).then(data => {
|
||||
bot.emit('update', qs.parse(data).result);
|
||||
|
||||
|
16
lib/index.js
16
lib/index.js
@ -133,6 +133,20 @@ export default class Bot extends EventEmitter {
|
||||
return message.send(this).catch(console.error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the bot, deattaching all listeners and polling
|
||||
*/
|
||||
stop() {
|
||||
this._stop = true;
|
||||
|
||||
if (this._webhookServer) {
|
||||
this._webhookServer.close();
|
||||
}
|
||||
|
||||
this.removeListener('update', this._update);
|
||||
this._events = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* The internal update event listener, used to parse messages and fire
|
||||
* command/get events - YOU SHOULD NOT USE THIS
|
||||
@ -148,8 +162,6 @@ export default class Bot extends EventEmitter {
|
||||
this.update.offset += 1;
|
||||
}
|
||||
|
||||
console.log(update);
|
||||
|
||||
update.forEach(res => {
|
||||
let text = res.message.text;
|
||||
if (!text) return;
|
||||
|
Reference in New Issue
Block a user