-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIRC.php
88 lines (71 loc) · 1.88 KB
/
IRC.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Phipe\Executor;
use Phipe\Watcher;
use Phipe\Connection;
use Phipe\Connection\Event\Factory as EventFactory;
use Phipe\Connection\Buffering\Factory as BufferingFactory;
$watcher = new Watcher();
$watcher->on(
'connect',
function (Connection $connection) {
echo 'Connected...' . PHP_EOL;
$connection->write("NICK monkey_brain\n");
$connection->write("USER monkey 8 * :monkey'\n");
}
);
$watcher->on(
'connect_fail',
function (Connection $connection) {
echo 'Connection failed' . PHP_EOL;
}
);
$watcher->on(
'read',
function (Connection $connection) {
$lines = preg_split("#\r?\n#", $connection->read(), -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
echo "← {$line}\n";
$parts = explode(':', $line, 2);
$command = trim(array_shift($parts));
if ($command === 'PING') {
$token = array_pop($parts);
$connection->write("PONG :{$token}\n");
}
}
}
);
$watcher->on(
'write',
function (Connection $connection, $data) {
echo "→ {$data}";
}
);
$watcher->on(
'eof',
function (Connection $connection) {
echo PHP_EOL;
echo 'EOF' . PHP_EOL;
}
);
$watcher->on(
'disconnect',
function (Connection $connection) {
echo PHP_EOL;
echo 'Disconnected' . PHP_EOL;
}
);
$factory = new \Phipe\Connection\Event\Factory();
//$factory = new \Phipe\Connection\Stream\Factory();
//$factory = new BufferingFactory(new EventFactory());
$phipe = new Executor([
'connections' => [
['host' => '108.61.240.240', 'port' => 6667], // DALnet
['host' => '76.72.161.35', 'port' => 6667] // IRCHighway
],
'observers' => [
$watcher
],
'factory' => $factory
]);
$phipe->execute();