Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <pre>
- <?
- class Slon {
- // regexp patterns
- public $triggers = array (
- "футбол"=>"ногомяч говно!",
- "за500"=>"Ежедневный запиццот рулит :power:",
- "(за550|за600)"=>".i.",
- "(ссср|коммунизм|ленин|сталин|капитализм)"=>"Коммунизм - это хорошо! Ленин и Сталин чёткие мужики! Даёшь старые границы СССР! Капитализм в топку! :power:",
- "религ.*"=>"Религию фтопку!",
- "ВРС"=>"ПФФ! Бабушкины сказки, разжижение мозга!",
- "хобот"=>"У меня самый большой хобот :power:",
- //add custom triggers here...
- //"" => "",
- );
- // returns random opinion
- public function getRandomOpinion()
- {
- $opinions = array(".i.", ":power:", ":mellow:");
- return $opinions[rand(0, count($opinions)-1)];
- }
- // scan sentence for triggers, stopping on first one
- public function scanSentence($sentence)
- {
- $retVal = "";
- foreach ($this->triggers as $pattern=>$response)
- {
- if (preg_match("#$pattern#i", $sentence))
- {
- $retVal = $response;
- break;
- }
- }
- $retVal = ($retVal) ? $retVal : $this->getRandomOpinion();
- return $retVal;
- }
- };
- // --- ENTRY POINT
- // all strings are cp1251, so we need to set locale for correct preg_match processing
- setlocale(LC_ALL, 'ru_RU.CP1251', 'rus_RUS.CP1251', 'Russian_Russia.1251');
- // create Slon!
- $S = new Slon();
- // Let's ask him some questions
- $sentences = array (
- "Слон, как ты относишься к религии?",
- "Что думаешь по поводу ВРС?",
- "Когда начнёшь делать за550?",
- "Любишь футбол?",
- "Ленин чмо?",
- // you are free to add your own questions
- // "",
- );
- foreach ($sentences as $sentence)
- {
- echo ">> $sentence\n";
- echo "<< " . $S->scanSentence($sentence) . "\n\n";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement