89 abstract protected function reload($flags);
115 $this->mainCfg = null;
117 $this->factories = array();
120 '!EventHandler' =>
'\\Erebot\\EventHandler',
122 '!Identity' =>
'\\Erebot\\Identity',
124 '!NumericHandler' =>
'\\Erebot\\NumericHandler',
126 '!NumericReference' =>
'\\Erebot\\NumericReference',
128 '!Styling' =>
'\\Erebot\\Styling',
130 '\\Erebot\\Styling\\Variables\\CurrencyInterface' =>
131 '\\Erebot\\Styling\\Variables\\CurrencyVariable',
133 '\\Erebot\\Styling\\Variables\\DateTimeInterface' =>
134 '\\Erebot\\Styling\\Variables\\DateTimeVariable',
136 '\\Erebot\\Styling\\Variables\\DurationInterface' =>
137 '\\Erebot\\Styling\\Variables\\DurationVariable',
139 '!TextWrapper' =>
'\\Erebot\\TextWrapper',
141 '!Timer' =>
'\\Erebot\\Timer',
143 foreach ($ifaces as $iface => $cls) {
153 $this->logger = null;
154 if (class_exists(
'\\Plop\\Plop')) {
155 $this->logger =& \Plop\Plop::getInstance();
190 if ($this->connection === null) {
191 $flags |= self::RELOAD_INIT;
197 $serverCfg = $this->connection->getConfig(null);
198 $this->mainCfg = $serverCfg->getMainCfg();
200 $this->translator = $this->mainCfg->getTranslator(get_called_class());
203 if ($this instanceof \
Erebot\Interfaces\HelpEnabled) {
236 if (!is_string($iface)) {
237 throw new \Erebot\InvalidValueException(
'Not an interface name');
240 $ifaceName = str_replace(
'!',
'\\Erebot\\Interfaces\\', $iface);
241 if (!interface_exists($ifaceName,
true)) {
242 $ifaceName = str_replace(
'!',
'\\Erebot\\', $iface) .
'Interface';
243 if (!interface_exists($ifaceName,
true)) {
244 throw new \Erebot\InvalidValueException(
245 'No such interface ('.$iface.
')' 250 if (!class_exists($cls,
true)) {
251 throw new \Erebot\InvalidValueException(
'No such class ('.$cls.
')');
254 $reflector = new \ReflectionClass($cls);
255 if (!$reflector->isSubclassOf($ifaceName)) {
256 throw new \Erebot\InvalidValueException(
257 'A class that implements the interface was expected' 260 $iface = strtolower($ifaceName);
261 $this->factories[$iface] = $cls;
285 if (!is_string($iface)) {
286 throw new \Erebot\InvalidValueException(
'Not an interface name');
289 $ifaceKey = strtolower(str_replace(
'!',
'\\Erebot\\Interfaces\\', $iface));
290 if (!isset($this->factories[$ifaceKey])) {
291 $ifaceKey = strtolower(str_replace(
'!',
'\\Erebot\\', $iface) .
'Interface');
292 if (!isset($this->factories[$ifaceKey])) {
293 throw new \Erebot\InvalidValueException(
294 'No such interface ('.$iface.
')' 298 return $this->factories[$ifaceKey];
323 $type = self::MSG_TYPE_PRIVMSG
325 $types = array(
'PRIVMSG',
'NOTICE',
'CTCP',
'CTCPREPLY',
'ACTION');
326 $type = strtoupper($type);
327 if (!in_array($type, $types)) {
328 throw new \Exception(
'Not a valid type');
331 if (is_array($targets)) {
332 $targets = implode(
',', $targets);
334 $targets = (string) $targets;
335 } elseif (!is_string($targets)) {
336 throw new \Exception(
'Not a valid target (expected a string)');
340 throw new \Exception(
'Not a valid message (expected a string)');
343 $message = (string) $message;
344 $parts = array_map(
'trim', explode(
"\n", trim($message)));
345 $message = implode(
' ', $parts);
349 if ($type ==
'ACTION') {
352 $ctcpType =
'ACTION';
355 if ($type ==
'CTCP' || $type ==
'CTCPREPLY') {
356 $type = ($type ==
'CTCP' ?
'PRIVMSG' :
'NOTICE');
358 $parts = explode(
' ', $message);
359 $ctcpType = array_shift($parts);
360 $message = implode(
' ', $parts);
363 if ($ctcpType !=
"" && $message !=
"") {
365 $message = self::ctcpQuote($message);
368 $prefix = $type.
' '.$targets.
' :'.$marker.$ctcpType;
375 400 - strlen($prefix) - 2,
380 $io = $this->connection->getIO();
381 foreach ($messages as $msg) {
382 $io->push($prefix.$msg.$marker);
406 "\020" =>
"\020\020",
408 $message = strtr($message, $quoting);
415 $message = strtr($message, $quoting);
428 throw new \Exception(
'Invalid command (not a string)');
430 $this->connection->getIO()->push((
string) $command);
445 $bot = $this->connection->getBot();
446 return $bot->addTimer($timer);
461 $bot = $this->connection->getBot();
462 return $bot->removeTimer($timer);
491 $function =
'parse'.$something;
492 $bot = $this->connection->getBot();
493 if ($this->channel !== null) {
495 $config = $this->connection->getConfig($this->channel);
496 return $config->$function(
'\\' . get_called_class(), $param);
501 $config = $this->connection->getConfig(null);
502 return $config->$function(
'\\' . get_called_class(), $param, $default);
563 protected function parseInt($param, $default = null)
615 $helper = $this->connection->getModule(
616 '\\Erebot\\Module\\Helper',
619 return $helper->realRegisterHelpMethod($this, $callback);
641 if ($chan ===
false) {
642 return new $cls($this->translator);
643 } elseif ($chan !== null) {
644 $config = $this->connection->getConfig($chan);
646 return new $cls($config->getTranslator(get_called_class()));
653 $config = $this->connection->getConfig($this->channel);
655 return new $cls($config->getTranslator(get_called_class()));
661 $config = $this->connection->getConfig(null);
662 return new $cls($config->getTranslator(get_called_class()));
678 $cls = $this->
getFactory(
'!NumericReference');
679 return new $cls($this->connection, $name);
sendMessage($targets, $message, $type=self::MSG_TYPE_PRIVMSG)
const MSG_TYPE_NOTICE
A notice.
const MSG_TYPE_CTCP
A CTCP request.
Base class for other (Erebot-related) exceptions.
parseSomething($something, $param, $default)
$translator
The translator to use for messages coming from this instance.
$connection
The connection associated with this instance.
Interface for something that can be called.
static stringifiable($item)
removeTimer(\Erebot\TimerInterface $timer)
const MSG_TYPE_PRIVMSG
A regular message.
parseReal($param, $default=null)
const RELOAD_HANDLERS
The module should (re)load its handlers.
reloadModule(\Erebot\Interfaces\Connection $connection, $flags)
An exception thrown when an invalid value has been passed to a function or method.
registerHelpMethod(\Erebot\CallableInterface $callback)
const RELOAD_ALL
The module should (re)load all of its contents.
const RELOAD_MEMBERS
The module should (re)load its members.
$factories
Factories to use for this module.
parseString($param, $default=null)
Interface for a timer implementation.
$logger
A logger for this module's messages.
parseInt($param, $default=null)
Represents the identity of an IRC user.
$channel
The channel associated with this instance, if any.
const RELOAD_INIT
Passed when the module is loaded (instead of reloaded).
const MSG_TYPE_CTCPREPLY
A reply to a CTCP request.
addTimer(\Erebot\TimerInterface $timer)
An abstract class which serves as the base to build additional modules for Erebot.
const RELOAD_TESTING
Passed during unittests (currently unused...).
parseBool($param, $default=null)
static ctcpQuote($message)
const MSG_TYPE_ACTION
An action.