commit | author | age
|
c57393
|
1 |
<?php |
JK |
2 |
class bot_ort_module implements BotModule { |
|
3 |
function handle($msg, $params) { |
|
4 |
$args = trim($msg->args); |
|
5 |
|
|
6 |
if(empty($args)) { |
|
7 |
return new BotMsg('Funkcja <b>ort</b> wymaga argumentu.<br />' |
|
8 |
. '<br />'."\n" |
|
9 |
. '<u>Przykład:</u><br />'."\n" |
|
10 |
. 'ort grzegżółka<br />'."\n" |
|
11 |
. 'ort warsawa'); |
|
12 |
} |
|
13 |
|
|
14 |
$args = strtr($args, array("\r\n" => ' ', "\r" => ' ', "\n" => ' ')); |
|
15 |
|
|
16 |
$proc = proc_open('aspell --lang=pl --encoding=utf-8 --ignore-case=true pipe', array(array('pipe', 'r'), array('pipe', 'w'), array('file', '/dev/null', 'w')), $pipe); |
|
17 |
|
|
18 |
fwrite($pipe[0], $args."\n"); |
|
19 |
fclose($pipe[0]); |
|
20 |
|
|
21 |
do { |
|
22 |
usleep(1); |
|
23 |
$status = proc_get_status($proc); |
|
24 |
} while($status['running']); |
|
25 |
|
|
26 |
fgets($pipe[1], 1024); |
|
27 |
$spell = fgets($pipe[1], 4096); |
|
28 |
fclose($pipe[1]); |
|
29 |
|
|
30 |
proc_close($proc); |
|
31 |
|
|
32 |
if(empty($spell)) { |
|
33 |
return new BotMsg('Błąd podczas sprawdzania słowa w słowniku. Przepraszamy.'); |
|
34 |
} |
|
35 |
elseif(substr($spell, 0, 1)=='*') { |
|
36 |
return new BotMsg('<span style="color:#060;">Pisownia poprawna.</span>'); |
|
37 |
} |
|
38 |
elseif(substr($spell, 0, 1)=='#') { |
|
39 |
return new BotMsg('Brak propozycji poprawnej pisowni.'); |
|
40 |
} |
|
41 |
else |
|
42 |
{ |
|
43 |
$spell = explode(': ', $spell, 2); |
|
44 |
$spell = explode(',', $spell[1]); |
|
45 |
|
|
46 |
$txt = '<p>Prawdopobnie chodziło ci o:</p>'."\n" |
|
47 |
. '<ul>'."\n"; |
|
48 |
|
|
49 |
foreach($spell as $val) { |
|
50 |
$txt .= '<li>'.htmlspecialchars(trim($val)).'</li>'."\n"; |
|
51 |
} |
|
52 |
$txt .= '</ul>'; |
|
53 |
|
|
54 |
return new BotMsg($txt); |
|
55 |
} |
|
56 |
} |
|
57 |
} |
|
58 |
?> |