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