Bot IRC - Documentation plugins
Plugin plug_base
Conduite du bot et commandes de base.
Description
Le plugin plug_base permet opérateurs de piloter le bot.
Changement de nick, déconnection, chargement ou déchargement de plugin, etc...
Les nicks autorisés à être opérateurs doivent être déclarés dans le fichier bot.conf.
Afin d'éviter l'usurpation de nick, l'opérateur devra d'abord s'identifier avec la commande
!botop et en fournssant le mot de passe du bot.
Il aura ensuite accés à toutes les commandes opérateur.
Un opérateur peux promouvoir n'importe quel nick opérateur par la commande !setbotop nick.
La promotion prendra fin à la déconnection du nick.
D'autres commandes accessibles à tous permettent entre autre d'afficher le topic, la liste des plugins ou encore la description d'un plugin.
Utilisation.
Commandes op�rateurs :
- !eject :: Déconnecte le bot
- !nick <new_nick> :: Change le nom du bot
- !addplug <plug_name> :: Charge le plugin plug_name
- !ulplug <plug_name> :: Décharge le plugin plug_name
- !listnick :: Liste des nicks sur le chan vu par le bot
- !listop :: Liste des opérateurs du bot
- !botop <password> :: Donne le status bot operator si autorisé
- !setbotop <nick> :: Donne le status bot operator à nick
Commandes utilisateurs :
- !topic :: Affiche le topic du chan
- !listplug :: Liste tous les plugins
- !infoplug :: Affiche la description du plugin

