# HG changeset patch # User Dan # Date 1219682066 14400 # Node ID 0acb8d9a3194f121f81dde4bc399e7664798ac15 # Parent 1d6e762433fef7e4b2f18e041df15b331bae8fde Welcome, modularization and stats. diff -r 1d6e762433fe -r 0acb8d9a3194 config-sample.php --- a/config-sample.php Fri May 09 22:37:57 2008 -0400 +++ b/config-sample.php Mon Aug 25 12:34:26 2008 -0400 @@ -2,6 +2,7 @@ // Rename this to config.php and run php ./enanobot.php to start. +$server = 'irc.freenode.net'; $nick = 'EnanoBot'; $pass = ''; $name = 'Enano CMS logging/message bot'; diff -r 1d6e762433fe -r 0acb8d9a3194 eliza.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/eliza.php Mon Aug 25 12:34:26 2008 -0400 @@ -0,0 +1,626 @@ + + * @author Dan Fuhry + * @copyright (c) 1997-2008 George Dunlop. All rights reserved, portions copyright (C) 2008 Dan Fuhry. + */ + +class Psychotherapist +{ + private $maxKey = 36; + private $keyNotFound = 0; + private $keyword = array(); + private $maxresponses = 116; + private $response = array(); + + private $maxConj = 19; + private $max2ndConj = 7; + + private $conj1 = Array(); + private $conj2 = Array(); + private $conj3 = Array(); + private $conj4 = Array(); + + private $punct = Array(".", ",", "!", "?", ":", ";", "&", '"', "@", "#", "(", ")" ); + + /** + * Constructor. + */ + + public function __construct() + { + $this->keyNotFound = $this->maxKey - 1; + $this->keyword = $this->create_array($this->maxKey); + $this->response = $this->create_array($this->maxresponses); + $this->conj1 = $this->create_array($this->maxConj); + $this->conj2 = $this->create_array($this->maxConj); + $this->conj3 = $this->create_array($this->max2ndConj); + $this->conj4 = $this->create_array($this->max2ndConj); + + $this->table_setup(); + } + + /** + * Replacement for str_replace that provides more options. + * if type == 0 straight string replacement + * if type == 1 assumes padded strings and replaces whole words only + * if type == 2 non case sensitive assumes padded strings to compare whole word only + * if type == 3 non case sensitive straight string replacement + * @param string Haystack + * @param string Needle + * @param string Replacement + * @param int Mode - defaults to 0 + */ + + private function replaceStr($strng, $substr1, $substr2, $type = 0) + { + if ( $type == 0 ) + { + return str_replace($substr1, $substr2, $strng); + } + else if ( $type == 1 ) + { + return str_replace(" $substr1 ", " $substr2 ", $strng); + } + else if ( $type == 2 || $type == 3 ) + { + if ( $type == 2 ) + { + $substr1 = " $substr1 "; + $substr2 = " $substr2 "; + } + return preg_replace('/' . preg_quote($substr1) . '/i', $substr2, $strng); + } + else + { + throw new Exception("Invalid parameter"); + } + } + + /** + * Function to pad a string. head, tail & punctuation + * @param string + * @return string + */ + + private function padString($strng) + { + $punct =& $this->punct; + + $aString = " " . $strng . " "; + for ( $i = 0; $i < count($punct); $i++ ) + { + $aString = $this->replaceStr( $aString, $punct[$i], " " . $punct[$i] . " ", 0 ); + } + return $aString; + } + + /** + * Function to strip padding + */ + + private function unpadString($strng) + { + $punct =& $this->punct; + + $aString = $strng; + $aString = $this->replaceStr( $aString, " ", " ", 0 ); // compress spaces + + $aString = trim($aString, ' '); + + for ( $i = 0; $i < count($punct); $i++ ) + { + $aString = $this->replaceStr( $aString, " " . $punct[$i], $punct[$i], 0 ); + } + return $aString; + } + + /** + * Dress Input formatting i.e leading & trailing spaces and tail punctuation + * @param string + * @return string + */ + + function strTrim($strng) + { + static $ht = 0; + + if ( $ht == 0 ) + { + $loc = 0; + } // head clip + else + { + $loc = strlen($strng) - 1; + } // tail clip ht = 1 + if ( substr($strng, $loc, 1) == " " ) + { + $aString = substr($strng, - ( $ht - 1 ), strlen($strng) - $ht); + $aString = $this->strTrim($aString); + } + else + { + $flg = false; + for ( $i = 0; $i <= 5; $i++ ) + { + $flg = $flg || ( substr($strng, $loc, 1) == $this->punct[$i]); + } + if ( $flg ) + { + $aString = substr($strng, - ( $ht - 1 ), strlen($strng) - $ht); + } + else + { + $aString = $strng; + } + if ( $aString != $strng ) + { + $aString = $this->strTrim($aString); + } + } + if ( $ht == 0 ) + { + $ht = 1; + $aString = $this->strTrim($aString); + } + else + { + $ht = 0; + } + return $aString; + } + + /** + * adjust pronouns and verbs & such + * @param string + * @return string + */ + + private function conjugate($sStrg) + { + $sString = $sStrg; + for ( $i = 0; $i < $this->maxConj; $i++ ) + { // decompose + $sString = $this->replaceStr( $sString, $this->conj1[$i], "#@&" . $i, 2 ); + } + for( $i = 0; $i < $this->maxConj; $i++ ) + { // recompose + $sString = $this->replaceStr( $sString, "#@&" . $i, $this->conj2[$i], 2 ); + } + // post process the resulting string + for( $i = 0; $i < $this->max2ndConj; $i++ ) + { // decompose + $sString = $this->replaceStr( $sString, $this->conj3[$i], "#@&" . $i, 2 ); + } + for( $i = 0; $i < $this->max2ndConj; $i++ ) + { // recompose + $sString = $this->replaceStr( $sString, "#@&" . $i, $this->conj4[$i], 2 ); + } + return $sString; + } + + /** + * Build our response string + * get a random choice of response based on the key + * Then structure the response + * @param string + * @param int Key index + * @return string + */ + + function phrase( $sString, $keyidx ) + { + $idxmin = $this->keyword[$keyidx]->idx; + $idrange = $this->keyword[$keyidx]->end - $idxmin + 1; + while ( $pass < 5 ) + { + $choice = $this->keyword[$keyidx]->idx + mt_rand(0, $idrange); + if ( $choice == $this->keyword[$keyidx]->last ) + { + $pass++; + continue; + } + break; + } + $this->keyword[$keyidx]->last = $choice; + $rTemp = $this->response[$choice]; + $tempt = substr($rTemp, strlen($rTemp) - 1, 1); + if ( ( $tempt == "*" ) || ( $tempt == "@" ) ) + { + $sTemp = $this->padString($sString); + $wTemp = strtoupper($sTemp); + $strpstr = intval(strpos($wTemp, " {$this->keyword[$keyidx]->key} ")); + + $strpstr += strlen($this->keyword[$keyidx]->key) + 1; + $thisstr = $this->conjugate( substr($sTemp, $strpstr, strlen($sTemp)) ); + $thisstr = $this->strTrim( $this->unpadString($thisstr) ); + if( $tempt == "*" ) + { + $sTemp = $this->replaceStr( $rTemp, "<*", " " . $thisstr . "?", 0 ); + } + else + { + $sTemp = $this->replaceStr( $rTemp, "<@", " " . $thisstr . ".", 0 ); + } + } + else + { + $sTemp = $rTemp; + } + return $sTemp; + } + + /** + * returns array index of first key found + * @param string + */ + + private function testkey($wString) + { + for ( $keyid = 0; $keyid < count($this->keyword); $keyid++ ) + { + if ( strpos($wString, " {$this->keyword[$keyid]->key} ") !== false ) + { + return $keyid; + } + } + return false; + } + + /** + * + */ + + private function findkey($wString) + { + $keyid = $this->testkey($wString); + if( !$keyid ) + { + $keyid = $this->keyNotFound; + } + return $keyid; + } + + /** + * Process a line from the user. + * @param string User input + * @return string AI output + */ + + function listen($User) + { + static $wTopic = ""; // Last worthy responce + static $sTopic = ""; // Last worthy responce + static $greet = false; + static $wPrevious = ""; // so we can check for repeats + + $sInput = $User; + $sInput = $this->strTrim($sInput); // dress input formating + + if ( $sInput != "" ) + { + $wInput = $this->padString(strtoupper($sInput)); // Work copy + $foundkey = $this->maxKey; // assume it's a repeat input + if ( $wInput != $wPrevious ) + { // check if user repeats himself + $foundkey = $this->findkey($wInput); // look for a keyword. + } + if( $foundkey == $this->keyNotFound ) + { + if( !$greet ) + { + $greet = true; + return "Don't you ever say Hello?"; + } + else + { + $wPrevious = $wInput; // save input to check repeats + if (( strlen($sInput) < 10 ) && ( $wTopic != "" ) && ( $wTopic != $wPrevious )) + { + $lTopic = $this->conjugate( $sTopic ); + $sTopic = ""; + $wTopic = ""; + return 'OK... "' + $lTopic + '". Tell me more.'; + } + else + { + if ( strlen($sInput) < 15 ) + { + return "Tell me more..."; + } + else + { + return $this->phrase( $sInput, $foundkey ); + } + } + } + } + else + { + if ( strlen($sInput) > 12 ) + { + $sTopic = $sInput; + $wTopic = $wInput; + } + $greet = true; + $wPrevious = $wInput; // save input to check repeats + return $this->phrase( $sInput, $foundkey ); // Get our response + } + } + else + { + return "I can't help if you will not chat with me!"; + } + } + + /** + * Creates an array of the specified length, and fills it with null values. + * @param int Array size + * @return array + */ + + function create_array($len) + { + $ret = array(); + for ( $i = 0; $i < $len; $i++ ) + { + $ret[] = null; + } + return $ret; + } + + /** + * Sets up the tables of phrases, etc. + */ + + private function table_setup() + { + // build our data base here + + $this->conj1[0] = "are"; $this->conj2[0] = "am"; + $this->conj1[1] = "am"; $this->conj2[1] = "are"; + $this->conj1[2] = "were"; $this->conj2[2] = "was"; + $this->conj1[3] = "was"; $this->conj2[3] = "were"; + $this->conj1[4] = "I"; $this->conj2[4] = "you"; + $this->conj1[5] = "me"; $this->conj2[5] = "you"; + $this->conj1[6] = "you"; $this->conj2[6] = "me"; + $this->conj1[7] = "my"; $this->conj2[7] = "your"; + $this->conj1[8] = "your"; $this->conj2[8] = "my"; + $this->conj1[9] = "mine"; $this->conj2[9] = "your's"; + $this->conj1[10] = "your's"; $this->conj2[10] = "mine"; + $this->conj1[11] = "I'm"; $this->conj2[11] = "you're"; + $this->conj1[12] = "you're"; $this->conj2[12] = "I'm"; + $this->conj1[13] = "I've"; $this->conj2[13] = "you've"; + $this->conj1[14] = "you've"; $this->conj2[14] = "I've"; + $this->conj1[15] = "I'll"; $this->conj2[15] = "you'll"; + $this->conj1[16] = "you'll"; $this->conj2[16] = "I'll"; + $this->conj1[17] = "myself"; $this->conj2[17] = "yourself"; + $this->conj1[18] = "yourself"; $this->conj2[18] = "myself"; + + // array to post process correct our tenses of pronouns such as "I/me" + + $this->conj3[0] = "me am"; $this->conj4[0] = "I am"; + $this->conj3[1] = "am me"; $this->conj4[1] = "am I"; + $this->conj3[2] = "me can"; $this->conj4[2] = "I can"; + $this->conj3[3] = "can me"; $this->conj4[3] = "can I"; + $this->conj3[4] = "me have"; $this->conj4[4] = "I have"; + $this->conj3[5] = "me will"; $this->conj4[5] = "I will"; + $this->conj3[6] = "will me"; $this->conj4[6] = "will I"; + + + // Keywords + + $this->keyword[ 0]=new Psychotherapist_Key( "CAN YOU", 1, 3); + $this->keyword[ 1]=new Psychotherapist_Key( "CAN I", 4, 5); + $this->keyword[ 2]=new Psychotherapist_Key( "YOU ARE", 6, 9); + $this->keyword[ 3]=new Psychotherapist_Key( "YOU'RE", 6, 9); + $this->keyword[ 4]=new Psychotherapist_Key( "I DON'T", 10, 13); + $this->keyword[ 5]=new Psychotherapist_Key( "I FEEL", 14, 16); + $this->keyword[ 6]=new Psychotherapist_Key( "WHY DON'T YOU", 17, 19); + $this->keyword[ 7]=new Psychotherapist_Key( "WHY CAN'T I", 20, 21); + $this->keyword[ 8]=new Psychotherapist_Key( "ARE YOU", 22, 24); + $this->keyword[ 9]=new Psychotherapist_Key( "I CAN'T", 25, 27); + $this->keyword[10]=new Psychotherapist_Key( "I AM", 28, 31); + $this->keyword[11]=new Psychotherapist_Key( "I'M", 28, 31); + $this->keyword[12]=new Psychotherapist_Key( "YOU", 32, 34); + $this->keyword[13]=new Psychotherapist_Key( "I WANT", 35, 39); + $this->keyword[14]=new Psychotherapist_Key( "WHAT", 40, 48); + $this->keyword[15]=new Psychotherapist_Key( "HOW", 40, 48); + $this->keyword[16]=new Psychotherapist_Key( "WHO", 40, 48); + $this->keyword[17]=new Psychotherapist_Key( "WHERE", 40, 48); + $this->keyword[18]=new Psychotherapist_Key( "WHEN", 40, 48); + $this->keyword[19]=new Psychotherapist_Key( "WHY", 40, 48); + $this->keyword[20]=new Psychotherapist_Key( "NAME", 49, 50); + $this->keyword[21]=new Psychotherapist_Key( "CAUSE", 51, 54); + $this->keyword[22]=new Psychotherapist_Key( "SORRY", 55, 58); + $this->keyword[23]=new Psychotherapist_Key( "DREAM", 59, 62); + $this->keyword[24]=new Psychotherapist_Key( "HELLO", 63, 63); + $this->keyword[25]=new Psychotherapist_Key( "HI", 63, 63); + $this->keyword[26]=new Psychotherapist_Key( "MAYBE", 64, 68); + $this->keyword[27]=new Psychotherapist_Key( "NO", 69, 73); + $this->keyword[28]=new Psychotherapist_Key( "YOUR", 74, 75); + $this->keyword[29]=new Psychotherapist_Key( "ALWAYS", 76, 79); + $this->keyword[30]=new Psychotherapist_Key( "THINK", 80, 82); + $this->keyword[31]=new Psychotherapist_Key( "ALIKE", 83, 89); + $this->keyword[32]=new Psychotherapist_Key( "YES", 90, 92); + $this->keyword[33]=new Psychotherapist_Key( "FRIEND", 93, 98); + $this->keyword[34]=new Psychotherapist_Key( "COMPUTER", 99, 105); + $this->keyword[35]=new Psychotherapist_Key( "NO KEY FOUND", 106, 112); + $this->keyword[36]=new Psychotherapist_Key( "REPEAT INPUT", 113, 116); + + + $this->response[ 0]="ELIZA - PHP version ported from Javascript (George Dunlop) code by Dan Fuhry"; + $this->response[ 1]="Don't you believe that I can<*"; + $this->response[ 2]="Perhaps you would like to be able to<*"; + $this->response[ 3]="You want me to be able to<*"; + $this->response[ 4]="Perhaps you don't want to<*"; + $this->response[ 5]="Do you want to be able to<*"; + $this->response[ 6]="What makes you think I am<*"; + $this->response[ 7]="Does it please you to believe I am<*"; + $this->response[ 8]="Perhaps you would like to be<*"; + $this->response[ 9]="Do you sometimes wish you were<*"; + $this->response[ 10]="Don't you really<*"; + $this->response[ 11]="Why don't you<*"; + $this->response[ 12]="Do you wish to be able to<*"; + $this->response[ 13]="Does that trouble you?"; + $this->response[ 14]="Tell me more about such feelings."; + $this->response[ 15]="Do you often feel<*"; + $this->response[ 16]="Do you enjoy feeling<*"; + $this->response[ 17]="Do you really believe I don't<*"; + $this->response[ 18]="Perhaps in good time I will<@"; + $this->response[ 19]="Do you want me to<*"; + $this->response[ 20]="Do you think you should be able to<*"; + $this->response[ 21]="Why can't you<*"; + $this->response[ 22]="Why are you interested in whether or not I am<*"; + $this->response[ 23]="Would you prefer if I were not<*"; + $this->response[ 24]="Perhaps in your fantasies I am<*"; + $this->response[ 25]="How do you know you can't<*"; + $this->response[ 26]="Have you tried?"; + $this->response[ 27]="Perhaps you can now<*"; + $this->response[ 28]="Did you come to me because you are<*"; + $this->response[ 29]="How long have you been<*"; + $this->response[ 30]="Do you believe it is normal to be<*"; + $this->response[ 31]="Do you enjoy being<*"; + $this->response[ 32]="We were discussing you, not me."; + $this->response[ 33]="Oh... <*"; + $this->response[ 34]="You're not really talking about me, are you?"; + $this->response[ 35]="What would it mean to you if you got<*"; + $this->response[ 36]="Why do you want<*"; + $this->response[ 37]="Suppose you got<*"; + $this->response[ 38]="What if you never got<*"; + $this->response[ 39]="I sometimes also want<@"; + $this->response[ 40]="Why do you ask?"; + $this->response[ 41]="Does that question interest you?"; + $this->response[ 42]="What answer would please you the most?"; + $this->response[ 43]="What do you think?"; + $this->response[ 44]="Are such questions on your mind often?"; + $this->response[ 45]="What is it that you really want to know?"; + $this->response[ 46]="Have you asked anyone else?"; + $this->response[ 47]="Have you asked such questions before?"; + $this->response[ 48]="What else comes to mind when you ask that?"; + $this->response[ 49]="Names don't interest me."; + $this->response[ 50]="I don't care about names, please go on."; + $this->response[ 51]="Is that the real reason?"; + $this->response[ 52]="Don't any other reasons come to mind?"; + $this->response[ 53]="Does that reason explain anything else?"; + $this->response[ 54]="What other reasons might there be?"; + $this->response[ 55]="Please don't apologise!"; + $this->response[ 56]="Apologies are not necessary."; + $this->response[ 57]="What feelings do you have when you apologise?"; + $this->response[ 58]="Don't be so defensive!"; + $this->response[ 59]="What does that dream suggest to you?"; + $this->response[ 60]="Do you dream often?"; + $this->response[ 61]="What persons appear in your dreams?"; + $this->response[ 62]="Are you disturbed by your dreams?"; + $this->response[ 63]="How are you today.. What would you like to discuss?"; + $this->response[ 64]="You don't seem quite certain."; + $this->response[ 65]="Why the uncertain tone?"; + $this->response[ 66]="Can't you be more positive?"; + $this->response[ 67]="You aren't sure?"; + $this->response[ 68]="Don't you know?"; + $this->response[ 69]="Are you saying no just to be negative?"; + $this->response[ 70]="You are being a bit negative."; + $this->response[ 71]="Why not?"; + $this->response[ 72]="Are you sure?"; + $this->response[ 73]="Why no?"; + $this->response[ 74]="Why are you concerned about my<*"; + $this->response[ 75]="What about your own<*"; + $this->response[ 76]="Can you think of a specific example?"; + $this->response[ 77]="When?"; + $this->response[ 78]="What are you thinking of?"; + $this->response[ 79]="Really, always?"; + $this->response[ 80]="Do you really think so?"; + $this->response[ 81]="But you are not sure you<*"; + $this->response[ 82]="Do you doubt you<*"; + $this->response[ 83]="In what way?"; + $this->response[ 84]="What resemblence do you see?"; + $this->response[ 85]="What does the similarity suggest to you?"; + $this->response[ 86]="What other connections do you see?"; + $this->response[ 87]="Could there really be some connection?"; + $this->response[ 88]="How?"; + $this->response[ 89]="You seem quite positive."; + $this->response[ 90]="Are you Sure?"; + $this->response[ 91]="I see."; + $this->response[ 92]="I understand."; + $this->response[ 93]="Why do you bring up the topic of friends?"; + $this->response[ 94]="Do your friends worry you?"; + $this->response[ 95]="Do your friends pick on you?"; + $this->response[ 96]="Are you sure you have any friends?"; + $this->response[ 97]="Do you impose on your friends?"; + $this->response[ 98]="Perhaps your love for friends worries you."; + $this->response[ 99]="Do computers worry you?"; + $this->response[100]="Are you talking about me in particular?"; + $this->response[101]="Are you frightened by machines?"; + $this->response[102]="Why do you mention computers?"; + $this->response[103]="What do you think machines have to do with your problems?"; + $this->response[104]="Don't you think computers can help people?"; + $this->response[105]="What is it about machines that worries you?"; + $this->response[106]="Say, do you have any psychological problems?"; + $this->response[107]="What does that suggest to you?"; + $this->response[108]="I see."; + $this->response[109]="I'm not sure I understand you fully."; + $this->response[110]="Come, come, elucidate your thoughts."; + $this->response[111]="Can you elaborate on that?"; + $this->response[112]="That is quite interesting."; + $this->response[113]="Why did you repeat yourself?"; + $this->response[114]="Do you expect a different answer by repeating yourself?"; + $this->response[115]="Come, come, elucidate your thoughts."; + $this->response[116]="Please don't repeat yourself!"; + } + +} + +/** + * Keyword class + */ + +class Psychotherapist_Key +{ + /** + * Phrase to match + * @var string + */ + + public $key = ''; + + /** + * First response to use + * @var int + */ + + public $idx = 0; + + /** + * Last response to use + * @var int + */ + + public $end = 0; + + /** + * Response last used time + * @var int + */ + + public $last = 0; + + /** + * Constructor. + * @param string Key + * @param int Index + * @param int End + */ + + public function __construct($key, $idx, $end) + { + $this->key = $key; + $this->idx = $idx; + $this->end = $end; + } +} + + diff -r 1d6e762433fe -r 0acb8d9a3194 enanobot --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/enanobot Mon Aug 25 12:34:26 2008 -0400 @@ -0,0 +1,11 @@ +#!/bin/bash +[ -n "$1" ] && +{ + php $(dirname $0)/enanobot.php $@ + exit $? +} +while true; do + php $(dirname $0)/enanobot.php + [ x$? = x2 ] && break +done & + diff -r 1d6e762433fe -r 0acb8d9a3194 enanobot.php --- a/enanobot.php Fri May 09 22:37:57 2008 -0400 +++ b/enanobot.php Mon Aug 25 12:34:26 2008 -0400 @@ -1,5 +1,4 @@ connect($nick, $user, $name, $pass); $irc->set_privmsg_handler('enanobot_privmsg_event'); @@ -138,15 +169,16 @@ $sockdata = trim($sockdata); $message = Request_IRC::parse_message($sockdata); $channelname = $chan->get_channel_name(); - enanobot_log_message($chan, $message); + + eval(eb_fetch_hook('event_raw_message')); + switch ( $message['action'] ) { case 'JOIN': - // if a known op joins the channel, send mode +o - if ( in_array($message['nick'], $privileged_list) ) - { - $chan->parent->put("MODE $channelname +o {$message['nick']}\r\n"); - } + eval(eb_fetch_hook('event_join')); + break; + case 'PART': + eval(eb_fetch_hook('event_part')); break; case 'PRIVMSG': enanobot_process_channel_message($sockdata, $chan, $message); @@ -158,113 +190,14 @@ { global $irc, $nick, $mysql_conn, $privileged_list; - if ( preg_match('/^\!echo /', $message['message']) && in_array($message['nick'], $privileged_list) ) - { - $chan->msg(preg_replace('/^\!echo /', '', $message['message']), true); - } - else if ( preg_match('/^\![\s]*([a-z0-9_-]+)([\s]*\|[\s]*([^ ]+))?$/', $message['message'], $match) ) + if ( strpos($message['message'], $nick) && !in_array($message['nick'], $privileged_list) && $message['nick'] != $nick ) { - $snippet =& $match[1]; - if ( @$match[3] === 'me' ) - $match[3] = $message['nick']; - $target_nick = ( !empty($match[3]) ) ? "{$match[3]}, " : "{$message['nick']}, "; - if ( $snippet == 'snippets' ) - { - // list available snippets - $m_et = false; - $q = eb_mysql_query('SELECT snippet_code, snippet_channels FROM snippets;'); - if ( mysql_num_rows($q) < 1 ) - { - $chan->msg("{$message['nick']}, I couldn't find that snippet (\"$snippet\") in the database.", true); - } - else - { - $snippets = array(); - while ( $row = mysql_fetch_assoc($q) ) - { - $channels = explode('|', $row['snippet_channels']); - if ( in_array($chan->get_channel_name(), $channels) ) - { - $snippets[] = $row['snippet_code']; - } - } - $snippets = implode(', ', $snippets); - $chan->msg("{$message['nick']}, the following snippets are available: $snippets", true); - } - @mysql_free_result($q); - } - else - { - // Look for the snippet... - $q = eb_mysql_query('SELECT snippet_text, snippet_channels FROM snippets WHERE snippet_code = \'' . mysql_real_escape_string($snippet) . '\';'); - if ( mysql_num_rows($q) < 1 ) - { - $chan->msg("{$message['nick']}, I couldn't find that snippet (\"$snippet\") in the database.", true); - } - else - { - $row = mysql_fetch_assoc($q); - $channels = explode('|', $row['snippet_channels']); - if ( in_array($chan->get_channel_name(), $channels) ) - { - $chan->msg("{$target_nick}{$row['snippet_text']}", true); - } - else - { - $chan->msg("{$message['nick']}, I couldn't find that snippet (\"$snippet\") in the database.", true); - } - } - @mysql_free_result($q); - } + //$target_nick =& $message['nick']; + //$chan->msg("{$target_nick}, I'm only a bot. :-) You should probably rely on the advice of humans if you need further assistance.", true); } - else if ( strpos($message['message'], $nick) && !in_array($message['nick'], $privileged_list) && $message['nick'] != $nick ) - { - $target_nick =& $message['nick']; - $chan->msg("{$target_nick}, I'm only a bot. :-) You should probably rely on the advice of humans if you need further assistance.", true); - } -} - -function enanobot_log_message($chan, $message) -{ - global $nick; - - // Log the message - $chan_db = mysql_real_escape_string($chan->get_channel_name()); - $nick_db = mysql_real_escape_string($message['nick']); - $line_db = mysql_real_escape_string($message['message']); - $day = date('Y-m-d'); - $time = time(); - $m_et = false; - $sql = false; - switch($message['action']) + else { - case 'PRIVMSG': - if ( substr($line_db, 0, 5) != '[off]' ) - { - $sql = "INSERT INTO irclog(channel, day, nick, timestamp, line) VALUES - ( '$chan_db', '$day', '$nick_db', '$time', '$line_db' );"; - } - break; - case 'JOIN': - $sql = "INSERT INTO irclog(channel, day, nick, timestamp, line) VALUES - ( '$chan_db', '$day', '', '$time', '$nick_db has joined $chan_db' );"; - break; - case 'PART': - $sql = "INSERT INTO irclog(channel, day, nick, timestamp, line) VALUES - ( '$chan_db', '$day', '', '$time', '$nick_db has left $chan_db' );"; - break; - case 'MODE': - list($mode, $target_nick) = explode(' ', $line_db); - if ( $message['nick'] != 'ChanServ' && $target_nick != $nick ) - { - $sql = "INSERT INTO irclog(channel, day, nick, timestamp, line) VALUES - ( '$chan_db', '$day', '', '$time', '$nick_db set mode $mode on $target_nick' );"; - } - break; - } - if ( $sql ) - { - eb_mysql_query($sql); + eval(eb_fetch_hook('event_channel_msg')); } } @@ -277,7 +210,7 @@ foreach ( $irc->channels as $channel ) { $part_cache[] = array($channel->get_channel_name(), $channel->get_handler()); - $channel->msg("I've received a request to stop logging messages and responding to requests from {$message['nick']}. Don't forget to unsuspend me with /msg $nick Resume when finished.", true); + $channel->msg("I've received a request from {$message['nick']} to stop responding to requests, messages, and activities. Don't forget to unsuspend me with /msg $nick Resume when finished.", true); $channel->part("Logging and presence suspended by {$message['nick']}", true); } } @@ -295,17 +228,21 @@ } else if ( in_array($message['nick'], $privileged_list) && $message['message'] == 'Shutdown' && $message['action'] == 'PRIVMSG' ) { + $GLOBALS['_shutdown'] = true; $irc->close("Remote bot shutdown ordered by {$message['nick']}", true); return 'BREAK'; } - else if ( in_array($message['nick'], $privileged_list) && preg_match("/^\!echo-([^\007, \r\n\a\t]+) /", $message['message'], $match) ) + else if ( $message['action'] == 'PRIVMSG' ) { - global $libirc_channels; - $channel_name =& $match[1]; - if ( isset($libirc_channels[$channel_name]) && is_object($libirc_channels[$channel_name]) ) - { - $libirc_channels[$channel_name]->msg(preg_replace("/^\!echo-([^\007, \r\n\a\t]+) /", '', $message['message']), true); - } + eval(eb_fetch_hook('event_privmsg')); + } + else + { + eval(eb_fetch_hook('event_other')); } } +if ( $_shutdown ) +{ + exit(2); +} diff -r 1d6e762433fe -r 0acb8d9a3194 hooks.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hooks.php Mon Aug 25 12:34:26 2008 -0400 @@ -0,0 +1,25 @@ += 0; $i-- ) +{ + $basetime = $this_hour - ( $i * 3600 ); + $ts = date('H:i', $basetime); + $basetime += 3600; + $graphdata[$ts] = stats_message_count($channel, 60, $basetime); +} + +$max = max($graphdata); + +// Determine axis interval +$interval = 2; +if ( $max > 20 ) + $interval = 4; +if ( $max > 25 ) + $interval = 5; +if ( $max > 50 ) + $interval = 10; +if ( $max > 200 ) + $interval = 40; +if ( $max > 500 ) + $interval = 80; +if ( $max > 1000 ) + $interval = 100; +if ( $max > 2000 ) + $interval = 200; +if ( $max > 5000 ) + $interval = 1000; +if ( $max > 15000 ) + $interval = 1500; +if ( $max > 30000 ) + $interval = round($max / 10); + +$g = new GraphMaker(); // _Compat(); + +$g->SetGraphPadding(20, 30, 20, 15); +$g->SetGraphAreaHeight(200); +$g->SetBarPadding(10); +$g->SetBarData($graphdata); +$g->SetGraphBackgroundTransparent(240, 250, 255, 0); +$g->SetGraphTransparency(25); +$g->SetAxisStep($interval); +$g->SetGraphTitle($channel . ' message count - last 24 hours'); + +$g->DrawGraph(); diff -r 1d6e762433fe -r 0acb8d9a3194 htdocs/changetz.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/htdocs/changetz.php Mon Aug 25 12:34:26 2008 -0400 @@ -0,0 +1,99 @@ + + + Change time zone + + + + ' . "Successfully set time zone to {$set_zone}. Return to the stats page." . ''; + } + ?> +
+ Select time zone: + +
+ Make sure you have cookies enabled. +
+ + diff -r 1d6e762433fe -r 0acb8d9a3194 htdocs/datafile.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/htdocs/datafile.php Mon Aug 25 12:34:26 2008 -0400 @@ -0,0 +1,6 @@ + + + + + <?php echo $nick; ?> - Statistics + + + +
+

