| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
class Phergie_Plugin_Autojoin extends Phergie_Plugin_Abstract_Base |
|---|
| 11 |
{ |
|---|
| 12 |
|
|---|
| 13 |
* Determines if the plugin is a passive plugin or not |
|---|
| 14 |
* |
|---|
| 15 |
* @var bool |
|---|
| 16 |
*/ |
|---|
| 17 |
public $passive = true; |
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
* Determines if the bot will autojoin a channel on an invite request |
|---|
| 21 |
* |
|---|
| 22 |
* @var bool |
|---|
| 23 |
*/ |
|---|
| 24 |
public $joinInvite = true; |
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
* Determines if the bot will rejoin the channel when kicked |
|---|
| 28 |
* |
|---|
| 29 |
* @var bool |
|---|
| 30 |
*/ |
|---|
| 31 |
public $joinKick = true; |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
* Initializes settings |
|---|
| 35 |
* |
|---|
| 36 |
* @return void |
|---|
| 37 |
*/ |
|---|
| 38 |
public function onInit() |
|---|
| 39 |
{ |
|---|
| 40 |
$joinInvite = $this->getPluginIni('invite'); |
|---|
| 41 |
if (isset($joinInvite)) { |
|---|
| 42 |
$this->joinInvite = $joinInvite; |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
$joinKick = $this->getPluginIni('kick'); |
|---|
| 46 |
if (isset($joinKick)) { |
|---|
| 47 |
$this->joinKick = $joinKick; |
|---|
| 48 |
} |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
* Returns whether or not the current environment meets the requirements |
|---|
| 53 |
* of the plugin in order for it to be run, including the PHP version, |
|---|
| 54 |
* loaded PHP extensions, and other plugins intended to be loaded. |
|---|
| 55 |
* Plugins with such requirements should override this method. |
|---|
| 56 |
* |
|---|
| 57 |
* @param Phergie_Driver_Abstract $client Client instance |
|---|
| 58 |
* @param array $plugins List of short names for plugins that the |
|---|
| 59 |
* bootstrap file intends to instantiate |
|---|
| 60 |
* @return bool TRUE if dependencies are met, FALSE otherwise |
|---|
| 61 |
*/ |
|---|
| 62 |
public static function checkDependencies(Phergie_Driver_Abstract $client, array $plugins) |
|---|
| 63 |
{ |
|---|
| 64 |
$channels = $client->getIni('autojoin.channels'); |
|---|
| 65 |
|
|---|
| 66 |
if (empty($channels)) { |
|---|
| 67 |
return 'Ini setting autojoin.channels must be filled-in'; |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
return true; |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
* Intercepts the end of the "message of the day" response and responds by |
|---|
| 75 |
* joining the channels specified in the configuration file. |
|---|
| 76 |
* |
|---|
| 77 |
* @return void |
|---|
| 78 |
*/ |
|---|
| 79 |
public function onResponse() |
|---|
| 80 |
{ |
|---|
| 81 |
switch ($this->event->getCode()) { |
|---|
| 82 |
case Phergie_Event_Response::RPL_ENDOFMOTD: |
|---|
| 83 |
case Phergie_Event_Response::ERR_NOMOTD: |
|---|
| 84 |
$channels = $this->getPluginIni('channels'); |
|---|
| 85 |
if (!empty($channels)) { |
|---|
| 86 |
$spec = split('/\s+/', preg_replace('/,\s+/', ',', trim($channels)), 2); |
|---|
| 87 |
if (count($spec) > 1) { |
|---|
| 88 |
$this->doJoin($spec[0], $spec[1]); |
|---|
| 89 |
} else { |
|---|
| 90 |
$this->doJoin($spec[0]); |
|---|
| 91 |
} |
|---|
| 92 |
} |
|---|
| 93 |
break; |
|---|
| 94 |
} |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
* Intercepts invite requests and will have the bot join the channel if set |
|---|
| 99 |
* in the configuration. |
|---|
| 100 |
* |
|---|
| 101 |
* @return void |
|---|
| 102 |
*/ |
|---|
| 103 |
public function onInvite() |
|---|
| 104 |
{ |
|---|
| 105 |
if ($this->joinInvite) { |
|---|
| 106 |
$this->doJoin($this->event->getArgument(1)); |
|---|
| 107 |
} |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
* Intercepts kick requests and will have the bot rejoin the channel if set |
|---|
| 112 |
* in the configuration. |
|---|
| 113 |
* |
|---|
| 114 |
* @return void |
|---|
| 115 |
*/ |
|---|
| 116 |
public function onKick() |
|---|
| 117 |
{ |
|---|
| 118 |
if ($this->joinKick && |
|---|
| 119 |
$this->event->getArgument(1) == $this->getIni('nick')) { |
|---|
| 120 |
$this->doJoin($this->event->getArgument(0)); |
|---|
| 121 |
} |
|---|
| 122 |
} |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|