Fix long-polling
This commit is contained in:
@ -188,13 +188,13 @@ var Bot = (function (_EventEmitter) {
|
||||
|
||||
update.forEach(function (res) {
|
||||
var text = res.message.text;
|
||||
if (text.startsWith('/')) {
|
||||
var selfUsername = '@' + _this2.info.username;
|
||||
|
||||
if (text.startsWith('/') && text.indexOf(selfUsername) > -1) {
|
||||
// Commands are sent in /command@thisusername format in groups
|
||||
var regex = new RegExp('(/.*)@' + _this2.info.username);
|
||||
text = text.replace(regex, '$1');
|
||||
res.message.text = text;
|
||||
|
||||
console.log(res.message.text);
|
||||
}
|
||||
|
||||
var ev = _this2._userEvents.find(function (_ref) {
|
||||
|
@ -7,21 +7,13 @@ exports['default'] = poll;
|
||||
|
||||
function poll(bot) {
|
||||
return bot.api.getUpdates(bot.update).then(function (response) {
|
||||
var again = wait(bot.update.timeout * 1000, bot).then(poll);
|
||||
if (!response.result.length) {
|
||||
return again;
|
||||
return poll(bot);
|
||||
}
|
||||
bot.emit('update', response.result);
|
||||
|
||||
return again;
|
||||
return poll(bot);
|
||||
});
|
||||
}
|
||||
|
||||
var wait = function wait(miliseconds, value) {
|
||||
return new Promise(function (resolve) {
|
||||
setTimeout(function () {
|
||||
resolve(value);
|
||||
}, miliseconds);
|
||||
});
|
||||
};
|
||||
module.exports = exports['default'];
|
||||
|
Reference in New Issue
Block a user