modules/log.php
author Dan
Mon, 25 Aug 2008 12:36:37 -0400
changeset 9 4192954c29d1
parent 8 0acb8d9a3194
permissions -rw-r--r--
Finalization of merge from devel branch

<?php

eb_hook('event_raw_message', 'enanobot_log_message($chan, $message);');

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'])
  {
    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);
  }
}