enanobot.php
author Dan
Sat, 11 Oct 2008 23:09:13 +0000
changeset 14 506a7e0fb106
parent 13 f073c94a1477
child 23 df31a3872d19
permissions -rw-r--r--
Disabled "snippet not found" message, for now
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
     1
<?php
6
a802bb5b3e08 Made the channel list completely dynamic now
Dan
parents: 4
diff changeset
     2
/**
a802bb5b3e08 Made the channel list completely dynamic now
Dan
parents: 4
diff changeset
     3
 * EnanoBot - the Enano CMS IRC logging and help automation bot
a802bb5b3e08 Made the channel list completely dynamic now
Dan
parents: 4
diff changeset
     4
 * GPL and no warranty, see the LICENSE file for more info
a802bb5b3e08 Made the channel list completely dynamic now
Dan
parents: 4
diff changeset
     5
 */
a802bb5b3e08 Made the channel list completely dynamic now
Dan
parents: 4
diff changeset
     6
7
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
     7
// parse command line
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
     8
if ( isset($argv[1]) )
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
     9
{
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    10
  $arg =& $argv[1];
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    11
  if ( $arg == '--daemon' || $arg == '-d' )
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    12
  {
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    13
    // attempt to fork...
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    14
    if ( function_exists('pcntl_fork') )
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    15
    {
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    16
      $pid = pcntl_fork();
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    17
      if ( $pid == -1 )
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    18
      {
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    19
        echo "Forking process failed.\n";
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    20
        exit(1);
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    21
      }
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    22
      else if ( $pid )
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    23
      {
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    24
        echo "EnanoBot daemon started, pid $pid\n";
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    25
        exit(0);
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    26
      }
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    27
      else
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    28
      {
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    29
        // do nothing, just continue.
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    30
      }
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    31
    }
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    32
    else
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    33
    {
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    34
      echo "No pcntl support in PHP, continuing in foreground\n";
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    35
    }
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    36
  }
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    37
  else if ( $arg == '-v' || $arg == '--verbose' )
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    38
  {
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    39
    define('LIBIRC_DEBUG', '');
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    40
  }
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    41
  else
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    42
  {
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    43
    echo <<<EOF
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    44
Usage: {$argv[0]}
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    45
Options:
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    46
  -d, --daemon     Run in background (requires pcntl support)
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    47
  -v, --verbose    Log communication to stdout (ignored if -d specified)
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    48
  -h, --help       This help message
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    49
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    50
EOF;
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    51
    exit(1);
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    52
  }
1d6e762433fe Added daemonizing (forking) support.
Dan
parents: 6
diff changeset
    53
}
6
a802bb5b3e08 Made the channel list completely dynamic now
Dan
parents: 4
diff changeset
    54
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    55
$censored_words = array('cock', 'fuck', 'cuck', 'funt', 'cunt', 'bitch');
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    56
$_shutdown = false;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    57
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    58
function eb_censor_words($text)
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    59
{
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    60
  // return $text;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    61
  
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    62
  global $censored_words;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    63
  foreach ( $censored_words as $word )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    64
  {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    65
    $replacement = substr($word, 0, 1) . preg_replace('/./', '*', substr($word, 1));
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    66
    while ( stristr($text, $word) )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    67
    {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    68
      $text = preg_replace("/$word/i", $replacement, $text);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    69
    }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    70
  }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    71
  return $text;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    72
}
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    73
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    74
require('libirc.php');
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    75
require('hooks.php');
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    76
require('config.php');
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    77
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    78
@ini_set('display_errors', 'on');
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    79
error_reporting(E_ALL);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    80
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    81
// load modules
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    82
foreach ( $modules as $module )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    83
{
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    84
  $modulefile = "modules/$module.php";
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    85
  if ( file_exists($modulefile) )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    86
  {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    87
    require($modulefile);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    88
  }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    89
}
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    90
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    91
$mysql_conn = false;
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
    92
