modules/snippets.php
author Dan
Sat, 11 Oct 2008 23:09:13 +0000
changeset 14 506a7e0fb106
parent 8 0acb8d9a3194
permissions -rw-r--r--
Disabled "snippet not found" message, for now
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_channel_msg', 'snippets_event_privmsg($chan, $message);');
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     4
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     5
function snippets_event_privmsg(&$chan, &$message)
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     6
{
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     7
  if ( preg_match('/^\![\s]*([a-z0-9_-]+)([\s]*\|[\s]*([^ ]+))?$/', $message['message'], $match) )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     8
  {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     9
    $snippet =& $match[1];
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    10
    if ( @$match[3] === 'me' )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    11
      $match[3] = $message['nick'];
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    12
    $target_nick = ( !empty($match[3]) ) ? "{$match[3]}, " : "{$message['nick']}, ";
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    13
    if ( $snippet == 'snippets' )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    14
    {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    15
      // list available snippets
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    16
      $m_et = false;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    17
      $q = eb_mysql_query('SELECT snippet_code, snippet_channels FROM snippets;');
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    18
      if ( mysql_num_rows($q) < 1 )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    19
      {
14
506a7e0fb106 Disabled "snippet not found" message, for now
Dan
parents: 8
diff changeset
    20
        // $chan->msg(eb_censor_words("{$message['nick']}, I couldn't find that snippet (\"$snippet\") in the database."), true);
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    21
      }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    22
      else
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    23
      {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    24
        $snippets = array();
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    25
        while ( $row = mysql_fetch_assoc($q) )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    26
        {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    27
          $channels = explode('|', $row['snippet_channels']);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    28
          if ( in_array($chan->get_channel_name(), $channels) )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    29
          {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    30
            $snippets[] = $row['snippet_code'];
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    31
          }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    32
        }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    33
        $snippets = implode(', ', $snippets);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    34
        $chan->msg(eb_censor_words("{$message['nick']}, the following snippets are available: $snippets"), true);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    35
      }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    36
      @mysql_free_result($q);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    37
    }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    38
    else
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    39
    {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    40
      if ( eval(eb_fetch_hook('snippet_dynamic')) )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    41
      {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    42
        return true;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    43
      }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    44
      
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    45
      // Look for the snippet...
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    46
      $q = eb_mysql_query('SELECT snippet_text, snippet_channels FROM snippets WHERE snippet_code = \'' . mysql_real_escape_string($snippet) . '\';');
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    47
      if ( mysql_num_rows($q) < 1 )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    48
      {
14
506a7e0fb106 Disabled "snippet not found" message, for now
Dan
parents: 8
diff changeset
    49
        // $chan->msg(eb_censor_words("{$message['nick']}, I couldn't find that snippet (\"$snippet\") in the database."), true);
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    50
      }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    51
      else
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    52
      {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    53
        $row = mysql_fetch_assoc($q);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    54
        $channels = explode('|', $row['snippet_channels']);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    55
        if ( in_array($chan->get_channel_name(), $channels) )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    56
        {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    57
          $chan->msg(eb_censor_words("{$target_nick}{$row['snippet_text']}"), true);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    58
        }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    59
        else
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    60
        {
14
506a7e0fb106 Disabled "snippet not found" message, for now
Dan
parents: 8
diff changeset
    61
          // $chan->msg(eb_censor_words("{$message['nick']}, I couldn't find that snippet (\"$snippet\") in the database."), true);
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    62
        }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    63
      }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    64
      @mysql_free_result($q);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    65
    }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    66
  }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    67
}