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>2014-08-11 23:38:49 +0400
committermrDoctorWho <mrdoctorwho@gmail.com>2014-08-11 23:38:49 +0400
commitfe7335e6f112711071290ace677491c250ea7f20 (patch)
treec6075ea4095f4386af85661162bbea3c61d63c8b /modules/mod_msg_main.py
parent7945dafd82660db0a61a33c293094c6366cde2e1 (diff)
A huge refactoring just happened to transport.
Deleted all handlers and now they're separately stored in the modules directory Added js sources which transport uses instead of local handling Fixed couple typos in translations Forward messages now have things called "spacers" in start of line Users is now handling in separate threads And there are more changes...
Diffstat (limited to 'modules/mod_msg_main.py')
-rw-r--r--modules/mod_msg_main.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/modules/mod_msg_main.py b/modules/mod_msg_main.py
new file mode 100644
index 0000000..6302d13
--- /dev/null
+++ b/modules/mod_msg_main.py
@@ -0,0 +1,97 @@
+# coding: utf-8
+# This file is a part of VK4XMPP transport
+# © simpleApps, 2013 — 2014.
+
+from __main__ import *
+from __main__ import _
+
+def reportReceived(msg, jidFrom, jidTo):
+ if msg.getTag("request"):
+ answer = xmpp.Message(jidFrom)
+ tag = answer.setTag("received", namespace = "urn:xmpp:receipts")
+ tag.setAttr("id", msg.getID())
+ answer.setFrom(jidTo)
+ answer.setID(msg.getID())
+ return answer
+
+def captchaAccept(cl, args, jidTo, source):
+ if args:
+ answer = None
+ user = Transport[source]
+ if user.vk.engine.captcha:
+ logger.debug("user %s called captcha challenge" % source)
+ user.vk.engine.captcha["key"] = args
+ success = False
+ try:
+ logger.debug("retrying for user %s" % source)
+ success = user.vk.engine.retry()
+ except api.CaptchaNeeded:
+ logger.error("retry for user %s failed!" % source)
+ user.vk.captchaChallenge()
+ if success:
+ logger.debug("retry for user %s successed!" % source)
+ answer = _("Captcha valid.")
+ Presence = xmpp.Presence(source, frm = TransportID)
+ Presence.setShow("available")
+ sender(Component, Presence)
+ user.tryAgain()
+ else:
+ answer = _("Captcha invalid.")
+ else:
+ answer = _("Not now. Ok?")
+ if answer:
+ msgSend(cl, source, jidTo, answer)
+
+
+def message_handler(cl, msg):
+ mType = msg.getType()
+ body = msg.getBody()
+ jidTo = msg.getTo()
+ destination = jidTo.getStripped()
+ jidFrom = msg.getFrom()
+ source = jidFrom.getStripped()
+
+ if source in Transport:
+ user = Transport[source]
+ if msg.getTag("composing"):
+ target = vk2xmpp(destination)
+ if target != TransportID:
+ user.vk.method("messages.setActivity", {"user_id": target, "type": "typing"}, True)
+
+ if body:
+ answer = None
+ if jidTo == TransportID:
+ raw = body.split(None, 1)
+ if len(raw) > 1:
+ text, args = raw
+ args = args.strip()
+ if text == "!captcha" and args:
+ captchaAccept(cl, args, jidTo, source)
+ answer = reportReceived(msg, jidFrom, jidTo)
+ elif text == "!eval" and args and source == evalJID:
+ try:
+ result = unicode(eval(args))
+ except Exception:
+ result = returnExc()
+ sendMessage(cl, source, jidTo, result)
+ elif text == "!exec" and args and source == evalJID:
+ try:
+ exec(unicode(args + "\n"), globals())
+ except Exception:
+ result = returnExc()
+ else:
+ result = "Done."
+ msgSend(cl, source, jidTo, result)
+ else:
+ uID = jidTo.getNode()
+ vkMessage = user.msg(body, uID)
+ if vkMessage:
+ answer = msgRecieved(msg, jidFrom, jidTo)
+ if answer:
+ sender(cl, answer)
+ for func in Handlers["msg02"]:
+ func(msg)
+
+
+def load():
+ Component.RegisterHandler("message", message_handler, "chat") \ No newline at end of file