5 $args = func_get_args();
6 } elseif (($error = error_get_last())) {
7 $args = ["%s", $error["message"]];
11 if (count($args) === 1 && is_numeric($args[0])) {
12 array_unshift($args, "Got signal %d");
14 trigger_error(call_user_func_array("sprintf", $args), E_USER_ERROR
);
20 function mkfifo($path) {
21 if (!isfifo($path, $stat)) {
22 $stat and unlink($path);
23 if (!posix_mkfifo($path, 0660)) {
27 return fopen($path, "r+");
30 function isfifo($path, &$stat = null) {
31 return ($stat = @stat
($path)) && ($stat["mode"] & POSIX_S_IFIFO
);
40 protected $queue = array();
42 function __construct($url, callable
$onJoin) {
43 if (!$url = parse_url($url)) {
44 fatal("could not parse url: '%s'", $url);
47 $this->session
= $session = new irc\client\
Session(
53 @list
($this->channel
, $this->keyword
) =
54 explode(" ", $url["fragment"]);
56 $session->onConnect
= $session->onPart
= function($origin, array $args) {
57 $this->joined
= false;
58 $this->session
->doJoin("#".$this->channel
, $this->keyword
);
60 $session->onJoin
= function($origin, array $args) use ($onJoin) {
62 $onJoin($this, $origin, $args);
64 $session->doConnect(false, $url["host"], @$url["port"]?
:6667, @$url["pass"]);
67 function send($message = null) {
68 if (isset($message)) {
69 $this->queue
[] = $message;
73 while ($this->queue
) {
74 $this->session
->doMsg("#".$this->channel
, array_shift($this->queue
));
79 function getSession() {
80 return $this->session
;
84 if (!extension_loaded("ircclient")) {
85 fatal("ext/ircclient not loaded");