| | 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 | } |
|---|