+ change]
'; + echo 'The time now is ' . date('H:i:s') . '.
Statistics last written to disk at ' . date('H:i:s', filemtime('../stats-data.php')) . '.
'; + ?> +

+

+ Channels:
+ $c ) + { + $bold = ( $c == $channel ); + echo $bold ? '' : ''; + echo $bold ? '' : ''; + echo $c; + echo $bold ? '' : ''; + echo $bold ? '' : ''; + echo $i == count($channels) - 1 ? '' : ' | '; + } + ?> +

+
+

Active members

+

For the last 1, 5, and 15 minutes: + +

+

Currently active members:

+

These people have posted in the last 3 minutes:

+ +

Last 20 minutes:

+ +

Last 24 hours

+ Graph image + + + + diff -r 1d6e762433fe -r 0acb8d9a3194 htdocs/json.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/htdocs/json.php Mon Aug 25 12:34:26 2008 -0400 @@ -0,0 +1,6 @@ + + + <?php echo $nick; ?> - privacy info + + + +

Privacy information

+

is designed to collect IRC statistics. It does this by recording raw data and then letting the frontend (index.php and a + few backend functions in stats-fe.php) look at the data and draw graphs and measurements based on it.

+

The only information collects is

+ +

also gives you the ability to disable recording statistics about you. To clear all your past statistics, type in any channel:

