Example #1
0
    def bot_handle_url(self, m, origin,args, text, bot=None):
        if not bot:
            bot=self.bot
        url=m.group(2)
        ircbot.debug("url: ",m.group(2))

        prefix=m.group(1).strip()
        postfix=m.group(3).strip()
        if args[1]==bot.nick:
            channel="bot"
            target=origin.nick
        else:
            channel=args[1]
            target=args[1]
        nick=origin.nick
        title=None
        description=None
        tags=[]
        if prefix:
            if prefix[-1] == ":":
                title=prefix[:-1]
                if title.find(" ")==-1:
                    title=None
            else:
                tags.extend(prefix.split())
        if postfix:
            if postfix[0]==",":
                description=postfix[1:].strip()
            else:
                tags.extend(postfix.split())
        urlobject=UrlObject(url,title=title,tags=tags,description=description,channel=channel,nick=nick)
        urlobject.target=target
        titlefetch=FetchURL(urlobject,self)
        if not titlefetch.connect():
			self.add_url(urlobject)
Example #2
0
 def handle_data(self):
     ircbot.debug("Got connection. path: ", self.path)
     self.send_response(200)
     self.send_header("Content-type", "text/html")
     self.end_headers()
     self.wfile.write(htmlheader)
     for url in urllist:
         self.wfile.write('<li><a href="%s">%s</a></li>\n' % (url, url))
     self.wfile.write(htmlfooter)
Example #3
0
 def __init__(self, url, urlhandler):
     urlelements=list(urlparse.urlparse(url.url))
     ircbot.debug(urlelements,url.url)
     if urlelements[0] != "http":
         self.do_connect=False
         return
     self.do_connect=True
     self.url=url
     self.urlhandler=urlhandler
     hosttuple=urlelements[1].split(":")
     host=hosttuple[0]
     if len(hosttuple)==2:
         port=int(hosttuple[1])
     else:
         port=80
     asynchttp.AsyncHTTPConnection.__init__(self,host,port)
     urlelements[0]=""
     urlelements[1]=""
     self._path=urlparse.urlunparse(urlelements)
Example #4
0
 def handle_response(self):
     title=None
     contenttype=self.response.getheader("Content-Type").split(";")[0].strip()
     try:
         quiet=self.bot.quiet
     except:
         quiet=0
     ircbot.debug("content type",contenttype)
     if contenttype=="text/html":
         if self.command=="GET":
             title=self.handle_html()
         else:
             self.handle_command("GET")
             return
     else:
         title="%s file: %s" % (contenttype,self.url)
     ircbot.debug("Title",title)
     id=add_url(self.url,self.nick,self.target,title)
     ircbot.debug("id",id)
     if not quiet:
         if not title:
             title=self.url
         if self.target == "links":
             self.bot.safeMsg(self.nick,["url%d, %s"%(id,title)])
         else:
             self.bot.safeMsg(self.target,["url%d, %s"%(id,title)])
     self.close()
Example #5
0
 def handle_response(self):
     title=None
     contenttype=self.response.getheader("Content-Type").split(";")[0].strip()
     ircbot.debug("content type",contenttype)
     if contenttype=="text/html":
         if self.command=="GET":
             title=self.handle_html()
         else:
             self.handle_command("GET")
             return
     else:
         title="%s file: %s" % (contenttype,self.url.url)
     ircbot.debug("Title",title)
     self.url.title=title
     self.urlhandler.add_url(self.url)
     ircbot.debug("id",id)
     self.close()
Example #6
0
 def handle_command(self,command):
     ircbot.debug("Handle command",command)
     self.command=command
     self.putrequest(command,self._path)
     self.endheaders()
     self.getresponse()