diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-02-22 23:14:43 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-02-22 23:14:43 +0100 |
commit | 6d1fa0e753073a00d9075227a6474f855157fc5d (patch) | |
tree | 17d56ea921443174393954d237e7563779f0f3e7 /module/plugins/hooks/IRCInterface.py | |
parent | filesonic info prefetching + premium fix (diff) | |
download | pyload-6d1fa0e753073a00d9075227a6474f855157fc5d.tar.xz |
captcha input via IRC, XMPP
Diffstat (limited to 'module/plugins/hooks/IRCInterface.py')
-rw-r--r-- | module/plugins/hooks/IRCInterface.py | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/module/plugins/hooks/IRCInterface.py b/module/plugins/hooks/IRCInterface.py index 22863916b..31d693018 100644 --- a/module/plugins/hooks/IRCInterface.py +++ b/module/plugins/hooks/IRCInterface.py @@ -21,13 +21,16 @@ from select import select import socket -import sys from threading import Thread import time from time import sleep from traceback import print_exc +import re from module.plugins.Hook import Hook +from module.network.RequestFactory import getURL + +from pycurl import FORM_FILE class IRCInterface(Thread, Hook): __name__ = "IRCInterface" @@ -41,7 +44,8 @@ class IRCInterface(Thread, Hook): ("nick", "str", "Nickname the Client will take", "pyLoad-IRC"), ("owner", "str", "Nickname the Client will accept commands from", "Enter your nick here!"), ("info_file", "bool", "Inform about every file finished", "False"), - ("info_pack", "bool", "Inform about every package finished", "True")] + ("info_pack", "bool", "Inform about every package finished", "True"), + ("captcha", "bool", "Send captcha requests", "True")] __author_name__ = ("Jeix") __author_mail__ = ("Jeix@hasnomail.com") @@ -75,7 +79,18 @@ class IRCInterface(Thread, Hook): self.response(_("Download finished: %(name)s @ %(plugin)s ") % { "name" : pyfile.name, "plugin": pyfile.pluginname} ) except: pass - + + def newCaptchaTask(self, task): + if self.getConfig("captcha"): + task.handler.append(self) + task.setWaiting(60) + + page = getURL("http://www.freeimagehosting.net/upload.php", post={"attached" : (FORM_FILE, task.captchaFile)}, multipart=True) + + url = re.search(r"\[url=http://www.freeimagehosting.net/\]\[img\]([^\[]+)\[/img\]\[/url\]", page).group(1) + self.response(_("New Captcha Request: %s") % url) + self.response(_("Answer with 'c %s text on the captcha'") % task.id) + def run(self): # connect to IRC etc. self.sock = socket.socket() @@ -162,12 +177,15 @@ class IRCInterface(Thread, Hook): trigger = "pass" args = None - - temp = msg["text"].split() - trigger = temp[0] - if len(temp) > 1: - args = temp[1:] - + + try: + temp = msg["text"].split() + trigger = temp[0] + if len(temp) > 1: + args = temp[1:] + except: + pass + handler = getattr(self, "event_%s" % trigger, self.event_pass) try: res = handler(args) @@ -360,7 +378,7 @@ class IRCInterface(Thread, Hook): def event_pull(self, args): if not args: - return ["ERROR: Pull package from queue like this: pull <package id>"] + return ["ERROR: Pull package from queue like this: pull <package id>."] id = int(args[0]) if not self.sm.get_package_data(id): @@ -369,6 +387,19 @@ class IRCInterface(Thread, Hook): self.sm.pull_out_package(id) return ["INFO: Pulled package #%d from queue to collector." % id] + def event_c(self, args): + """ captcha answer """ + if not args: + return ["ERROR: Captcha ID missing."] + + task = self.core.captchaManager.getTaskByID(args[0]) + if not task: + return ["ERROR: Captcha Task with ID %s does not exists." % args[0]] + + task.setResult(" ".join(args[1:])) + return ["INFO: Result %s saved." % " ".join(args[1:])] + + def event_help(self, args): lines = [] lines.append("The following commands are available:") |