From 1e141d263303747f1bf5368e4ed392856968cdf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Sat, 15 Sep 2018 23:48:52 -0300 Subject: [PATCH] Add HyperVoice --- hypervoice.php | 122 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100755 hypervoice.php diff --git a/hypervoice.php b/hypervoice.php new file mode 100755 index 0000000..1d802c4 --- /dev/null +++ b/hypervoice.php @@ -0,0 +1,122 @@ + -1) { + return true; + } + else { + return false; + } +} + +// --- + +function funcSendCommand($cmd) { + sleep(2); + fputs($GLOBALS['irc'], $cmd . NEW_LINE); + funcOutput($cmd, 'snd'); +} + +function funcExtractNick ($fullUsername) { + return preg_replace("/\:(.*)\!(.*)/i", "$1", $fullUsername); +} + +function funcOutput($output, $mode) { + if ($mode != 'err' && $GLOBALS['isDaemon']) { + return; + } + + switch ($mode) { + case 'snd': + print('Snd> ' . $output . NEW_LINE); + break; + case 'rcv': + print('Rvc> ' . $output); + break; + case 'msg': + print('Msg> ' . $output . NEW_LINE); + break; + case 'err': + print('Err> ' . $output . NEW_LINE); + break; + default: + return; + } +} +// --- + +$ircServer = 'chat.freenode.net'; +$ircPort = '6667'; +$botNick = 'hypervoice'; +$botChannel = '#hyperbola'; + +$arrayConnectCommands = array( + "USER $botNick $botNick $botNick $botNick :$botNick", + "NICK $botNick", + "PONG", + "CAP REQ :account-notify extended-join", + "NICKSERV identify nick password", + "JOIN $botChannel" +); + +$irc = fsockopen($ircServer, $ircPort); + +if (!$irc) { + funcOutput('Something went wrong with the socket', 'err'); + exit(1); +} + +foreach ($arrayConnectCommands as $_value) { + funcSendCommand($_value); +} + +// --- + +while(1) { + while ($raw = fgets($irc)) { + if (startsWith($raw, 'PING')) { + $lastPing = time(); + funcOutput($raw, 'rcv'); + funcSendCommand('PONG'); + } + + if (startsWith($raw, 'ERROR')) { + funcOutput($raw, 'rcv'); + exit(1); + } + + if (startsWith($raw, ':')) { + $rawEx = explode(' ', $raw); + funcOutput($raw, 'rcv'); + switch($rawEx[1]) { + case 'PONG': + $lastPing = time(); + break; + case 'JOIN': + if (!contains($rawEx[0], $botNick) && $rawEx[3] != '*') { + funcSendCommand("MODE $botChannel +v " . funcExtractNick($rawEx[0])); + } + break; + case 'ACCOUNT': + funcSendCommand("MODE $botChannel +v " . funcExtractNick($rawEx[0])); + break; + } + } + } +} + +?>