Assembla home | Assembla project page
 

Changeset 258

Show
Ignore:
Timestamp:
06/21/08 19:02:14 (5 months ago)
Author:
Slynderdale
Message:

Fixes #38 by checking actions for spelling corrections as well as added support to retrieve and check the spelling for words using CTCP messages to the bot.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Phergie/Plugin/Spellcheck.php

    r248 r258  
    145145        } 
    146146    } 
     147 
     148    /** 
     149     * Parses incoming CTCP action requests for spelling suggestions. 
     150     * 
     151     * @return void 
     152     */ 
     153    public function onAction() 
     154    { 
     155        $message = $this->event->getArgument(1); 
     156        $target = $this->event->getNick(); 
     157 
     158        if (preg_match('#(\S+)\s*\(sp\??\)#i', $message, $m)) { 
     159            $word = $m[1]; 
     160            if (!pspell_check($this->pspell, $word)) { 
     161                $suggestions = pspell_suggest($this->pspell, $word); 
     162                if (empty($suggestions)) { 
     163                    $this->doPrivmsg($target, 'I could not find any suggestions for ' . $word); 
     164                } else { 
     165                    $suggestions = array_splice($suggestions, 0, $this->limit); 
     166                    $this->doPrivmsg($target, $target . ': Suggestions for \'' . $word . '\': ' . implode(', ', $suggestions)); 
     167                } 
     168            } else { 
     169                $this->doPrivmsg($target, $target . ': The word ' . $word . ' seems to be spelled correctly.'); 
     170            } 
     171        } 
     172    } 
     173 
     174    /** 
     175     * Parses incoming CTCP request for spelling suggestions. 
     176     * 
     177     * @return void 
     178     */ 
     179    public function onCtcp() 
     180    { 
     181        $source = $this->event->getSource(); 
     182        $ctcp = $this->event->getArgument(1); 
     183 
     184        if (preg_match('{spell(?:[\s_+-]*check)?\s+(\S+)}ix', $ctcp, $m)) { 
     185            $word = $m[1]; 
     186            if (!pspell_check($this->pspell, $word)) { 
     187                $suggestions = pspell_suggest($this->pspell, $word); 
     188                if (empty($suggestions)) { 
     189                    $this->doPrivmsg($source, 'I could not find any suggestions for ' . $word); 
     190                } else { 
     191                    $suggestions = array_splice($suggestions, 0, $this->limit); 
     192                    $this->doPrivmsg($source, $target . ': Suggestions for \'' . $word . '\': ' . implode(', ', $suggestions)); 
     193                } 
     194            } else { 
     195                $this->doPrivmsg($source, $target . ': The word ' . $word . ' seems to be spelled correctly.'); 
     196            } 
     197        } 
     198    } 
    147199}