enanobot.php
author Dan
Sat, 15 Mar 2008 19:53:27 -0400
changeset 0 d02690a8552c
child 1 739423b66116
permissions -rw-r--r--
Initial population. EnanoBot v0.1.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
     1
<?php
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
     2
// define('LIBIRC_DEBUG', '');
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
     3
require('libirc.php');
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
     4
require('config.php');
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
     5
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
     6
@ini_set('display_errors', 'on');
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
     7
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
     8
$mysql_conn = false;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
     9
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    10
function mysql_reconnect()
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    11
{
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    12
  global $mysql_conn, $mysql_host, $mysql_user, $mysql_pass;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    13
  if ( $mysql_conn )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    14
    @mysql_close($mysql_conn);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    15
  // connect to MySQL
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    16
  $mysql_conn = @mysql_connect($mysql_host, $mysql_user, $mysql_pass);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    17
  if ( !$mysql_conn )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    18
  {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    19
    $m_e = mysql_error();
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    20
    echo "Error connecting to MySQL: $m_e\n";
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    21
    exit(1);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    22
  }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    23
  $q = @mysql_query('USE enanobot;', $mysql_conn);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    24
  if ( !$q )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    25
  {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    26
    $m_e = mysql_error();
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    27
    echo "Error selecting database: $m_e\n";
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    28
    exit(1);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    29
  }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    30
}
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    31
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    32
mysql_reconnect();
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    33
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    34
$irc = new Request_IRC('irc.freenode.net');
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    35
$irc->connect($nick, $user, $name, $pass);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    36
$irc->set_privmsg_handler('enanobot_privmsg_event');
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    37
$enano = $irc->join('#enano', 'enanobot_channel_event_enano');
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    38
$enano_dev = $irc->join('#enano-dev', 'enanobot_channel_event_enanodev');
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    39
$irc->privmsg('ChanServ', 'OP #enano EnanoBot');
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    40
$irc->privmsg('ChanServ', 'OP #enano-dev EnanoBot');
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    41
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    42
$irc->event_loop();
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    43
$irc->close();
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    44
mysql_close($mysql_conn);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    45
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    46
function enanobot_channel_event_enano($sockdata, $chan)
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    47
{
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    48
  global $irc, $nick, $mysql_conn, $privileged_list;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    49
  $sockdata = trim($sockdata);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    50
  $message = Request_IRC::parse_message($sockdata);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    51
  switch ( $message['action'] )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    52
  {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    53
    case 'JOIN':
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    54
      // if a known op joins the channel, send mode +o
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    55
      if ( in_array($message['nick'], $privileged_list) )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    56
      {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    57
        $chan->parent->put("MODE #enano +o {$message['nick']}\r\n");
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    58
      }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    59
      break;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    60
    case 'PRIVMSG':
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    61
      enanobot_process_channel_message($sockdata, $chan, $message);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    62
      break;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    63
  }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    64
}
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    65
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    66
function enanobot_channel_event_enanodev($sockdata, $chan)
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    67
{
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    68
  global $irc, $privileged_list;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    69
  $sockdata = trim($sockdata);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    70
  $message = Request_IRC::parse_message($sockdata);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    71
  switch ( $message['action'] )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    72
  {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    73
    case 'JOIN':
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    74
      // if dandaman32 joins the channel, use mode +o
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    75
      if ( in_array($message['nick'], $privileged_list) )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    76
        $chan->parent->put("MODE #enano-dev +o {$message['nick']}\r\n");
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    77
      break;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    78
    case 'PRIVMSG':
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    79
      enanobot_process_channel_message($sockdata, $chan, $message);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    80
      break;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    81
  }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    82
}
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    83
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    84
function enanobot_process_channel_message($sockdata, $chan, $message)
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    85
{
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    86
  global $irc, $nick, $mysql_conn, $privileged_list;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    87
  
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    88
  // Log the message
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    89
  $chan_db = mysql_real_escape_string($chan->get_channel_name());
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    90
  $nick_db = mysql_real_escape_string($message['nick']);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    91
  $line_db = mysql_real_escape_string($message['message']);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    92
  $day     = date('Y-m-d');
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    93
  $time    = time();
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    94
  $m_et = false;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    95
  while ( true )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    96
  {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    97
    $q = @mysql_query("INSERT INTO irclog(channel, day, nick, timestamp, line) VALUES
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    98
                         ( '$chan_db', '$day', '$nick_db', '$time', '$line_db' );");
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    99
    if ( !$q )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   100
    {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   101
      $m_e = mysql_error();
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   102
      $m_et = true;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   103
      if ( $m_e == 'MySQL server has gone away' && !$m_et )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   104
      {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   105
        mysql_reconnect();
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   106
        continue;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   107
      }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   108
      $irc->close("MySQL query error: $m_e");
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   109
      exit(1);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   110
    }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   111
    break;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   112
  }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   113
  
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   114
  if ( preg_match('/^\!echo /', $message['message']) && in_array($message['nick'], $privileged_list) )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   115
  {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   116
    $chan->msg(preg_replace('/^\!echo /', '', $message['message']), true);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   117
  }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   118
  else if ( preg_match('/^\![\s]*([a-z0-9_-]+)([\s]*\|[\s]*([^ ]+))?$/', $message['message'], $match) )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   119
  {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   120
    $snippet =& $match[1];
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   121
    if ( @$match[3] === 'me' )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   122
      $match[3] = $message['nick'];
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   123
    $target_nick = ( !empty($match[3]) ) ? "{$match[3]}, " : "{$message['nick']}, ";
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   124
    // Look for the snippet...
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   125
    $m_et = false;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   126
    while ( true )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   127
    {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   128
      $q = mysql_query('SELECT snippet_text, snippet_channels FROM snippets WHERE snippet_code = \'' . mysql_real_escape_string($snippet) . '\';', $mysql_conn);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   129
      if ( !$q )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   130
      {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   131
        $m_e = mysql_error();
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   132
        $m_et = true;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   133
        if ( $m_e == 'MySQL server has gone away' && !$m_et )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   134
        {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   135
          mysql_reconnect();
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   136
          continue;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   137
        }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   138
        $irc->close("MySQL query error: $m_e");
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   139
        exit(1);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   140
      }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   141
      break;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   142
    }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   143
    if ( mysql_num_rows($q) < 1 )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   144
    {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   145
      $chan->msg("{$message['nick']}, I couldn't find that snippet (\"$snippet\") in the database.", true);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   146
    }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   147
    else
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   148
    {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   149
      $row = mysql_fetch_assoc($q);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   150
      $channels = explode('|', $row['snippet_channels']);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   151
      if ( in_array($chan->get_channel_name(), $channels) )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   152
      {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   153
        $chan->msg("{$target_nick}{$row['snippet_text']}", true);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   154
      }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   155
      else
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   156
      {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   157
        $chan->msg("{$message['nick']}, I couldn't find that snippet (\"$snippet\") in the database.", true);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   158
      }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   159
    }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   160
  }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   161
  else if ( strpos($message['message'], $nick) && !in_array($message['nick'], $privileged_list) && $message['nick'] != $nick )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   162
  {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   163
    $target_nick =& $message['nick'];
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   164
    $chan->msg("{$target_nick}, I'm only a bot. :-) You should probably rely on the advice of humans if you need further assistance.", true);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   165
  }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   166
}
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   167
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   168
function enanobot_privmsg_event($message)
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   169
{
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   170
  global $privileged_list, $irc;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   171
  static $part_cache = array();
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   172
  if ( in_array($message['nick'], $privileged_list) && $message['message'] == 'Suspend' && $message['action'] == 'PRIVMSG' )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   173
  {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   174
    foreach ( $irc->channels as $channel )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   175
    {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   176
      $part_cache[] = array($channel->get_channel_name(), $channel->get_handler());
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   177
      $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 EnanoBot Resume when finished.", true);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   178
      $channel->part("Logging and presence suspended by {$message['nick']}", true);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   179
    }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   180
  }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   181
  else if ( in_array($message['nick'], $privileged_list) && $message['message'] == 'Resume' && $message['action'] == 'PRIVMSG' )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   182
  {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   183
    global $nick;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   184
    foreach ( $part_cache as $chan_data )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   185
    {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   186
      $chan_name = substr($chan_data[0], 1);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   187
      $GLOBALS[$chan_name] = $irc->join($chan_data[0], $chan_data[1]);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   188
      $GLOBALS[$chan_name]->msg("Bot resumed by {$message['nick']}.", true);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   189
      $irc->privmsg('ChanServ', "OP {$chan_data[0]} $nick");
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   190
    }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   191
    $part_cache = array();
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   192
  }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   193
  else if ( in_array($message['nick'], $privileged_list) && $message['message'] == 'Shutdown' && $message['action'] == 'PRIVMSG' )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   194
  {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   195
    $irc->close("Remote bot shutdown ordered by {$message['nick']}", true);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   196
    return 'BREAK';
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   197
  }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   198
  else if ( in_array($message['nick'], $privileged_list) && preg_match('/^\!echo-enano /', $message['message']) )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   199
  {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   200
    global $enano;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   201
    $enano->msg(preg_replace('/^\!echo-enano /', '', $message['message']), true);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   202
  }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   203
}
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   204