From 7458497759b9b68ceda8a03baa511f01b0692947 Mon Sep 17 00:00:00 2001
From: Adhidarma Hadiwinoto <me@adhisimon.org>
Date: Thu, 4 Aug 2016 09:19:02 +0700
Subject: [PATCH] pingMySelf

---
 index.js | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/index.js b/index.js
index e73e984..b130c8d 100644
--- a/index.js
+++ b/index.js
@@ -34,6 +34,13 @@ var logger = new (winston.Logger)({
   ]
 });
 
+function pingMySelf() {
+    if (warming_up) {
+        return;
+    }
+
+    sendMessage(config.globals.jid, "PING " + strftime('%F %T', new Date()));
+}
 
 function xmppConnect() {
     logger.info('Connecting to XMPP server');
@@ -73,7 +80,10 @@ function createHttpListener() {
 }
 
 function sendMessage(destination, message) {
-    logger.info('Sending xmpp message', {from: config.globals.jid, to: destination, message: message});
+    if (destination != config.globals.jid) {
+        logger.info('Sending xmpp message', {from: config.globals.jid, to: destination, message: message});
+    }
+
     xmpp.send(destination, message);
 }
 
@@ -114,6 +124,10 @@ xmpp.on('online', function(data) {
 });
 
 xmpp.on('chat', function(from, message) {
+    if (from == config.globals.jid) {
+        return;
+    }
+
     logger.info('Incoming message via XMPP ', {to: config.globals.jid, from: from, message: message});
 
     if (warming_up) {
@@ -141,3 +155,5 @@ xmpp.on('subscribe', function(from) {
 
 createHttpListener();
 xmppConnect();
+
+setInterval(pingMySelf, 60000);
-- 
1.9.0