From 41f4181c1a183c8870cefacb51f393611cbe1640 Mon Sep 17 00:00:00 2001 From: Adhidarma Hadiwinoto <me@adhisimon.org> Date: Sun, 26 Aug 2018 09:14:24 +0700 Subject: [PATCH] Pemanasan saat awal --- transport-telegram.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/transport-telegram.js b/transport-telegram.js index d910ac3..fa1efa0 100644 --- a/transport-telegram.js +++ b/transport-telegram.js @@ -3,12 +3,14 @@ const TelegramBot = require('node-telegram-bot-api'); const LRU = require('lru-cache'); -const config = require('komodo-sdk/config') +const config = require('komodo-sdk/config'); const logger = require('komodo-sdk/logger'); let bot; let _callback; +let isReady = false; + const chats = LRU({ max: config.max_chats || 200, maxAge: 1000 * 3600 @@ -17,6 +19,11 @@ const chats = LRU({ function onMessage(msg) { //console.log(msg); + if (!isReady) { + logger.info('Pesan diabaikan karena center belum siap (masih melakukan pemanasan)'); + return; + } + const now = Math.floor(new Date().getTime()/1000); const age = now - msg.date; @@ -52,6 +59,13 @@ function init(cb) { bot = new TelegramBot(config.transport.token, {polling: true}); bot.on('message', onMessage); + + setTimeout( + function() { + isReady = true; + }, + 60 * 1000 + ); } function send(partner, msg) { -- 1.9.0