SOURCES: t0xirc.php - add verbose flag, add usage display
glen
glen at pld-linux.org
Wed Feb 4 12:33:01 CET 2009
Author: glen Date: Wed Feb 4 11:33:01 2009 GMT
Module: SOURCES Tag: HEAD
---- Log message:
- add verbose flag, add usage display
---- Files affected:
SOURCES:
t0xirc.php (1.4 -> 1.5)
---- Diffs:
================================================================
Index: SOURCES/t0xirc.php
diff -u SOURCES/t0xirc.php:1.4 SOURCES/t0xirc.php:1.5
--- SOURCES/t0xirc.php:1.4 Mon May 22 19:14:57 2006
+++ SOURCES/t0xirc.php Wed Feb 4 12:32:56 2009
@@ -3,21 +3,59 @@
/*
nagiosalert.php 2006 Mikael Fridh <mikael.fridh at ongame.com>
Telnets to an eggdrop and .say's messages to a channel.
- Modified and cleaned up by Elan Ruusamäe <glen at pld-linux.org>
+ Modified and cleaned up by Elan Ruusamäe <glen at pld-linux.org>
*/
error_reporting(E_ALL & ~E_NOTICE);
-require "/usr/share/php/t0xirc.php";
+define('PROGRAM', basename($argv[0]));
-$opt = getopt("u:p:h:P:c:m:");
+function usage() {
+ $PROGRAM = PROGRAM;
+ fwrite(STDERR, "Usage:
+ {$PROGRAM} -u USER -p PASSWORD -h HOSTNAME -P PORT [-c CHANNEL] [-m MESSAGE]
+
+Connects to an eggdrop and .say's messages to a channel.
+If CHANNEL is omited bot's default channel is used.
+if Message is omited, message is read from STDIN.
-$mybot =& new t0xirc_bot($opt['u'], $opt['p'], $opt['h'], $opt['P']);
-$mybot->connect() or die("Unable to connect\n");
+");
+}
+
+require_once '/usr/share/php/t0xirc.php';
+
+$opt = getopt("u:p:h:P:c:m:v");
+if (empty($opt['u']) || empty($opt['p']) || empty($opt['h']) || empty($opt['P'])) {
+ usage();
+ exit(1);
+}
+
+$verbose = isset($opt['v']);
+
+$bot =& new t0xirc_bot($opt['u'], $opt['p'], $opt['h'], $opt['P']);
+if ($verbose) {
+ echo "Connecting to {$opt['h']}:{$opt['P']}\n";
+}
+if (!$bot->connect()) {
+ fwrite(STDERR, "Unable to connect to {$opt['h']}:{$opt['P']}!\n");
+ exit(1);
+}
+if ($verbose) {
+ echo "Connected!\n";
+}
-printf("Connected to %s default chan %s.\n", $mybot->bot_nick, $mybot->channel['name']);
+if (empty($opt['c'])) {
+ $opt['c'] = $bot->channel['name'];
+ if ($verbose) {
+ printf("Connected to %s default channel %s.\n", $bot->bot_nick, $bot->channel['name']);
+ }
+} else {
+ if ($verbose) {
+ printf("Connected to %s, channel: %s.\n", $bot->bot_nick, $bot->channel['name']);
+ }
+}
if ($opt['m']) {
- $mybot->say($opt['m'], $opt['c']);
+ $bot->say($opt['m'], $opt['c']);
} else {
// read from stdin
$fp = STDIN;
@@ -26,10 +64,8 @@
if (!$line) {
break;
}
- $mybot->say($line, $opt['c']);
+ $bot->say($line, $opt['c']);
}
}
-$mybot->disconnect();
-
-?>
+$bot->disconnect();
================================================================
---- CVS-web:
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SOURCES/t0xirc.php?r1=1.4&r2=1.5&f=u
More information about the pld-cvs-commit
mailing list