9 * This source file is subject to the new BSD license that is bundled
10 * with this package in the file LICENSE.
11 * It is also available through the world-wide-web at this URL:
12 * http://phergie.org/license
15 * @package Phergie_Plugin_TerryChay
16 * @author Phergie Development Team <team@phergie.org>
17 * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
18 * @license http://phergie.org/license New BSD License
19 * @link http://pear.phergie.org/package/Phergie_Plugin_TerryChay
23 * Parses incoming messages for the words "Terry Chay" or tychay and responds
24 * with a random Terry fact retrieved from the Chayism web service.
27 * @package Phergie_Plugin_TerryChay
28 * @author Phergie Development Team <team@phergie.org>
29 * @license http://phergie.org/license New BSD License
30 * @link http://pear.phergie.org/package/Phergie_Plugin_TerryChay
31 * @uses Phergie_Plugin_Http pear.phergie.org
33 class Phergie_Plugin_TerryChay extends Phergie_Plugin_Abstract
36 * URL to the web service
40 const URL = 'http://phpdoc.info/chayism/';
45 * @var Phergie_Plugin_Http
50 * Checks for dependencies.
54 public function onLoad()
56 $this->getPluginHandler()->getPlugin('Http');
62 * @return string|bool Fetched chayism or FALSE if the operation failed
64 public function getChayism()
74 * Parses incoming messages for "Terry Chay" and related variations and
75 * responds with a chayism.
79 public function onPrivmsg()
81 $event = $this->getEvent();
82 $source = $event->getSource();
83 $message = $event->getText();
85 = '{^(' . preg_quote($this->getConfig('command.prefix')) .
86 '\s*)?.*(terry\s+chay|tychay)}ix';
88 if (preg_match($pattern, $message)) {
89 if($fact = $this->getChayism()) {
90 $this->doPrivmsg($source, 'Fact: ' . $fact);