+

!deluser

+

You can also prevent yourself from being logged in the future with:

+

/msg anonymize

+

Remove yourself from the anonymization list with:

+

/msg denonymize

+

Want to know more about the numbers collects? Download 's data file yourself (in JSON format).

+ + diff -r 1d6e762433fe -r 0acb8d9a3194 htdocs/snippets.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/htdocs/snippets.php Mon Aug 25 12:34:26 2008 -0400 @@ -0,0 +1,164 @@ +user_level < USER_LEVEL_ADMIN ) +{ + die_friendly('Access denied', '

Admin rights needed to use this script.

'); +} + +$db->close(); +unset($db, $session, $paths, $template, $plugins); +*/ + +// We're authed. +// Load config +require(ENANOBOT_ROOT . 'config.php'); + +// check config +if ( empty($mysql_host) || empty($mysql_user) || empty($mysql_dbname) ) +{ + die("Bad config file - have a look at config-sample.php.\n"); +} + +// connect to MySQL +$mysql_conn = @mysql_connect($mysql_host, $mysql_user, $mysql_pass); +if ( !$mysql_conn ) +{ + $m_e = mysql_error(); + echo "Error connecting to MySQL: $m_e\n"; + exit(1); +} +$q = @mysql_query('USE `' . $mysql_dbname . '`;', $mysql_conn); +if ( !$q ) +{ + $m_e = mysql_error(); + echo "Error selecting database: $m_e\n"; + exit(1); +} + +function mysql_die() +{ + $m_e = mysql_error(); + die("MySQL error: $m_e"); +} + +?> + + + EnanoBot snippet management + + + +

EnanoBot snippet management

+
+
+ Add a snippet + + + + + + + + + + + + + +
Snippet code
+ all lowercase, no spaces; ex: mysnippet
Text
+ anything you want, keep it relatively short.
Channels
+ separate with pipe characters, ex: #enano|#enano-dev|#ubuntu
+
+
+ Edit existing snippets + + + + + + + + $row['snippet_id'], + 'snippet_code' => $_POST['snippet'][$row['snippet_id']]['code'], + 'snippet_text' => $_POST['snippet'][$row['snippet_id']]['text'], + 'snippet_channels' => $_POST['snippet'][$row['snippet_id']]['channels'] + ); + } + } + } + echo ' '; + echo ''; + echo ''; + echo ''; + echo ''; + echo '' . "\n "; + } + ?>
CodeSnippet textChannelsDelete
+
+
+ +
+
+ +sock ) throw new Exception('Could not make socket connection to host.'); - stream_set_timeout($this->sock, 5); - - // Wait for initial ident messages - while ( $msg = $this->get() ) - { - } + stream_set_timeout($this->sock, 1); // Send nick and username $this->put("NICK $nick\r\n"); $this->put("USER $username 0 * :$realname\r\n"); - // Wait for response and end of motd - $motd = ''; - while ( $msg = $this->get() ) + // wait for a mode +i or end of the motd + while ( true ) { - // Match particles - $msg = trim($msg); - $mc = preg_match('/^:([A-z0-9\.-]+) ([0-9]+) [A-z0-9_-]+ :(.+)$/', $msg, $match); - if ( !$mc ) + $msg = $this->get(); + if ( empty($msg) ) + continue; + if ( ( strstr($msg, 'MODE') && strstr($msg, '+i') ) || strstr(strtolower($msg), 'end of /motd') ) { - $mc = preg_match('/^:([A-z0-9_-]+)!([A-z0-9_-]+)@([A-z0-9_\.-]+) NOTICE [A-z0-9_-]+ :(.+)$/', $msg, $match); - if ( !$mc ) - continue; - // Look for a response from NickServ - if ( $match[1] == 'NickServ' ) - { - // Asking for auth? - if ( strpos($match[4], 'IDENTIFY') ) - { - // Yes, send password - $this->privmsg('NickServ', "IDENTIFY $pass"); - } - } + break; } - list(, $host, $stat, $msg) = $match; - $motd .= "$msg"; + if ( preg_match('/^PING :(.+?)$/', $msg, $match) ) + { + $this->put("PONG :{$match[1]}\r\n"); + } } + // identify to nickserv + $this->privmsg('NickServ', "IDENTIFY $pass"); + $this->nick = $nick; $this->user = $username; } @@ -222,11 +209,12 @@ if ( preg_match('/^PING :(.+?)$/', $data_trim, $pmatch) ) { $this->put("PONG :{$pmatch[1]}\r\n"); + eval(eb_fetch_hook('event_ping')); } else if ( $match ) { // Received PRIVMSG or other mainstream action - if ( $match['action'] == 'JOIN' ) + if ( $match['action'] == 'JOIN' || $match['action'] == 'PART' ) $channel =& $match['message']; else $channel =& $match['target']; @@ -235,7 +223,7 @@ { // Private message from user $result = $this->handle_privmsg($data); - stream_set_timeout($this->sock, 0xFFFFFFFE); + @stream_set_timeout($this->sock, 0xFFFFFFFE); } else if ( isset($this->channels[strtolower($channel)]) ) { @@ -243,7 +231,7 @@ $chan =& $this->channels[strtolower($channel)]; $func = $chan->get_handler(); $result = @call_user_func($func, $data, $chan); - stream_set_timeout($this->sock, 0xFFFFFFFE); + @stream_set_timeout($this->sock, 0xFFFFFFFE); } if ( $result == 'BREAK' ) { @@ -397,13 +385,14 @@ { $this->parent = $parent; $this->parent->put("JOIN $channel\r\n"); - stream_set_timeout($this->parent->sock, 3); - while ( $msg = $this->parent->get() ) - { - // Do nothing - } + // stream_set_timeout($this->parent->sock, 3); + // while ( $msg = $this->parent->get() ) + // { + // // Do nothing + // } $this->channel_name = $channel; $this->handler = $handler; + eval(eb_fetch_hook('event_self_join')); } /** diff -r 1d6e762433fe -r 0acb8d9a3194 libjson.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libjson.php Mon Aug 25 12:34:26 2008 -0400 @@ -0,0 +1,1037 @@ +_cycleCheck = $cycleCheck; + } + + /** + * Use the JSON encoding scheme for the value specified + * + * @param mixed $value The value to be encoded + * @param boolean $cycleCheck Whether or not to check for possible object recursion when encoding + * @return string The encoded value + */ + public static function encode($value, $cycleCheck = false) + { + $encoder = new Zend_Json_Encoder(($cycleCheck) ? true : false); + + return $encoder->_encodeValue($value); + } + + /** + * Recursive driver which determines the type of value to be encoded + * and then dispatches to the appropriate method. $values are either + * - objects (returns from {@link _encodeObject()}) + * - arrays (returns from {@link _encodeArray()}) + * - basic datums (e.g. numbers or strings) (returns from {@link _encodeDatum()}) + * + * @param $value mixed The value to be encoded + * @return string Encoded value + */ + protected function _encodeValue(&$value) + { + if (is_object($value)) { + return $this->_encodeObject($value); + } else if (is_array($value)) { + return $this->_encodeArray($value); + } + + return $this->_encodeDatum($value); + } + + + + /** + * Encode an object to JSON by encoding each of the public properties + * + * A special property is added to the JSON object called '__className' + * that contains the name of the class of $value. This is used to decode + * the object on the client into a specific class. + * + * @param $value object + * @return string + * @throws Zend_Json_Exception If recursive checks are enabled and the object has been serialized previously + */ + protected function _encodeObject(&$value) + { + if ($this->_cycleCheck) { + if ($this->_wasVisited($value)) { + throw new Zend_Json_Exception( + 'Cycles not supported in JSON encoding, cycle introduced by ' + . 'class "' . get_class($value) . '"' + ); + } + + $this->_visited[] = $value; + } + + $props = ''; + foreach (get_object_vars($value) as $name => $propValue) { + if (isset($propValue)) { + $props .= ',' + . $this->_encodeValue($name) + . ':' + . $this->_encodeValue($propValue); + } + } + + return '{"__className":"' . get_class($value) . '"' + . $props . '}'; + } + + + /** + * Determine if an object has been serialized already + * + * @param mixed $value + * @return boolean + */ + protected function _wasVisited(&$value) + { + if (in_array($value, $this->_visited, true)) { + return true; + } + + return false; + } + + + /** + * JSON encode an array value + * + * Recursively encodes each value of an array and returns a JSON encoded + * array string. + * + * Arrays are defined as integer-indexed arrays starting at index 0, where + * the last index is (count($array) -1); any deviation from that is + * considered an associative array, and will be encoded as such. + * + * @param $array array + * @return string + */ + protected function _encodeArray(&$array) + { + $tmpArray = array(); + + // Check for associative array + if (!empty($array) && (array_keys($array) !== range(0, count($array) - 1))) { + // Associative array + $result = '{'; + foreach ($array as $key => $value) { + $key = (string) $key; + $tmpArray[] = $this->_encodeString($key) + . ':' + . $this->_encodeValue($value); + } + $result .= implode(',', $tmpArray); + $result .= '}'; + } else { + // Indexed array + $result = '['; + $length = count($array); + for ($i = 0; $i < $length; $i++) { + $tmpArray[] = $this->_encodeValue($array[$i]); + } + $result .= implode(',', $tmpArray); + $result .= ']'; + } + + return $result; + } + + + /** + * JSON encode a basic data type (string, number, boolean, null) + * + * If value type is not a string, number, boolean, or null, the string + * 'null' is returned. + * + * @param $value mixed + * @return string + */ + protected function _encodeDatum(&$value) + { + $result = 'null'; + + if (is_int($value) || is_float($value)) { + $result = (string)$value; + } elseif (is_string($value)) { + $result = $this->_encodeString($value); + } elseif (is_bool($value)) { + $result = $value ? 'true' : 'false'; + } + + return $result; + } + + + /** + * JSON encode a string value by escaping characters as necessary + * + * @param $value string + * @return string + */ + protected function _encodeString(&$string) + { + // Escape these characters with a backslash: + // " \ / \n \r \t \b \f + $search = array('\\', "\n", "\t", "\r", "\b", "\f", '"'); + $replace = array('\\\\', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'); + $string = str_replace($search, $replace, $string); + + // Escape certain ASCII characters: + // 0x08 => \b + // 0x0c => \f + $string = str_replace(array(chr(0x08), chr(0x0C)), array('\b', '\f'), $string); + + return '"' . $string . '"'; + } + + + /** + * Encode the constants associated with the ReflectionClass + * parameter. The encoding format is based on the class2 format + * + * @param $cls ReflectionClass + * @return string Encoded constant block in class2 format + */ + private static function _encodeConstants(ReflectionClass $cls) + { + $result = "constants : {"; + $constants = $cls->getConstants(); + + $tmpArray = array(); + if (!empty($constants)) { + foreach ($constants as $key => $value) { + $tmpArray[] = "$key: " . self::encode($value); + } + + $result .= implode(', ', $tmpArray); + } + + return $result . "}"; + } + + + /** + * Encode the public methods of the ReflectionClass in the + * class2 format + * + * @param $cls ReflectionClass + * @return string Encoded method fragment + * + */ + private static function _encodeMethods(ReflectionClass $cls) + { + $methods = $cls->getMethods(); + $result = 'methods:{'; + + $started = false; + foreach ($methods as $method) { + if (! $method->isPublic() || !$method->isUserDefined()) { + continue; + } + + if ($started) { + $result .= ','; + } + $started = true; + + $result .= '' . $method->getName(). ':function('; + + if ('__construct' != $method->getName()) { + $parameters = $method->getParameters(); + $paramCount = count($parameters); + $argsStarted = false; + + $argNames = "var argNames=["; + foreach ($parameters as $param) { + if ($argsStarted) { + $result .= ','; + } + + $result .= $param->getName(); + + if ($argsStarted) { + $argNames .= ','; + } + + $argNames .= '"' . $param->getName() . '"'; + + $argsStarted = true; + } + $argNames .= "];"; + + $result .= "){" + . $argNames + . 'var result = ZAjaxEngine.invokeRemoteMethod(' + . "this, '" . $method->getName() + . "',argNames,arguments);" + . 'return(result);}'; + } else { + $result .= "){}"; + } + } + + return $result . "}"; + } + + + /** + * Encode the public properties of the ReflectionClass in the class2 + * format. + * + * @param $cls ReflectionClass + * @return string Encode properties list + * + */ + private static function _encodeVariables(ReflectionClass $cls) + { + $properties = $cls->getProperties(); + $propValues = get_class_vars($cls->getName()); + $result = "variables:{"; + $cnt = 0; + + $tmpArray = array(); + foreach ($properties as $prop) { + if (! $prop->isPublic()) { + continue; + } + + $tmpArray[] = $prop->getName() + . ':' + . self::encode($propValues[$prop->getName()]); + } + $result .= implode(',', $tmpArray); + + return $result . "}"; + } + + /** + * Encodes the given $className into the class2 model of encoding PHP + * classes into JavaScript class2 classes. + * NOTE: Currently only public methods and variables are proxied onto + * the client machine + * + * @param $className string The name of the class, the class must be + * instantiable using a null constructor + * @param $package string Optional package name appended to JavaScript + * proxy class name + * @return string The class2 (JavaScript) encoding of the class + * @throws Zend_Json_Exception + */ + public static function encodeClass($className, $package = '') + { + $cls = new ReflectionClass($className); + if (! $cls->isInstantiable()) { + throw new Zend_Json_Exception("$className must be instantiable"); + } + + return "Class.create('$package$className',{" + . self::_encodeConstants($cls) ."," + . self::_encodeMethods($cls) ."," + . self::_encodeVariables($cls) .'});'; + } + + + /** + * Encode several classes at once + * + * Returns JSON encoded classes, using {@link encodeClass()}. + * + * @param array $classNames + * @param string $package + * @return string + */ + public static function encodeClasses(array $classNames, $package = '') + { + $result = ''; + foreach ($classNames as $className) { + $result .= self::encodeClass($className, $package); + } + + return $result; + } + +} + +/** + * Decode JSON encoded string to PHP variable constructs + * + * @category Zend + * @package Zend_Json + * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Json_Decoder +{ + /** + * Parse tokens used to decode the JSON object. These are not + * for public consumption, they are just used internally to the + * class. + */ + const EOF = 0; + const DATUM = 1; + const LBRACE = 2; + const LBRACKET = 3; + const RBRACE = 4; + const RBRACKET = 5; + const COMMA = 6; + const COLON = 7; + + /** + * Use to maintain a "pointer" to the source being decoded + * + * @var string + */ + protected $_source; + + /** + * Caches the source length + * + * @var int + */ + protected $_sourceLength; + + /** + * The offset within the souce being decoded + * + * @var int + * + */ + protected $_offset; + + /** + * The current token being considered in the parser cycle + * + * @var int + */ + protected $_token; + + /** + * Flag indicating how objects should be decoded + * + * @var int + * @access protected + */ + protected $_decodeType; + + /** + * Constructor + * + * @param string $source String source to decode + * @param int $decodeType How objects should be decoded -- see + * {@link Zend_Json::TYPE_ARRAY} and {@link Zend_Json::TYPE_OBJECT} for + * valid values + * @return void + */ + protected function __construct($source, $decodeType) + { + + // eliminate comments + $source = preg_replace(array( + + // eliminate single line comments in '// ...' form + '#^\s*//(.+)$#m', + + // eliminate multi-line comments in '/* ... */' form, at start of string + '#^\s*/\*(.+)\*/#Us', + + // eliminate multi-line comments in '/* ... */' form, at end of string + '#/\*(.+)\*/\s*$#Us' + + ), '', $source); + + // Set defaults + $this->_source = $source; + $this->_sourceLength = strlen($source); + $this->_token = self::EOF; + $this->_offset = 0; + + // Normalize and set $decodeType + if (!in_array($decodeType, array(Zend_Json::TYPE_ARRAY, Zend_Json::TYPE_OBJECT))) + { + $decodeType = Zend_Json::TYPE_ARRAY; + } + $this->_decodeType = $decodeType; + + // Set pointer at first token + $this->_getNextToken(); + } + + /** + * Decode a JSON source string + * + * Decodes a JSON encoded string. The value returned will be one of the + * following: + * - integer + * - float + * - boolean + * - null + * - StdClass + * - array + * - array of one or more of the above types + * + * By default, decoded objects will be returned as associative arrays; to + * return a StdClass object instead, pass {@link Zend_Json::TYPE_OBJECT} to + * the $objectDecodeType parameter. + * + * Throws a Zend_Json_Exception if the source string is null. + * + * @static + * @access public + * @param string $source String to be decoded + * @param int $objectDecodeType How objects should be decoded; should be + * either or {@link Zend_Json::TYPE_ARRAY} or + * {@link Zend_Json::TYPE_OBJECT}; defaults to TYPE_ARRAY + * @return mixed + * @throws Zend_Json_Exception + */ + public static function decode($source = null, $objectDecodeType = Zend_Json::TYPE_ARRAY) + { + if (null === $source) { + throw new Zend_Json_Exception('Must specify JSON encoded source for decoding'); + } elseif (!is_string($source)) { + throw new Zend_Json_Exception('Can only decode JSON encoded strings'); + } + + $decoder = new self($source, $objectDecodeType); + + return $decoder->_decodeValue(); + } + + + /** + * Recursive driving rountine for supported toplevel tops + * + * @return mixed + */ + protected function _decodeValue() + { + switch ($this->_token) { + case self::DATUM: + $result = $this->_tokenValue; + $this->_getNextToken(); + return($result); + break; + case self::LBRACE: + return($this->_decodeObject()); + break; + case self::LBRACKET: + return($this->_decodeArray()); + break; + default: + return null; + break; + } + } + + /** + * Decodes an object of the form: + * { "attribute: value, "attribute2" : value,...} + * + * If ZJsonEnoder or ZJAjax was used to encode the original object + * then a special attribute called __className which specifies a class + * name that should wrap the data contained within the encoded source. + * + * Decodes to either an array or StdClass object, based on the value of + * {@link $_decodeType}. If invalid $_decodeType present, returns as an + * array. + * + * @return array|StdClass + */ + protected function _decodeObject() + { + $members = array(); + $tok = $this->_getNextToken(); + + while ($tok && $tok != self::RBRACE) { + if ($tok != self::DATUM || ! is_string($this->_tokenValue)) { + throw new Zend_Json_Exception('Missing key in object encoding: ' . $this->_source); + } + + $key = $this->_tokenValue; + $tok = $this->_getNextToken(); + + if ($tok != self::COLON) { + throw new Zend_Json_Exception('Missing ":" in object encoding: ' . $this->_source); + } + + $tok = $this->_getNextToken(); + $members[$key] = $this->_decodeValue(); + $tok = $this->_token; + + if ($tok == self::RBRACE) { + break; + } + + if ($tok != self::COMMA) { + throw new Zend_Json_Exception('Missing "," in object encoding: ' . $this->_source); + } + + $tok = $this->_getNextToken(); + } + + switch ($this->_decodeType) { + case Zend_Json::TYPE_OBJECT: + // Create new StdClass and populate with $members + $result = new StdClass(); + foreach ($members as $key => $value) { + $result->$key = $value; + } + break; + case Zend_Json::TYPE_ARRAY: + default: + $result = $members; + break; + } + + $this->_getNextToken(); + return $result; + } + + /** + * Decodes a JSON array format: + * [element, element2,...,elementN] + * + * @return array + */ + protected function _decodeArray() + { + $result = array(); + $starttok = $tok = $this->_getNextToken(); // Move past the '[' + $index = 0; + + while ($tok && $tok != self::RBRACKET) { + $result[$index++] = $this->_decodeValue(); + + $tok = $this->_token; + + if ($tok == self::RBRACKET || !$tok) { + break; + } + + if ($tok != self::COMMA) { + throw new Zend_Json_Exception('Missing "," in array encoding: ' . $this->_source); + } + + $tok = $this->_getNextToken(); + } + + $this->_getNextToken(); + return($result); + } + + + /** + * Removes whitepsace characters from the source input + */ + protected function _eatWhitespace() + { + if (preg_match( + '/([\t\b\f\n\r ])*/s', + $this->_source, + $matches, + PREG_OFFSET_CAPTURE, + $this->_offset) + && $matches[0][1] == $this->_offset) + { + $this->_offset += strlen($matches[0][0]); + } + } + + + /** + * Retrieves the next token from the source stream + * + * @return int Token constant value specified in class definition + */ + protected function _getNextToken() + { + $this->_token = self::EOF; + $this->_tokenValue = null; + $this->_eatWhitespace(); + + if ($this->_offset >= $this->_sourceLength) { + return(self::EOF); + } + + $str = $this->_source; + $str_length = $this->_sourceLength; + $i = $this->_offset; + $start = $i; + + switch ($str{$i}) { + case '{': + $this->_token = self::LBRACE; + break; + case '}': + $this->_token = self::RBRACE; + break; + case '[': + $this->_token = self::LBRACKET; + break; + case ']': + $this->_token = self::RBRACKET; + break; + case ',': + $this->_token = self::COMMA; + break; + case ':': + $this->_token = self::COLON; + break; + case '"': + $result = ''; + do { + $i++; + if ($i >= $str_length) { + break; + } + + $chr = $str{$i}; + if ($chr == '\\') { + $i++; + if ($i >= $str_length) { + break; + } + $chr = $str{$i}; + switch ($chr) { + case '"' : + $result .= '"'; + break; + case '\\': + $result .= '\\'; + break; + case '/' : + $result .= '/'; + break; + case 'b' : + $result .= chr(8); + break; + case 'f' : + $result .= chr(12); + break; + case 'n' : + $result .= chr(10); + break; + case 'r' : + $result .= chr(13); + break; + case 't' : + $result .= chr(9); + break; + case '\'' : + $result .= '\''; + break; + default: + throw new Zend_Json_Exception("Illegal escape " + . "sequence '" . $chr . "'"); + } + } elseif ($chr == '"') { + break; + } else { + $result .= $chr; + } + } while ($i < $str_length); + + $this->_token = self::DATUM; + //$this->_tokenValue = substr($str, $start + 1, $i - $start - 1); + $this->_tokenValue = $result; + break; + case "'": + $result = ''; + do { + $i++; + if ($i >= $str_length) { + break; + } + + $chr = $str{$i}; + if ($chr == '\\') { + $i++; + if ($i >= $str_length) { + break; + } + $chr = $str{$i}; + switch ($chr) { + case "'" : + $result .= "'"; + break; + case '\\': + $result .= '\\'; + break; + case '/' : + $result .= '/'; + break; + case 'b' : + $result .= chr(8); + break; + case 'f' : + $result .= chr(12); + break; + case 'n' : + $result .= chr(10); + break; + case 'r' : + $result .= chr(13); + break; + case 't' : + $result .= chr(9); + break; + case '"' : + $result .= '"'; + break; + default: + throw new Zend_Json_Exception("Illegal escape " + . "sequence '" . $chr . "'"); + } + } elseif ($chr == "'") { + break; + } else { + $result .= $chr; + } + } while ($i < $str_length); + + $this->_token = self::DATUM; + //$this->_tokenValue = substr($str, $start + 1, $i - $start - 1); + $this->_tokenValue = $result; + break; + case 't': + if (($i+ 3) < $str_length && substr($str, $start, 4) == "true") { + $this->_token = self::DATUM; + } + $this->_tokenValue = true; + $i += 3; + break; + case 'f': + if (($i+ 4) < $str_length && substr($str, $start, 5) == "false") { + $this->_token = self::DATUM; + } + $this->_tokenValue = false; + $i += 4; + break; + case 'n': + if (($i+ 3) < $str_length && substr($str, $start, 4) == "null") { + $this->_token = self::DATUM; + } + $this->_tokenValue = NULL; + $i += 3; + break; + case ' ': + break; + } + + if ($this->_token != self::EOF) { + $this->_offset = $i + 1; // Consume the last token character + return($this->_token); + } + + $chr = $str{$i}; + if ($chr == '-' || $chr == '.' || ($chr >= '0' && $chr <= '9')) { + if (preg_match('/-?([0-9])*(\.[0-9]*)?((e|E)((-|\+)?)[0-9]+)?/s', + $str, $matches, PREG_OFFSET_CAPTURE, $start) && $matches[0][1] == $start) { + + $datum = $matches[0][0]; + + if (is_numeric($datum)) { + if (preg_match('/^0\d+$/', $datum)) { + throw new Zend_Json_Exception("Octal notation not supported by JSON (value: $datum)"); + } else { + $val = intval($datum); + $fVal = floatval($datum); + $this->_tokenValue = ($val == $fVal ? $val : $fVal); + } + } else { + throw new Zend_Json_Exception("Illegal number format: $datum"); + } + + $this->_token = self::DATUM; + $this->_offset = $start + strlen($datum); + } + } else { + throw new Zend_Json_Exception("Illegal Token at pos $i: $chr\nContext:\n--------------------------------------------------" . substr($str, $i) . "\n--------------------------------------------------"); + } + + return($this->_token); + } +} + +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Json + * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + + +/** + * @category Zend + * @package Zend_Json + * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Json_Exception extends Zend_Exception +{} + +/** + * @category Zend + * @package Zend + * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Exception extends Exception +{} + +/** + * Class for encoding to and decoding from JSON. + * + * @category Zend + * @package Zend_Json + * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Json +{ + /** + * How objects should be encoded -- arrays or as StdClass. TYPE_ARRAY is 1 + * so that it is a boolean true value, allowing it to be used with + * ext/json's functions. + */ + const TYPE_ARRAY = 1; + const TYPE_OBJECT = 0; + + /** + * @var bool + */ + public static $useBuiltinEncoderDecoder = true; + + /** + * Decodes the given $encodedValue string which is + * encoded in the JSON format + * + * Uses ext/json's json_decode if available. + * + * @param string $encodedValue Encoded in JSON format + * @param int $objectDecodeType Optional; flag indicating how to decode + * objects. See {@link ZJsonDecoder::decode()} for details. + * @return mixed + */ + public static function decode($encodedValue, $objectDecodeType = Zend_Json::TYPE_ARRAY) + { + if (function_exists('json_decode') && self::$useBuiltinEncoderDecoder !== true) { + return json_decode($encodedValue, $objectDecodeType); + } + + return Zend_Json_Decoder::decode($encodedValue, $objectDecodeType); + } + + + /** + * Encode the mixed $valueToEncode into the JSON format + * + * Encodes using ext/json's json_encode() if available. + * + * NOTE: Object should not contain cycles; the JSON format + * does not allow object reference. + * + * NOTE: Only public variables will be encoded + * + * @param mixed $valueToEncode + * @param boolean $cycleCheck Optional; whether or not to check for object recursion; off by default + * @return string JSON encoded object + */ + public static function encode($valueToEncode, $cycleCheck = false) + { + if (function_exists('json_encode') && self::$useBuiltinEncoderDecoder !== true) { + return json_encode($valueToEncode); + } + + return Zend_Json_Encoder::encode($valueToEncode, $cycleCheck); + } +} + +/** + * Wrapper for JSON encoding. + * @param mixed Variable to encode + * @return string JSON-encoded string + */ + +function eb_json_encode($data) +{ + return Zend_Json::encode($data, true); +} + +/** + * Wrapper for JSON decoding. + * @param string JSON-encoded string + * @return mixed Decoded value + */ + +function eb_json_decode($data) +{ + return Zend_Json::decode($data, Zend_Json::TYPE_ARRAY); +} + +?> diff -r 1d6e762433fe -r 0acb8d9a3194 modules/autoop.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/autoop.php Mon Aug 25 12:34:26 2008 -0400 @@ -0,0 +1,16 @@ +get_channel_name(); + + // if a known op joins the channel, send mode +o + if ( in_array($message['nick'], $privileged_list) ) + { + $chan->parent->put("MODE $channelname +o {$message['nick']}\r\n"); + } +} diff -r 1d6e762433fe -r 0acb8d9a3194 modules/doctor.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/doctor.php Mon Aug 25 12:34:26 2008 -0400 @@ -0,0 +1,41 @@ +msg(eb_censor_words("{$message['nick']}, thank you for visiting the psychotherapist. Come again soon!"), true); + } + else + { + $doctor[$message['nick']] = new Psychotherapist(); + $chan->msg(eb_censor_words("{$message['nick']}, I am the psychotherapist. Please explain your problems to me. When you are finished talking with me, type !doctor again."), true); + } + return true; + } +} + +function doctor_listen(&$chan, &$message) +{ + global $doctor; + + if ( isset($doctor[$message['nick']]) && $message['message'] != '!doctor' ) + { + $chan->msg(eb_censor_words($doctor[$message['nick']]->listen($message['message']))); + } +} + +function doctor_greet(&$append) +{ + $append .= ' Type !doctor for the psychotherapist.'; +} diff -r 1d6e762433fe -r 0acb8d9a3194 modules/echo.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/echo.php Mon Aug 25 12:34:26 2008 -0400 @@ -0,0 +1,29 @@ +msg(eb_censor_words(preg_replace('/^\!echo /', '', $message['message'])), true); + } +} + +function echo_event_privmsg($message) +{ + global $privileged_list; + + if ( in_array($message['nick'], $privileged_list) && preg_match("/^\!echo-([^\007, \r\n\a\t]+) /", $message['message'], $match) ) + { + global $libirc_channels; + $channel_name =& $match[1]; + if ( isset($libirc_channels[$channel_name]) && is_object($libirc_channels[$channel_name]) ) + { + $libirc_channels[$channel_name]->msg(eb_censor_words(preg_replace("/^\!echo-([^\007, \r\n\a\t]+) /", '', $message['message'])), true); + } + } +} diff -r 1d6e762433fe -r 0acb8d9a3194 modules/greeting.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/greeting.php Mon Aug 25 12:34:26 2008 -0400 @@ -0,0 +1,32 @@ += time() ) + { + $chan->msg("Welcome back."); + $wb = true; + } + } + if ( !$wb ) + { + $append = ''; + eval(eb_fetch_hook('event_greeting')); + $chan->msg(eb_censor_words("Hi, {$message['nick']}.$append")); + } + break; + case 'PART': + $part_list[$message['nick']] = time(); + break; + } +} diff -r 1d6e762433fe -r 0acb8d9a3194 modules/log.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/log.php Mon Aug 25 12:34:26 2008 -0400 @@ -0,0 +1,48 @@ +get_channel_name()); + $nick_db = mysql_real_escape_string($message['nick']); + $line_db = mysql_real_escape_string($message['message']); + $day = date('Y-m-d'); + $time = time(); + $m_et = false; + $sql = false; + switch($message['action']) + { + case 'PRIVMSG': + if ( substr($line_db, 0, 5) != '[off]' ) + { + $sql = "INSERT INTO irclog(channel, day, nick, timestamp, line) VALUES + ( '$chan_db', '$day', '$nick_db', '$time', '$line_db' );"; + } + break; + case 'JOIN': + $sql = "INSERT INTO irclog(channel, day, nick, timestamp, line) VALUES + ( '$chan_db', '$day', '', '$time', '$nick_db has joined $chan_db' );"; + break; + case 'PART': + $sql = "INSERT INTO irclog(channel, day, nick, timestamp, line) VALUES + ( '$chan_db', '$day', '', '$time', '$nick_db has left $chan_db' );"; + break; + case 'MODE': + list($mode, $target_nick) = explode(' ', $line_db); + if ( $message['nick'] != 'ChanServ' && $target_nick != $nick ) + { + $sql = "INSERT INTO irclog(channel, day, nick, timestamp, line) VALUES + ( '$chan_db', '$day', '', '$time', '$nick_db set mode $mode on $target_nick' );"; + } + break; + } + if ( $sql ) + { + eb_mysql_query($sql); + } +} + diff -r 1d6e762433fe -r 0acb8d9a3194 modules/snippets.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/snippets.php Mon Aug 25 12:34:26 2008 -0400 @@ -0,0 +1,67 @@ +msg(eb_censor_words("{$message['nick']}, I couldn't find that snippet (\"$snippet\") in the database."), true); + } + else + { + $snippets = array(); + while ( $row = mysql_fetch_assoc($q) ) + { + $channels = explode('|', $row['snippet_channels']); + if ( in_array($chan->get_channel_name(), $channels) ) + { + $snippets[] = $row['snippet_code']; + } + } + $snippets = implode(', ', $snippets); + $chan->msg(eb_censor_words("{$message['nick']}, the following snippets are available: $snippets"), true); + } + @mysql_free_result($q); + } + else + { + if ( eval(eb_fetch_hook('snippet_dynamic')) ) + { + return true; + } + + // Look for the snippet... + $q = eb_mysql_query('SELECT snippet_text, snippet_channels FROM snippets WHERE snippet_code = \'' . mysql_real_escape_string($snippet) . '\';'); + if ( mysql_num_rows($q) < 1 ) + { + $chan->msg(eb_censor_words("{$message['nick']}, I couldn't find that snippet (\"$snippet\") in the database."), true); + } + else + { + $row = mysql_fetch_assoc($q); + $channels = explode('|', $row['snippet_channels']); + if ( in_array($chan->get_channel_name(), $channels) ) + { + $chan->msg(eb_censor_words("{$target_nick}{$row['snippet_text']}"), true); + } + else + { + $chan->msg(eb_censor_words("{$message['nick']}, I couldn't find that snippet (\"$snippet\") in the database."), true); + } + } + @mysql_free_result($q); + } + } +} diff -r 1d6e762433fe -r 0acb8d9a3194 modules/stats.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/stats.php Mon Aug 25 12:34:26 2008 -0400 @@ -0,0 +1,259 @@ + '@', + 'v' => '+' +); +$stats_data = array('anonymous' => array(), 'messages' => array()); +@include('./stats-data.php'); +unset($stats_data['members']); +$stats_data['members'] =& $stats_memberlist; + +eb_hook('event_self_join', 'stats_init_channel($this);'); +eb_hook('event_raw_message', 'stats_process_message($chan, $message);'); +eb_hook('snippet_dynamic', 'if ( $snippet === "memberlist" ) return stats_list_members($chan, $message); if ( $snippet === "deluser" ) return stats_del_user($chan, $message);'); +eb_hook('event_other', 'stats_handle_other_event($message);'); +eb_hook('event_privmsg', 'stats_handle_privmsg($message);'); + +function stats_init_channel(&$chan) +{ + global $stats_memberlist, $stats_prefixes, $stats_data; + + $channel_name = $chan->get_channel_name(); + $stats_memberlist[$channel_name] = array(); + $prefixes_regexp = '/^([' . preg_quote(implode('', $stats_prefixes)) . '])+/'; + $prefixes_flipped = array_flip($stats_prefixes); + $prefixes_regexp_notlist = '/[^' . preg_quote(implode('', $prefixes_flipped)) . ']/'; + + if ( !isset($stats_data['messages'][$channel_name]) ) + { + $stats_data['messages'][$channel_name] = array(); + } + + // read list of members from channel + @stream_set_timeout($chan->parent->sock, 3); + while ( $msg = $chan->parent->get() ) + { + if ( $ml = strstr($msg, ' 353 ') ) + { + $memberlist = trim(substr(strstr($ml, ':'), 1)); + $stats_memberlist[$channel_name] = explode(' ', $memberlist); + $stats_memberlist[$channel_name] = array_flip($stats_memberlist[$channel_name]); + foreach ( $stats_memberlist[$channel_name] as $nick => $_ ) + { + $stats_memberlist[$channel_name][$nick] = ''; + while ( preg_match($prefixes_regexp, $nick) ) + { + $prefix = substr($nick, 0, 1); + $add = preg_replace($prefixes_regexp_notlist, '', strval($stats_memberlist[$channel_name][$nick])); + unset($stats_memberlist[$channel_name][$nick]); + $nick = substr($nick, 1); + $stats_memberlist[$channel_name][$nick] = $prefixes_flipped[$prefix] . $add; + } + } + break; + } + } +} + +function stats_process_message(&$chan, $message) +{ + global $stats_memberlist, $stats_data; + $channel_name = $chan->get_channel_name(); + if ( !isset($stats_memberlist[$channel_name]) ) + { + return false; + } + + $ml =& $stats_memberlist[$channel_name]; + + // we need to change statistics accordingly depending on the event + if ( $message['action'] == 'JOIN' ) + { + // member joined - init their flags and up the member count by one + $ml[$message['nick']] = ''; + } + else if ( $message['action'] == 'PART' ) + { + // member left - clear flags and decrement the total member count + unset($ml[$message['nick']]); + $ml = array_values($ml); + } + else if ( $message['action'] == 'MODE' ) + { + // update member list (not sure why this would be useful, but export it anyway - display scripts might find it useful) + list($mode, $target) = explode(' ', $message['message']); + $action = substr($mode, 0, 1); + + global $stats_prefixes; + $ml[$target] = str_replace(substr($mode, 1), '', $ml[$target]); + if ( $action == '+' ) + { + $ml[$target] .= substr($mode, 1); + } + } + else if ( $message['action'] == 'PRIVMSG' ) + { + // private message into $channel_name - mark the user active and log the message time + if ( isset($stats_data['anonymous'][$message['nick']]) ) + $message['nick'] = 'Anonymous'; + + $messages =& $stats_data['messages'][$channel_name]; + + $messages[] = array( + 'time' => time(), + 'nick' => $message['nick'] + ); + } + + stats_cron(); +} + +function stats_list_members(&$chan, &$message) +{ + global $stats_memberlist; + $channel_name = $chan->get_channel_name(); + if ( !isset($stats_memberlist[$channel_name]) ) + { + return false; + } + + $ml =& $stats_memberlist[$channel_name]; + + $chan->parent->privmsg($message['nick'], "memberlist:\n" . str_replace("\n", ' ', print_r($ml, true))); + + return true; +} + +function stats_del_user(&$chan, &$message) +{ + global $stats_memberlist, $privileged_list, $irc, $stats_data; + + // remove a user from the DB + $targetuser = trim(substr(strstr($message['message'], '|'), 1)); + if ( empty($targetuser) ) + $targetuser = $message['nick']; + + if ( $targetuser != $message['nick'] && !in_array($message['nick'], $privileged_list) ) + { + $irc->privmsg($message['nick'], "Sorry, you need to be a moderator to delete statistics for users other than yourself."); + return true; + } + + // we should be good - delete the user + foreach ( $stats_data['messages'] as $channel => &$messages ) + { + foreach ( $messages as $i => &$currentmessage ) + { + if ( $currentmessage['nick'] == $targetuser ) + { + unset($messages[$i]); + } + } + $messages = array_values($messages); + } + unset($users, $currentmessage, $messages); + + global $nick; + $greeting = ( $targetuser == $message['nick'] ) ? "All of your statistics data" : "All of {$targetuser}'s statistic data"; + $irc->privmsg($message['nick'], "$greeting has been removed from the database for all channels. The changes will show up in the next commit to disk, which is usually no more than once every two minutes."); + $irc->privmsg($message['nick'], "Want your stats to be anonymized in the future? Type /msg $nick anonymize to make me keep all your stats anonymous in the future. This only applies to your current nick though - for example if you change your nick to \"{$message['nick']}|sleep\" or similar your information will not be anonymous."); + $irc->privmsg($message['nick'], "You can't clear your logs if you're anonymous. Type /msg $nick denonymize to remove yourself from the anonymization list. Anonymized logs can't be converted back to their original nicks."); + + return true; +} + +function stats_handle_privmsg(&$message) +{ + global $irc, $stats_data, $nick; + static $poll_list = array(); + + $message['message'] = strtolower($message['message']); + + if ( trim($message['message']) === 'anonymize' ) + { + $stats_data['anonymous'][$message['nick']] = true; + $poll_list[$message['nick']] = true; + $irc->privmsg($message['nick'], "Anonymization complete. Any further statistics recorded about you will be anonymous."); + $irc->privmsg($message['nick'], "Do you want to also anonymize any past statistics about you? (type \"yes\" or \"no\")"); + } + else if ( trim($message['message']) === 'denonymize' ) + { + $stats_data['anonymous'][$message['nick']] = false; + unset($stats_data['anonymous'][$message['nick']]); + $irc->privmsg($message['nick'], "Denonymization complete. Any further statistics recorded about you will bear your nick. Remember that you can always change this with /msg $nick anonymize."); + } + else if ( trim($message['message']) === 'yes' && isset($poll_list[$message['nick']]) ) + { + // anonymize logs for this user + // we should be good - delete the user + $targetuser = $message['nick']; + + foreach ( $stats_data['messages'] as $channel => &$messages ) + { + foreach ( $messages as $i => &$currentmessage ) + { + if ( $currentmessage['nick'] == $targetuser ) + { + $currentmessage['nick'] = 'Anonymous'; + } + } + $messages = array_values($messages); + } + unset($users, $currentmessage, $messages); + $irc->privmsg($message['nick'], "Anonymization complete. All past statistics on your nick are now anonymous."); + + unset($poll_list[$message['nick']]); + } + stats_cron(); +} + +function stats_handle_other_event(&$message) +{ + global $stats_memberlist; + + if ( $message['action'] == 'NICK' ) + { + // we have a nick change; go through all channels and replace the old nick with the new + foreach ( $stats_memberlist as &$ml ) + { + if ( isset($ml[$message['nick']]) ) + { + $ml[$message['message']] = $ml[$message['nick']]; + unset($ml[$message['nick']]); + } + } + } + stats_cron(); +} + +function stats_cron() +{ + static $commit_time = 0; + $now = time(); + // commit to disk every 1 minute + if ( $commit_time + 60 < $now ) + { + $commit_time = $now; + stats_commit(); + } +} + +function stats_commit() +{ + global $stats_data; + ob_start(); + var_export($stats_data); + $stats_data_exported = ob_get_contents(); + ob_end_clean(); + + $fp = @fopen('./stats-data.php', 'w'); + if ( !$fp ) + return false; + fwrite($fp, "user_level < USER_LEVEL_ADMIN ) { @@ -22,6 +23,7 @@ $db->close(); unset($db, $session, $paths, $template, $plugins); +*/ // We're authed. // Load config @@ -63,7 +65,7 @@

EnanoBot snippet management

-
+
Add a snippet diff -r 1d6e762433fe -r 0acb8d9a3194 stats-fe.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stats-fe.php Mon Aug 25 12:34:26 2008 -0400 @@ -0,0 +1,84 @@ + + */ + +if ( !isset($GLOBALS['stats_data']) ) +{ + require(dirname(__FILE__) . '/stats-data.php'); + $data =& $stats_data; +} + +define('NOW', time()); + +/** + * Gets the number of messages posted in IRC in the last X minutes. + * @param string Channel + * @param int Optional - time period for message count. Defaults to 10 minutes. + * @param int Optional - Base time, defaults to right now + * @return int + */ + +function stats_message_count($channel, $mins = 10, $base = NOW) +{ + global $data; + + $time_min = $base - ( $mins * 60 ); + $time_max = $base; + + if ( !isset($data['messages'][$channel]) ) + { + return 0; + } + + $count = 0; + foreach ( $data['messages'][$channel] as $message ) + { + if ( $message['time'] >= $time_min && $message['time'] <= $time_max ) + { + $count++; + } + } + + return $count; +} + +/** + * Gets the percentages as to who's posted the most messages in the last X minutes. + * @param string Channel name + * @param int Optional - How many minutes, defaults to 10 + * @param int Optional - Base time, defaults to right now + * @return array Associative, with floats. + */ + +function stats_activity_percent($channel, $mins = 10, $base = NOW) +{ + global $data; + if ( !($total = stats_message_count($channel, $mins, $base)) ) + { + return array(); + } + $results = array(); + $usercounts = array(); + $time_min = $base - ( $mins * 60 ); + $time_max = $base; + foreach ( $data['messages'][$channel] as $message ) + { + if ( $message['time'] >= $time_min && $message['time'] <= $time_max ) + { + if ( !isset($usercounts[$message['nick']]) ) + $usercounts[$message['nick']] = 0; + $usercounts[$message['nick']]++; + } + } + foreach ( $usercounts as $nick => $count ) + { + $results[$nick] = $count / $total; + } + arsort($results); + return $results; +} diff -r 1d6e762433fe -r 0acb8d9a3194 timezone.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/timezone.php Mon Aug 25 12:34:26 2008 -0400 @@ -0,0 +1,510 @@ +