modules/log.php
author Dan
Sat, 15 Nov 2008 15:00:52 -0500
changeset 20 e2f6e3af9959
parent 8 0acb8d9a3194
permissions -rw-r--r--
Stats now uses MySQL backend
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     1
<?php
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     2
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     3
eb_hook('event_raw_message', 'enanobot_log_message($chan, $message);');
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     4
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     5
function enanobot_log_message(&$chan, &$message)
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     6
{
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     7
  global $nick;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     8
  
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     9
  // Log the message
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    10
  $chan_db = mysql_real_escape_string($chan->get_channel_name());
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    11
  $nick_db = mysql_real_escape_string($message['nick']);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    12
  $line_db = mysql_real_escape_string($message['message']);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    13
  $day     = date('Y-m-d');
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    14
  $time    = time();
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    15
  $m_et = false;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    16
  $sql = false;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    17
  switch($message['action'])
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    18
  {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    19
    case 'PRIVMSG':
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    20
      if ( substr($line_db, 0, 5) != '[off]' )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    21
      {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    22
        $sql = "INSERT INTO irclog(channel, day, nick, timestamp, line) VALUES
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    23
                  ( '$chan_db', '$day', '$nick_db', '$time', '$line_db' );";
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    24
      }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    25
      break;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    26
    case 'JOIN':
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    27
      $sql = "INSERT INTO irclog(channel, day, nick, timestamp, line) VALUES
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    28
                ( '$chan_db', '$day', '', '$time', '$nick_db has joined $chan_db' );";
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    29
      break;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    30
    case 'PART':
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    31
      $sql = "INSERT INTO irclog(channel, day, nick, timestamp, line) VALUES
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    32
                ( '$chan_db', '$day', '', '$time', '$nick_db has left $chan_db' );";
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    33
      break;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    34
    case 'MODE':
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    35
      list($mode, $target_nick) = explode(' ', $line_db);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    36
      if ( $message['nick'] != 'ChanServ' && $target_nick != $nick )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    37
      {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    38
        $sql = "INSERT INTO irclog(channel, day, nick, timestamp, line) VALUES
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    39
                  ( '$chan_db', '$day', '', '$time', '$nick_db set mode $mode on $target_nick' );";
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    40
      }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    41
      break;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    42
  }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    43
  if ( $sql )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    44
  {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    45
    eb_mysql_query($sql);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    46
  }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    47
}
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    48