|
Revision 113, 2.5 KB
(checked in by tobias382, 5 years ago)
|
|
* Fixed a bug in the Autojoin plugin where the channel list was not processed correctly when using a space as a delimiter (thanks Slynderdale)
* Modified the Spellcheck plugin to not require a space between the word being checked and the spell check request trigger (thanks Slynderdale)
|
| Line | |
|---|
| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | require_once 'Phergie/Plugin/Abstract/Base.php'; |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | class Phergie_Plugin_SpellCheck extends Phergie_Plugin_Abstract_Base |
|---|
| 14 | { |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | protected $pspell; |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | protected $limit; |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | public function init() |
|---|
| 36 | { |
|---|
| 37 | $this->pspell = pspell_new($this->getPluginIni('lang')); |
|---|
| 38 | $this->limit = $this->getPluginIni('limit'); |
|---|
| 39 | if (!$this->limit) { |
|---|
| 40 | $this->limit = 5; |
|---|
| 41 | } |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | static public function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) |
|---|
| 54 | { |
|---|
| 55 | if (!extension_loaded('pspell') |
|---|
| 56 | || !$client->getIni('spellcheck.lang')) { |
|---|
| 57 | return false; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | return true; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | public function onPrivmsg() |
|---|
| 69 | { |
|---|
| 70 | $source = $this->event->getSource(); |
|---|
| 71 | $message = $this->event->getArgument(1); |
|---|
| 72 | |
|---|
| 73 | if (preg_match('#(\S+)\s*\(sp\??\)#i', $message, $m)) { |
|---|
| 74 | $word = $m[1]; |
|---|
| 75 | if (!pspell_check($this->pspell, $word)) { |
|---|
| 76 | $suggestions = pspell_suggest($this->pspell, $word); |
|---|
| 77 | if (empty($suggestions)) { |
|---|
| 78 | $this->doPrivmsg($source, 'I could not find any suggestions for '.$word); |
|---|
| 79 | } else { |
|---|
| 80 | $suggestions = array_splice($suggestions, 0, $this->limit); |
|---|
| 81 | $this->doPrivmsg($source, 'Suggestions for \''.$word.'\': '.implode(', ', $suggestions)); |
|---|
| 82 | } |
|---|
| 83 | } else { |
|---|
| 84 | $this->doPrivmsg($source, 'The word '.$word.' seems to be spelled correctly.'); |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | } |
|---|