$doctor = array();
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    93
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    94
function mysql_reconnect()
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    95
{
2
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
    96
  global $mysql_conn, $mysql_host, $mysql_user, $mysql_pass, $mysql_dbname;
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    97
  if ( $mysql_conn )
4
8f62a406d9d9 Added debug message for MySQL reconnection; it's tested and confirmed working now
Dan
parents: 3
diff changeset
    98
  {
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
    99
    @mysql_close($mysql_conn);
4
8f62a406d9d9 Added debug message for MySQL reconnection; it's tested and confirmed working now
Dan
parents: 3
diff changeset
   100
    if ( defined('LIBIRC_DEBUG') )
8f62a406d9d9 Added debug message for MySQL reconnection; it's tested and confirmed working now
Dan
parents: 3
diff changeset
   101
    {
8f62a406d9d9 Added debug message for MySQL reconnection; it's tested and confirmed working now
Dan
parents: 3
diff changeset
   102
      echo "< > Reconnecting to MySQL\n";
8f62a406d9d9 Added debug message for MySQL reconnection; it's tested and confirmed working now
Dan
parents: 3
diff changeset
   103
    }
8f62a406d9d9 Added debug message for MySQL reconnection; it's tested and confirmed working now
Dan
parents: 3
diff changeset
   104
  }
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   105
  // connect to MySQL
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   106
  $mysql_conn = @mysql_connect($mysql_host, $mysql_user, $mysql_pass);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   107
  if ( !$mysql_conn )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   108
  {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   109
    $m_e = mysql_error();
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   110
    echo "Error connecting to MySQL: $m_e\n";
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   111
    exit(1);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   112
  }
2
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   113
  $q = @mysql_query("USE `$mysql_dbname`;", $mysql_conn);
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   114
  if ( !$q )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   115
  {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   116
    $m_e = mysql_error();
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   117
    echo "Error selecting database: $m_e\n";
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   118
    exit(1);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   119
  }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   120
}
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   121
2
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   122
function eb_mysql_query($sql, $conn = false)
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   123
{
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   124
  global $mysql_conn, $irc;
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   125
  $m_et = false;
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   126
  while ( true )
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   127
  {
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   128
    $q = mysql_query($sql, $mysql_conn);
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   129
    if ( !$q )
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   130
    {
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   131
      $m_e = mysql_error();
3
02e1c3f8f0ef Hopefully made MySQL reconnection possible
Dan
parents: 2
diff changeset
   132
      if ( strpos($m_e, 'gone away') && !$m_et )
2
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   133
      {
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   134
        mysql_reconnect();
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   135
        continue;
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   136
      }
3
02e1c3f8f0ef Hopefully made MySQL reconnection possible
Dan
parents: 2
diff changeset
   137
      $m_et = true;
2
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   138
      $irc->close("MySQL query error: $m_e");
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   139
      exit(1);
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   140
    }
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   141
    break;
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   142
  }
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   143
  return $q;
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   144
}
c474904ed707 Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents: 1
diff changeset
   145
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   146
mysql_reconnect();
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   147
6
a802bb5b3e08 Made the channel list completely dynamic now
Dan
parents: 4
diff changeset
   148
$libirc_channels = array();
a802bb5b3e08 Made the channel list completely dynamic now
Dan
parents: 4
diff changeset
   149
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   150
$irc = new Request_IRC($server);
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   151
$irc->connect($nick, $user, $name, $pass);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   152
$irc->set_privmsg_handler('enanobot_privmsg_event');
6
a802bb5b3e08 Made the channel list completely dynamic now
Dan
parents: 4
diff changeset
   153
a802bb5b3e08 Made the channel list completely dynamic now
Dan
parents: 4
diff changeset
   154
foreach ( $channels as $channel )
a802bb5b3e08 Made the channel list completely dynamic now
Dan
parents: 4
diff changeset
   155
{
a802bb5b3e08 Made the channel list completely dynamic now
Dan
parents: 4
diff changeset
   156
  $libirc_channels[$channel] = $irc->join($channel, 'enanobot_channel_event');
a802bb5b3e08 Made the channel list completely dynamic now
Dan
parents: 4
diff changeset
   157
  $channel_clean = preg_replace('/^[#&]/', '', $channel);
a802bb5b3e08 Made the channel list completely dynamic now
Dan
parents: 4
diff changeset
   158
  $libirc_channels[$channel_clean] =& $libirc_channels[$channel];
a802bb5b3e08 Made the channel list completely dynamic now
Dan
parents: 4
diff changeset
   159
  $irc->privmsg('ChanServ', "OP $channel $nick");
a802bb5b3e08 Made the channel list completely dynamic now
Dan
parents: 4
diff changeset
   160
}
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   161
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   162
$irc->event_loop();
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   163
$irc->close();
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   164
mysql_close($mysql_conn);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   165
6
a802bb5b3e08 Made the channel list completely dynamic now
Dan
parents: 4
diff changeset
   166