Source du plugin.
/**
* fichier : plug_base.php :
* plugin de fonctions basiques
*
* @package Cspbot
* @since 2006/08/17
* @version 0.3
* @author Fabrice Lezoray - Tetsuo - Alain Nicolas (mcAllan)
* @copyright See licence.txt
*
*/
class plug_base extends plugin {
/**
* IRCMain object
* @var object IRCMain
*/
private $main;
/**
* Comands list
* @var array arrCmd
*/
private $arrCmd = array(
'topic',
'eject',
'nick',
'addplug',
'ulplug',
'listplug',
'infoplug',
'listnick',
'listop',
'setbotop',
'botop'
);
/**
* Constructor
*
* @param IRCMain main
*
*/
public function __construct($main) {
$this->main = $main;
}
/**
* Start run plugin
*
*/
public function start() {
$this->check();
$this->CTCP($this->main-> mess);
}
/**
* Check for comands
*
*/
private function check(){
$cdeMask = '`^\!(' . implode( "|" , $this->arrCmd) . ')(.*)`i';
if(preg_match($cdeMask, $this->main->mess,$T)) {
switch ($T[1]){
#=== Eject bot
case 'eject' :
if($this->main->isBotOp($this->main->from)){
$this->main->eject($this->main->from);
}else{
$this->main->sendMsg($this->main->from." : Tu crois pouvoir me virer ? :p");
}
break;
#=== Show topic
case 'topic' :
$this->main->sendMsg("******* Le TOPIC pour \002".IRCConn::$channel."\002 est : ");
$this->main->sendMsg($this->main->topicStr);
$this->main->sendMsg('Le '.$this->main->topicTime." par \002".$this->main->topicName."\002");
break;
#=== Change Bot nick
case 'nick' :
if($this->main->isBotOp($this->main->from) && !empty($T[2])){
$this->main->changeBotNick($T[2],$this->main->from);
}
break;
#=== Load plugin
case 'addplug' :
if($this->main->isBotOp($this->main->from) && !empty($T[2])){
$p_name = trim($T[2]);
if(isset($this->main->plugs->allPlugs[$p_name])){
$this->main->plugs->loadPlug($p_name);
$this->main->sendPrivNotice($this->main->from ,'Plugin Chargé');
}else{
$this->main->sendPrivNotice($this->main->from ,'Plugin Inconnu !');
}
}
break;
#=== Unload plugin
case 'ulplug' :
if($this->main->isBotOp($this->main->from) && !empty($T[2])){
$p_name = trim($T[2]);
if(isset($this->main->plugs->activePlugs[$p_name])){
$this->main->plugs->unloadPlug($p_name);
$this->main->sendPrivNotice($this->main->from ,'Plugin Déchargé');
}else{
$this->main->sendPrivNotice($this->main->from ,'Plugin Inactif !');
}
}
break;
#=== Display plug list
case 'listplug' :
$txt = explode ( "\n", trim($this->main->plugs->listPlug()));
foreach ( $txt as $line ) {
$this->main->sendPrivMsg( $this->main->from , $line );
}
break;
#=== Display plugin infos
case 'infoplug' :
if(!empty($T[2])){
$txt = explode ( "\n", trim($this->main->plugs->plugInfos(trim($T[2]))));
foreach ( $txt as $line ) {
$this->main->sendPrivMsg( $this->main->from , $line );
}
}
break;
#=== List nick on chan
case 'listnick' :
if($this->main->isBotOp($this->main->from)){
$this->main->sendPrivMsg($this->main->from, "\002Nicks on Chan :\002");
foreach($this->main->nickOnChan as $nick=>$time){
$this->main->sendPrivMsg($this->main->from, ' - '.trim($nick).' ('.date('Y-m-d H:i:s', $time).") ");
}
}
break;
#=== List bot operator
case 'listop' :
if($this->main->isBotOp($this->main->from)){
$this->main->sendPrivMsg($this->main->from, "\002 ".IRCConn::$myBotName." Opérators :\002");
foreach($this->main->botOp as $nick => $ident){
$identified = $ident ? 'Identifié' : 'Non identifié';
$this->main->sendPrivMsg($this->main->from, ' - '.trim($nick).' ('.$identified.')');
}
}
break;
#=== Set bot operator
case 'botop' :
if(!empty($T[2]) && trim($T[2]) == BOT_PWD){
if(isset($this->main->botOp[$this->main->from]) && !$this->main->botOp[$this->main->from]){
$this->main->botOp[$this->main->from] = TRUE;
$this->main->sendPrivNotice($this->main->from, 'You are now Bot Operator for me. Congratulations ! :)');
}
}else{
$this->main->sendPrivNotice($this->main->from, 'Password and auth required !');
}
break;
#=== Set bot operator
case 'setbotop' :
if($this->main->isBotOp($this->main->from)){
$nick=trim($T[2]);
if(!empty($nick) && isset($this->main->nickOnChan[$nick])){
$this->main->botOp[$nick]= TRUE;
$this->main->sendPrivNotice($nick , 'You are now Bot Operator for me. Congratulations ! :)');
}
}
break;
}
}
}
/**
* Answer CTCP request
*
* @param mess from chan
*
*/
private function CTCP($IRCtext) {
if(preg_match('`^:(.*?)!.*?@.*? PRIVMSG '.preg_quote(IRCConn::$myBotName, '`').'(.*?)(VERSION|USERINFO|CLIENTINFO)`', $IRCtext, $T)) {
$this->main->sendPrivNotice($T[1],' :XboT V'.IRCConn::$botVersion.' - PHP '.phpversion().' -- par Fabrice Lezoray (http://classes.scriptsphp.org/) modifié par mcAllan');
}
if(preg_match('`^:(.*?)!.*?@.*? PRIVMSG '.preg_quote(IRCConn::$myBotName, '`').'(.*?)PING (.*?)\r?\n`', $IRCtext, $T)) {
$this->main->sendPrivNotice($T[1]," \001PING".time()."\001");
}
if(preg_match('`^:(.*?)!.*?@.*? PRIVMSG '.preg_quote(IRCConn::$myBotName,'`').'(.*?)(TIME)`', $IRCtext, $T)) {
$this->main->sendPrivNotice($T[1],' '.date('Y-m-d H:i:s'));
}
}
}
?>
