cvs: pearbot / PEARbot.php
[email protected] ("Mirco 'meebey' Bauer") Sun, 27 Apr 2003 20:20:23 -0000
| Newsgroups | php.pear.bot |
|---|---|
| Message-ID | <cvsmeebey1051474823@cvsserver> |
meebey Sun Apr 27 16:20:23 2003 EDT
Modified files:
/pearbot PEARbot.php
Log:
- added !who command.
- modified verify() to return username instead of true.
Index: pearbot/PEARbot.php
diff -u pearbot/PEARbot.php:1.5 pearbot/PEARbot.php:1.6
--- pearbot/PEARbot.php:1.5 Mon Feb 3 10:58:26 2003
+++ pearbot/PEARbot.php Sun Apr 27 16:20:23 2003
@@ -1,7 +1,7 @@
-#!/home/meebey/PEARbot/php
+#!/home/meebey/php
<?php
/**
- * $Id: PEARbot.php,v 1.5 2003/02/03 15:58:26 meebey Exp $
+ * $Id: PEARbot.php,v 1.6 2003/04/27 20:20:23 meebey Exp $
*
* PEARbot
* this is an IRC service bot for #pear written in PHP
@@ -49,6 +49,47 @@
class CPEARbot
{
+ function nick2pearusername(&$irc, $nickname)
+ {
+ $query = "SELECT pearusername FROM dnsentries WHERE nickname='".$nickname."'";
+ $result = dbquery($query);
+ $row = mysql_fetch_array($result);
+ return $row['pearusername'];
+ }
+
+ function reverseverify(&$irc, $host, $nick)
+ {
+ $query = "SELECT nickname,dnsalias FROM dnsentries";
+ $result = dbquery($query);
+
+ $list = array();
+ $foundnick = false;
+ $userip = gethostbyname($host);
+ while ($row = mysql_fetch_array($result)) {
+ $dbip = gethostbyname($row['dnsalias']);
+ $dbnickname = $row['nickname'];
+
+ if ($userip == $dbip) {
+ if ($dbnickname != $nick) {
+ $foundnick = $dbnickname;
+ }
+
+ break;
+ }
+ }
+
+ if ($foundnick !== false) {
+ $result = $this->verify($irc, $foundnick, $nick);
+ } else {
+ $result = $this->verify($irc, $nick);
+ }
+
+ if ($result !== false)
+ return $result;
+ else
+ return false;
+ }
+
function verify(&$irc, $nickname, $ircnickname = null)
{
$who = $nickname;
@@ -76,12 +117,13 @@
$dnsaliasip = gethostbyname($row['dnsalias']);
if ($dnsaliasip == $ip) {
- return true;
+ return $row['nickname'];
}
}
- return false;
}
+
+ return false;
}
}
@@ -92,37 +134,36 @@
return;
if ($data->channel == '#pear') {
- $query = "SELECT nickname,dnsalias FROM dnsentries";
- $result = dbquery($query);
-
- $list = array();
- $foundnick = false;
- $userip = gethostbyname($data->host);
- while ($row = mysql_fetch_array($result)) {
- $dbip = gethostbyname($row['dnsalias']);
- $dbnickname = $row['nickname'];
-
- if ($userip == $dbip) {
- if ($dbnickname != $data->nick) {
- $foundnick = $dbnickname;
- }
-
- break;
- }
- }
+ $result = $this->reverseverify($irc, $data->host, $data->nick);
-
- if ($foundnick !== false) {
- $result = $this->verify($irc, $foundnick, $data->nick);
- } else {
- $result = $this->verify($irc, $data->nick);
- }
-
- if ($result === true) {
+ if ($result !== false) {
$irc->op('#pear', $data->nick);
}
}
}
+
+ function packagelist()
+ {
+ }
+
+ function who(&$irc, &$data)
+ {
+ $requester = $data->nick;
+ $lookupfor = $data->messageex[1];
+ $lowerlookupfor = strtolower($data->messageex[1]);
+
+ if (isset($irc->channel['#pear']->users[$lowerlookupfor])) {
+ $host = $irc->channel['#pear']->users[$lowerlookupfor]->host;
+ } else {
+ $irc->message(SMARTIRC_TYPE_CHANNEL, '#pear', $requester.": ".$lookupfor." is not in this channel");
+ return;
+ }
+
+ $result = $this->reverseverify($irc, $host, $lookupfor);
+
+ if ($result !== false)
+ $irc->message(SMARTIRC_TYPE_CHANNEL, '#pear', $requester.": ".$lookupfor." is ".$result);
+ }
}
$bot = &new CPEARbot();
@@ -137,9 +178,10 @@
$irc->setReceiveTimeout(600);
$irc->setTransmitTimeout(600);
$irc->registerActionhandler(SMARTIRC_TYPE_JOIN, '.*', $bot, 'onjoin');
+$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL|SMARTIRC_TYPE_QUERY, '^!who ', $bot, 'who');
$irc->connect('efnet.skynet.be', 6668);
$irc->login($config['nick'], $config['real_name'], 8, $config['ident']);
$irc->join('#pear');
$irc->listen();
$irc->disconnect();
-?>
+?>
\ No newline at end of file