Assembla home | Assembla project page
 

Changeset 37

Show
Ignore:
Timestamp:
02/10/08 17:59:32 (10 months ago)
Author:
tobias382
Message:

Fixes #10
* Added the UrbanDictionary? plugin
* Added a check to the Acronym plugin for server timeouts

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Phergie/Event/Handler/Acronym.php

    r34 r37  
    2323    { 
    2424        if ($event->getNick() != $this->getConnection()->getNick()) { 
     25            $channel = $event->getArgument(0); 
     26 
    2527            preg_match_all('/([A-Z]{2,}+)\\?/', $event->getArgument(1), $acronyms); 
    2628 
     
    3436                ); 
    3537                $context = stream_context_create($opts);  
    36                 $contents = file_get_contents('http://silmaril.ie/cgi-bin/uncgi/acronyms', false, $context); 
     38                $contents = @file_get_contents('http://silmaril.ie/cgi-bin/uncgi/acronyms', false, $context); 
    3739 
    38                 $start = stripos($contents, '<dl>'); 
    39                 $end = stripos($contents, '</dl>', $start); 
    40                 $contents = substr($contents, $start, $end - $start); 
    41                 preg_match_all('/<dd><b><a[^>]+>([^<]+)/', $contents, $matches); 
     40                if ($contents === false) { 
     41                    $this->doPrivmsg($channel, 'Sorry, the acronym database seems to be down right now.'); 
     42                } else { 
     43                    $start = stripos($contents, '<dl>'); 
     44                    $end = stripos($contents, '</dl>', $start); 
     45                    $contents = substr($contents, $start, $end - $start); 
     46                    preg_match_all('/<dd><b><a[^>]+>([^<]+)/', $contents, $matches); 
    4247 
    43                 $matches = array_unique($matches[1]); 
    44                 if ($this->_limit != 0) { 
    45                     $matches = array_slice($matches, 0, $this->_limit); 
     48                    $matches = array_unique($matches[1]); 
     49                    if ($this->_limit != 0) { 
     50                        $matches = array_slice($matches, 0, $this->_limit); 
     51                    } 
     52                    $text = 'Possible matches for ' . $acronym . ': ' . implode(', ', $matches);  
     53                    $this->doPrivmsg($channel, $text);  
    4654                } 
    47                 $text = 'Possible matches for ' . $acronym . ': ' . implode(', ', $matches);  
    48                 $this->doPrivmsg($event->getArgument(0), $text);  
    4955            } 
    5056        }