function enanobot_channel_event($sockdata, $chan)
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   167
{
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   168
  global $irc, $nick, $mysql_conn, $privileged_list;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   169
  $sockdata = trim($sockdata);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   170
  $message = Request_IRC::parse_message($sockdata);
6
a802bb5b3e08 Made the channel list completely dynamic now
Dan
parents: 4
diff changeset
   171
  $channelname = $chan->get_channel_name();
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   172
  
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   173
  eval(eb_fetch_hook('event_raw_message'));
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   174
  
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   175
  switch ( $message['action'] )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   176
  {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   177
    case 'JOIN':
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   178
      eval(eb_fetch_hook('event_join'));
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   179
      break;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   180
    case 'PART':
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   181
      eval(eb_fetch_hook('event_part'));
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   182
      break;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   183
    case 'PRIVMSG':
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   184
      enanobot_process_channel_message($sockdata, $chan, $message);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   185
      break;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   186
  }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   187
}
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   188
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   189
function enanobot_process_channel_message($sockdata, $chan, $message)
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   190
{
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   191
  global $irc, $nick, $mysql_conn, $privileged_list;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   192
  
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   193
  if ( strpos($message['message'], $nick) && !in_array($message['nick'], $privileged_list) && $message['nick'] != $nick )
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   194
  {
9
4192954c29d1 Finalization of merge from devel branch
Dan
parents: 8
diff changeset
   195
    $target_nick =& $message['nick'];
13
f073c94a1477 Disabled annoying "I'm only a bot" message
Dan
parents: 9
diff changeset
   196
    // $chan->msg("{$target_nick}, I'm only a bot. :-) You should probably rely on the advice of humans if you need further assistance.", true);
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   197
  }
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   198
  else
1
739423b66116 Added support for logging mode messages and join/part messages
Dan
parents: 0
diff changeset
   199
  {
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   200
    eval(eb_fetch_hook('event_channel_msg'));
1
739423b66116 Added support for logging mode messages and join/part messages
Dan
parents: 0
diff changeset
   201
  }
739423b66116 Added support for logging mode messages and join/part messages
Dan
parents: 0
diff changeset
   202
}
739423b66116 Added support for logging mode messages and join/part messages
Dan
parents: 0
diff changeset
   203
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   204
function enanobot_privmsg_event($message)
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   205
{
6
a802bb5b3e08 Made the channel list completely dynamic now
Dan
parents: 4
diff changeset
   206
  global $privileged_list, $irc, $nick;
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   207
  static $part_cache = array();
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   208
  if ( in_array($message['nick'], $privileged_list) && $message['message'] == 'Suspend' && $message['action'] == 'PRIVMSG' )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   209
  {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   210
    foreach ( $irc->channels as $channel )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   211
    {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   212
      $part_cache[] = array($channel->get_channel_name(), $channel->get_handler());
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   213
      $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);
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   214
      $channel->part("Logging and presence suspended by {$message['nick']}", true);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   215
    }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   216
  }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   217
  else if ( in_array($message['nick'], $privileged_list) && $message['message'] == 'Resume' && $message['action'] == 'PRIVMSG' )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   218
  {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   219
    global $nick;
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   220
    foreach ( $part_cache as $chan_data )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   221
    {
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   222
      $chan_name = substr($chan_data[0], 1);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   223
      $GLOBALS[$chan_name] = $irc->join($chan_data[0], $chan_data[1]);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   224
      $GLOBALS[$chan_name]->msg("Bot resumed by {$message['nick']}.", true);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   225
      $irc->privmsg('ChanServ', "OP {$chan_data[0]} $nick");
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   226
    }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   227
    $part_cache = array();
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   228
  }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   229
  else if ( in_array($message['nick'], $privileged_list) && $message['message'] == 'Shutdown' && $message['action'] == 'PRIVMSG' )
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   230
  {
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   231
    $GLOBALS['_shutdown'] = true;
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   232
    $irc->close("Remote bot shutdown ordered by {$message['nick']}", true);
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   233
    return 'BREAK';
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   234
  }
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   235
  else if ( $message['action'] == 'PRIVMSG' )
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   236
  {
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   237
    eval(eb_fetch_hook('event_privmsg'));
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   238
  }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   239
  else
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   240
  {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   241
    eval(eb_fetch_hook('event_other'));
0
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   242
  }
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   243
}
d02690a8552c Initial population. EnanoBot v0.1.
Dan
parents:
diff changeset
   244
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   245
if ( $_shutdown )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   246
{
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   247
  exit(2);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents: 7
diff changeset
   248
}