Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mrDoctorWho/vk4xmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrDoctorWho <mrdoctorwho@gmail.com>2015-04-15 15:47:29 +0300
committermrDoctorWho <mrdoctorwho@gmail.com>2015-04-15 15:47:29 +0300
commit57e4db68cd28d7d6400e93016ef9755bdefcb484 (patch)
treeca88f200e3ec0c40e20b36640c0edce585a5ebec
parent8403a2e20875a6b286a9c52601460771f150673f (diff)
Add alive_keeper extension
Replace URL_VCARD_NO_IMAGE in the config by a new URL
-rw-r--r--Config_example.txt2
-rw-r--r--extensions/alive_keeper.py41
-rw-r--r--extensions/avatar_hash.py1
-rw-r--r--gateway.py10
4 files changed, 49 insertions, 5 deletions
diff --git a/Config_example.txt b/Config_example.txt
index dfd1d76..781a83b 100644
--- a/Config_example.txt
+++ b/Config_example.txt
@@ -64,7 +64,7 @@ THREAD_STACK_SIZE = 0
MAXIMUM_FORWARD_DEPTH = 20
## Image that will be used if the transport can't recieve image from VK.
-URL_VCARD_NO_IMAGE = "http://simpleapps.ru/vk4xmpp.png"
+URL_VCARD_NO_IMAGE = "https://raw.githubusercontent.com/mrDoctorWho/vk4xmpp/master/vk4xmpp.png"
## Eval JID (JID for "!eval" command and admin-features in adhoc).
ADMIN_JIDS = []
diff --git a/extensions/alive_keeper.py b/extensions/alive_keeper.py
new file mode 100644
index 0000000..60501f8
--- /dev/null
+++ b/extensions/alive_keeper.py
@@ -0,0 +1,41 @@
+# coding: utf-8
+# Code © WitcherGeralt, 2012.
+# Originally coded for BlackSmith bot mark.2
+## Installation:
+## Add a field named ALIVE_KEEPER_ENABLED in the main config file and set it's value to True in order to enable the keeper.
+
+"""
+Makes the transport ping itself, so it can detect connection hang
+It's also can be useful for Openfire administrators
+in case if the transport suddenly disconnects
+"""
+
+isdef = lambda var: var in globals()
+
+def alive_keeper():
+ logger.debug("alive_keeper has started!")
+
+ def alive_keeper_answer(cl, stanza):
+ logger.debug("alive_keeper: answer received, continuing iteration")
+ Component.aKeeper = 0
+
+ while True:
+ time.sleep(60)
+ thrIds = [x.name for x in threading.enumerate()]
+ if not hasattr(Component, "aKeeper"):
+ Component.aKeeper = 0
+
+ if Component.aKeeper > 3:
+ logger.error("alive_keeper: answer wasn't received more than 3 times!")
+ Print("No answer from the server, restarting...")
+ disconnectHandler()
+ else:
+ logger.debug("alive_keeper: sending request")
+ Component.aKeeper += 1
+ iq = xmpp.Iq("get", to=TransportID, frm=TransportID)
+ iq.addChild("ping", namespace=xmpp.NS_PING)
+ sender(Component, iq, cb=alive_keeper_answer)
+
+
+if isdef("ALIVE_KEEPER_ENABLED") and ALIVE_KEEPER_ENABLED:
+ registerHandler("evt01", alive_keeper) \ No newline at end of file
diff --git a/extensions/avatar_hash.py b/extensions/avatar_hash.py
index 768ab28..be79f2b 100644
--- a/extensions/avatar_hash.py
+++ b/extensions/avatar_hash.py
@@ -18,6 +18,7 @@ def makePhotoHash(user, list=None):
Parameters:
list is a list of user ids to make hash from
"""
+ list = list or []
if user.settings.avatar_hash:
photos = []
if not list:
diff --git a/gateway.py b/gateway.py
index f42200b..6c6533a 100644
--- a/gateway.py
+++ b/gateway.py
@@ -451,7 +451,10 @@ class VK(object):
"""
if not self.pollInitialzed:
raise api.LongPollError("The Poll wasn't initialized yet")
- return self.engine.RIP.getOpener(self.pollServer, self.pollConfig)
+ opener = self.engine.RIP.getOpener(self.pollServer, self.pollConfig)
+ if not opener:
+ raise api.LongPollError("Poll request failed")
+ return opener
def method(self, method, args=None, nodecode=False, force=False):
"""
@@ -1189,7 +1192,7 @@ def getPid():
if os.path.exists(pidFile):
oldPid = rFile(pidFile)
if oldPid:
- Print("#-# Killing old transport instance: ", False)
+ Print("#-# Killing the previous instance: ", False)
oldPid = int(oldPid)
if pid != oldPid:
try:
@@ -1248,8 +1251,7 @@ class ModuleLoader:
if name in sys.modules:
module = sys.modules[name]
cls.__unregister(module)
- reload(module)
- return module
+ return reload(module)
@classmethod