cleaning
[irbot.git] / sources / Plugins / Command / Command_Abstract.php
blobb70ede3f1d6e13b000651a521ac1bb54a0781a86
1 <?php
2 /**
3 * This file is part of IrBot, irc robot.
4 * Copyright (C) 2007-2008 Bellière Ludovic
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 abstract class Plugins_Command_Abstract {
23 const REQUIERED_ARGS = 'requieredArgs';
24 const ACCEPTED_ARGS = 'acceptedArgs';
25 const COMMAND_VISIBILITY = 'commandVisibility';
26 const TYPE_PUBLIC = 'public';
27 const TYPE_PRIVATE = 'private';
28 const TYPE_BOTH = 'both';
29 const NOT_PUBLIC_MESSAGE = 'notPublicMessage';
30 const NOT_PRIVATE_MESSAGE = 'notPublicMessage';
31 const ALLOW_EMPTY = 'allowEmpty';
32 const NOT_EMPTY_MESSAGE = 'notEmptyMessage';
33 const ON_EVENT = 'onEvent';
34 const EVENT_PRIVMSG = "privmsg";
35 const EVENT_NOTICE = "notice";
39 /**
40 * Parent object
42 * @var Plugins_Abstract
44 protected $_plugin;
46 protected $_helpMessage = '';
47 protected $type;
49 protected $_defaults = array(
50 self::REQUIERED_ARGS => 0,
51 self::ACCEPTED_ARGS => 0,
52 self::COMMAND_VISIBILITY => self::TYPE_BOTH,
53 self::NOT_PUBLIC_MESSAGE => 'Sorry, but the command is not for public channel.',
54 self::NOT_PRIVATE_MESSAGE => 'Sorry, but the command is not for private query.',
57 protected $_defaultsArgs = array(
58 self::ALLOW_EMPTY => true,
62 protected $_events = array(
63 self::EVENT_NOTICE => true,
64 self::EVENT_PRIVMSG => true
67 /**
68 * Event object
70 * @var Event
72 protected $_event;
74 public function __construct(Plugins_Abstract $plugin) {
75 $this->_plugin = $plugin;
78 public function setOptions(array $options) {
79 foreach ($options as $option => $value) {
80 switch ($option) {
81 case self::ACCEPTED_ARGS:
82 case self::REQUIERED_ARGS:
83 $this->_default[$option] = $value;
84 break;
85 default:
86 throw new Exception ("Unkown option '$option'");
91 public function setCurrentEvent (Event $event) {
92 $this->_event = $event;
95 public function helpMessage() {
96 return $this->_helpMessage;
99 public function __get($option) {
100 return $this->_default[$option];
102 abstract public function __toString();