| 1 |
<?php
|
| 2 |
// $Id: bot_agotchi.module,v 1.3 2006/11/17 04:30:02 morbus Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Proper care and feeding lets your bot grow and be happy!
|
| 7 |
*
|
| 8 |
* Usage note: code and variable wise, it's "bot_agotchi" (so as to have
|
| 9 |
* proper alphabetizing with the rest of the plugins in a directory). To
|
| 10 |
* a human, however, it is always called a "botagotchi".
|
| 11 |
*/
|
| 12 |
|
| 13 |
/**
|
| 14 |
* Implementation of hook_help().
|
| 15 |
*/
|
| 16 |
function bot_agotchi_help($section) {
|
| 17 |
switch ($section) {
|
| 18 |
case 'irc:features':
|
| 19 |
return array(t('Botagotchi'));
|
| 20 |
case 'irc:features#botagotchi':
|
| 21 |
return t('Proper care and feeding lets your botagotchi grow and be happy!');
|
| 22 |
case 'admin/settings/bot/agotchi':
|
| 23 |
return '<p>'.t('Configure your botagotchi with these settings.').'</p>';
|
| 24 |
}
|
| 25 |
}
|
| 26 |
|
| 27 |
/**
|
| 28 |
* Implementation of hook_menu().
|
| 29 |
*/
|
| 30 |
function bot_agotchi_menu($may_cache) {
|
| 31 |
$items = array();
|
| 32 |
|
| 33 |
if ($may_cache) {
|
| 34 |
$items[] = array(
|
| 35 |
'access' => user_access('administer bot'),
|
| 36 |
'callback' => 'drupal_get_form',
|
| 37 |
'callback arguments' => 'bot_agotchi_settings',
|
| 38 |
'description' => t('Configure your botagotchi with these settings.'),
|
| 39 |
'path' => 'admin/settings/bot/agotchi',
|
| 40 |
'title' => t('Botagotchi'),
|
| 41 |
);
|
| 42 |
}
|
| 43 |
|
| 44 |
return $items;
|
| 45 |
}
|
| 46 |
|
| 47 |
/**
|
| 48 |
* Listen for conversation directed at, or about, the bot.
|
| 49 |
*
|
| 50 |
* @param $data
|
| 51 |
* The regular $data object prepared by the IRC library.
|
| 52 |
* @param $from_query
|
| 53 |
* Boolean; whether this was a queried request.
|
| 54 |
*/
|
| 55 |
function bot_agotchi_irc_msg_channel($data, $from_query) {
|
| 56 |
$substitutions = array('!who' => $data->nick, '!channel' => $data->channel);
|
| 57 |
$bot_name = variable_get('bot_nickname', 'bot_module');
|
| 58 |
$addressed = "$bot_name:? ?"; // bot name prefixed.
|
| 59 |
$to = $from_query ? $data->nick : $data->channel;
|
| 60 |
|
| 61 |
// feeding makes the bot's tumbly less rumbly.
|
| 62 |
if (preg_match("/^($addressed)?(bot(\s|\-)?snack)/i", $data->message)) {
|
| 63 |
$feeding_responses = explode("\n", variable_get('bot_agotchi_feeding_responses', _bot_agotchi_feeding_responses()));
|
| 64 |
$feeding_response_key = array_rand($feeding_responses); // of all our feeding responses, get a random one.
|
| 65 |
bot_message($to, strtr($feeding_responses[$feeding_response_key], $substitutions));
|
| 66 |
}
|
| 67 |
|
| 68 |
// spit out a greeting in response to another (addressed or not).
|
| 69 |
if (preg_match("/^\s*(h(ello|i( there)?|owdy|ey|ola)|salut|bonjour|niihau|que\s*tal)( $bot_name)?\s*$/i", $data->message)) {
|
| 70 |
if (rand(0, 100) < variable_get('bot_agotchi_greeting_randomness', 65)) {
|
| 71 |
$greeting_responses = explode("\n", variable_get('bot_agotchi_greeting_responses', _bot_agotchi_greeting_responses()));
|
| 72 |
$greeting_response_key = array_rand($greeting_responses); // of all our greeting responses, get a random one.
|
| 73 |
bot_message($to, strtr($greeting_responses[$greeting_response_key], $substitutions));
|
| 74 |
}
|
| 75 |
}
|
| 76 |
|
| 77 |
// we've been thanked, so you're welcome 'em.
|
| 78 |
if (preg_match("/^${addressed}thank(s| you)/i", $data->message)) {
|
| 79 |
$thankful_responses = explode("\n", variable_get('bot_agotchi_thankful_responses', _bot_agotchi_thankful_responses()));
|
| 80 |
$thankful_response_key = array_rand($thankful_responses); // of all our thankful responses, get a random one.
|
| 81 |
bot_message($to, strtr($thankful_responses[$thankful_response_key], $substitutions));
|
| 82 |
}
|
| 83 |
}
|
| 84 |
|
| 85 |
/**
|
| 86 |
* All responses are available via a query.
|
| 87 |
*/
|
| 88 |
function bot_agotchi_irc_msg_query($data) {
|
| 89 |
bot_agotchi_irc_msg_channel($data, 1);
|
| 90 |
}
|
| 91 |
|
| 92 |
/**
|
| 93 |
* Configures the botagotchi's personality.
|
| 94 |
*/
|
| 95 |
function bot_agotchi_settings() {
|
| 96 |
$form = array();
|
| 97 |
|
| 98 |
$form['#prefix'] = t('The following variables are available for use in responses: !nick, !channel.');
|
| 99 |
|
| 100 |
$form['bot_agotchi_feeding_responses'] = array(
|
| 101 |
'#default_value' => variable_get('bot_agotchi_feeding_responses', _bot_agotchi_feeding_responses()),
|
| 102 |
'#description' => t('List the responses, one per line, your botagotchi will say when fed a botsnack.'),
|
| 103 |
'#title' => t('Feeding responses'),
|
| 104 |
'#type' => 'textarea',
|
| 105 |
);
|
| 106 |
$form['bot_agotchi_greeting_responses'] = array(
|
| 107 |
'#default_value' => variable_get('bot_agotchi_greeting_responses', _bot_agotchi_greeting_responses()),
|
| 108 |
'#description' => t('List the responses, one per line, your botagotchi will say when it hears a greeting.'),
|
| 109 |
'#title' => t('Greeting responses'),
|
| 110 |
'#type' => 'textarea',
|
| 111 |
);
|
| 112 |
$form['bot_agotchi_greeting_randomness'] = array(
|
| 113 |
'#default_value' => variable_get('bot_agotchi_greeting_randomness', 65),
|
| 114 |
'#description' => t('The percentage that your botagotchi will actually respond to a heard greeting.'),
|
| 115 |
'#title' => t('Greeting randomness'),
|
| 116 |
'#type' => 'textfield',
|
| 117 |
);
|
| 118 |
$form['bot_agotchi_thankful_responses'] = array(
|
| 119 |
'#default_value' => variable_get('bot_agotchi_thankful_responses', _bot_agotchi_thankful_responses()),
|
| 120 |
'#description' => t('List the responses, one per line, your botagotchi will say when it has been thanked.'),
|
| 121 |
'#title' => t('Thankful responses'),
|
| 122 |
'#type' => 'textarea',
|
| 123 |
);
|
| 124 |
|
| 125 |
return system_settings_form($form);
|
| 126 |
}
|
| 127 |
|
| 128 |
/**
|
| 129 |
* Returns the default list of feeding responses.
|
| 130 |
*/
|
| 131 |
function _bot_agotchi_feeding_responses() {
|
| 132 |
return implode("\n", array(
|
| 133 |
'this is why I love !channel',
|
| 134 |
'thanks !who :)',
|
| 135 |
':)',
|
| 136 |
));
|
| 137 |
}
|
| 138 |
|
| 139 |
/**
|
| 140 |
* Returns the default list of greeting responses.
|
| 141 |
*/
|
| 142 |
function _bot_agotchi_greeting_responses() {
|
| 143 |
return implode("\n", array(
|
| 144 |
'hi',
|
| 145 |
'hey',
|
| 146 |
'hola',
|
| 147 |
'hello',
|
| 148 |
'salut',
|
| 149 |
'eh oh',
|
| 150 |
'niihau',
|
| 151 |
'privet',
|
| 152 |
'bonjour',
|
| 153 |
'que tal',
|
| 154 |
"what's up",
|
| 155 |
));
|
| 156 |
}
|
| 157 |
|
| 158 |
/**
|
| 159 |
* Returns the default list of thankful responses.
|
| 160 |
*/
|
| 161 |
function _bot_agotchi_thankful_responses() {
|
| 162 |
return implode("\n", array(
|
| 163 |
'bitte',
|
| 164 |
'de nada',
|
| 165 |
'de rien',
|
| 166 |
'no problem',
|
| 167 |
'no worries',
|
| 168 |
'sure thing',
|
| 169 |
'my pleasure',
|
| 170 |
'pas de quoi',
|
| 171 |
));
|
| 172 |
}
|