Bot IRC - Documentation plugins
Plugin plug_hello
Permet au bot de dire bonjour.
Description
Ce plugin permet au bot de dire bonjour.
Le bot ne dira bonjour à un nick qu'une fois par 24h.
Une commande permet à tout utilisateur d'interdire au bot de lui dire bonjour.
Utilisation.
Commandes op�rateurs :
- !hellolist :: Affiche les paramètres en cours pour hello.
Commandes utilisateurs :
- !sayhello <1|yes|true|0|no|false> :: Interdit ou autorise le bot à vous dire bonjour.

Source du plugin.
<?php
/**
* fichier : plug_hello.php :
* plugin pour dire bonjour
*
* @package Cspbot
* @since 2006/08/17
* @version 0.3
* @author Fabrice Lezoray - Tetsuo - Alain Nicolas (mcAllan)
* @copyright See licence.txt
*
*/
class plug_hello extends plugin {
/**
* IRCMain object
* @var object IRCMain
*/
private $main;
/**
* array hello words
* @var array
*/
protected $hello = array('Bonjour', 'Salut', 'rahhhhh', 'Hi', 'lo', 'lu', 'hello', 'yep', 'kikoo', 'yala', '\'lut', 'bien le bonjour');
/**
* array nick having say hello
* @var array
*/
protected $haveSayHello = array();
/**
* array nick to don't say hello
* @var array
*/
protected $doNotSayHelloTo = array();
/**
* string file
* @var string
*/
public $doNotSayHelloToFile = './files/nohello.txt';
/**
* int time to say hello again
* @var array
*/
public $cctime = 86400;
/**
* Constructor
*
* @param IRCMain main
*
*/
public function __construct($main) {
$this->main = $main;
// Chargement de nohello.txt
$this->doNotSayHelloTo = explode("\n", file_get_contents($this->doNotSayHelloToFile));
}
/**
* Start run plugin
*
*/
public function start() {
$this->hello();
$this->NoHello();
$this->listNoHello();
}
/**
* Say hello
*
*/
private function hello() {
if(preg_match('`^:[^ ]+ 353 '.IRCConn::$myBotName.' = '.IRCConn::$channel.' :(.*?)\r?\n`', $this->main->msg, $T)){
$this->alreadyInChan = explode(' ', trim($T[1]));
foreach($this->alreadyInChan as $nick){
$nick = str_replace('@', '', $nick);
$this->haveSayHello[trim($nick)]= time();
}
}
$helloMask = '`^((?:sa|\')?lut?|b(?:on)?j(?:ou)?r|hello|slt|hi|lo|re|yop|\'jour)(( (.*))|$)`i';
if(preg_match($helloMask, trim($this->main->mess), $T)) {
//perform
// time 24hours to say hello again
$cctime = $this->cctime;
foreach($this->haveSayHello as $k => $v) {
if(time() - $v > $cctime) {
unset($this->haveSayHello[$k]);
}
}
$T[1] = $this->main->from;
if(!isset($this->haveSayHello[$T[1]])) {
srand(date('s'));
$rand = $this->hello[rand(0, count($this->hello)-1)];
$this->haveSayHello[$T[1]] = time();
if($this->sayHello == 1 && !in_array(strtolower($T[1]), $this->doNotSayHelloTo) ) {
$this->main->sendMsg($rand.' '.$this->main->from);
}
}
}
if(preg_match('`^:(.*?)!.*?@.*? NICK :(.*?)\r?\n`i', $this->main->msg, $T)) {
if(isset($this->haveSayHello[$T[1]])) {
$this->haveSayHello[$T[2]] = $this->haveSayHello[$T[1]];
unset($this->haveSayHello[$T[1]]);
}
}
}
/**
* Don't say hello
*
*/
private function NoHello() {
if(preg_match('`^:(.*?)!.*?@.*? PRIVMSG '.preg_quote(IRCCOnn::$myBotName).' : *sayhello *(1|yes|true|0|no|false) *\r?\n`', $this->main->msg, $T)) {
if(in_array($T[2], array('false', 'no', '0'))) {
if(!in_array(strtolower($T[1]), $this->doNotSayHelloTo)) {
$this->doNotSayHelloTo[] = strtolower(trim($T[1]));
file_put_contents($this->doNotSayHelloToFile, implode("\n", $this->doNotSayHelloTo));
$this->main->sendPrivNotice($T[1],' Je ne vous dirai désormais plus bonjour, vexé le moi !');
}
}elseif(in_array($T[2], array('true', 'yes', '1'))) {
$TMP = array_keys($this->doNotSayHelloTo, strtolower($T[1]));
foreach($TMP as $v) {
unset($this->doNotSayHelloTo[$v]);
}
file_put_contents($this->doNotSayHelloToFile, implode("\n", $this->doNotSayHelloTo));
$this->main->sendPrivNotice($T[1],' Ahhhh c\'est gentil ca :)....');
}
}
}
/**
* Hello params
*
*/
private function listNoHello(){
if(preg_match('`^!hellolist(.*?)`i', $this->main->mess,$T)) {
if($this->main->isBotOp($this->main->from)){
$list ='No hello to :';
foreach($this->doNotSayHelloTo as $nick){
$list .= ' - '.trim($nick);
}
$this->main->sendPrivMsg($this->main->from, $list);
$list ='Have say hello to :';
foreach($this->haveSayHello as $nick=>$time){
$list .= ' - '.trim($nick).'('.date('Y-m-d H:i:s', $time).')';
}
$this->main->sendPrivMsg($this->main->from, $list);
}
}
}
}
?>
/**
* fichier : plug_hello.php :
* plugin pour dire bonjour
*
* @package Cspbot
* @since 2006/08/17
* @version 0.3
* @author Fabrice Lezoray - Tetsuo - Alain Nicolas (mcAllan)
* @copyright See licence.txt
*
*/
class plug_hello extends plugin {
/**
* IRCMain object
* @var object IRCMain
*/
private $main;
/**
* array hello words
* @var array
*/
protected $hello = array('Bonjour', 'Salut', 'rahhhhh', 'Hi', 'lo', 'lu', 'hello', 'yep', 'kikoo', 'yala', '\'lut', 'bien le bonjour');
/**
* array nick having say hello
* @var array
*/
protected $haveSayHello = array();
/**
* array nick to don't say hello
* @var array
*/
protected $doNotSayHelloTo = array();
/**
* string file
* @var string
*/
public $doNotSayHelloToFile = './files/nohello.txt';
/**
* int time to say hello again
* @var array
*/
public $cctime = 86400;
/**
* Constructor
*
* @param IRCMain main
*
*/
public function __construct($main) {
$this->main = $main;
// Chargement de nohello.txt
$this->doNotSayHelloTo = explode("\n", file_get_contents($this->doNotSayHelloToFile));
}
/**
* Start run plugin
*
*/
public function start() {
$this->hello();
$this->NoHello();
$this->listNoHello();
}
/**
* Say hello
*
*/
private function hello() {
if(preg_match('`^:[^ ]+ 353 '.IRCConn::$myBotName.' = '.IRCConn::$channel.' :(.*?)\r?\n`', $this->main->msg, $T)){
$this->alreadyInChan = explode(' ', trim($T[1]));
foreach($this->alreadyInChan as $nick){
$nick = str_replace('@', '', $nick);
$this->haveSayHello[trim($nick)]= time();
}
}
$helloMask = '`^((?:sa|\')?lut?|b(?:on)?j(?:ou)?r|hello|slt|hi|lo|re|yop|\'jour)(( (.*))|$)`i';
if(preg_match($helloMask, trim($this->main->mess), $T)) {
//perform
// time 24hours to say hello again
$cctime = $this->cctime;
foreach($this->haveSayHello as $k => $v) {
if(time() - $v > $cctime) {
unset($this->haveSayHello[$k]);
}
}
$T[1] = $this->main->from;
if(!isset($this->haveSayHello[$T[1]])) {
srand(date('s'));
$rand = $this->hello[rand(0, count($this->hello)-1)];
$this->haveSayHello[$T[1]] = time();
if($this->sayHello == 1 && !in_array(strtolower($T[1]), $this->doNotSayHelloTo) ) {
$this->main->sendMsg($rand.' '.$this->main->from);
}
}
}
if(preg_match('`^:(.*?)!.*?@.*? NICK :(.*?)\r?\n`i', $this->main->msg, $T)) {
if(isset($this->haveSayHello[$T[1]])) {
$this->haveSayHello[$T[2]] = $this->haveSayHello[$T[1]];
unset($this->haveSayHello[$T[1]]);
}
}
}
/**
* Don't say hello
*
*/
private function NoHello() {
if(preg_match('`^:(.*?)!.*?@.*? PRIVMSG '.preg_quote(IRCCOnn::$myBotName).' : *sayhello *(1|yes|true|0|no|false) *\r?\n`', $this->main->msg, $T)) {
if(in_array($T[2], array('false', 'no', '0'))) {
if(!in_array(strtolower($T[1]), $this->doNotSayHelloTo)) {
$this->doNotSayHelloTo[] = strtolower(trim($T[1]));
file_put_contents($this->doNotSayHelloToFile, implode("\n", $this->doNotSayHelloTo));
$this->main->sendPrivNotice($T[1],' Je ne vous dirai désormais plus bonjour, vexé le moi !');
}
}elseif(in_array($T[2], array('true', 'yes', '1'))) {
$TMP = array_keys($this->doNotSayHelloTo, strtolower($T[1]));
foreach($TMP as $v) {
unset($this->doNotSayHelloTo[$v]);
}
file_put_contents($this->doNotSayHelloToFile, implode("\n", $this->doNotSayHelloTo));
$this->main->sendPrivNotice($T[1],' Ahhhh c\'est gentil ca :)....');
}
}
}
/**
* Hello params
*
*/
private function listNoHello(){
if(preg_match('`^!hellolist(.*?)`i', $this->main->mess,$T)) {
if($this->main->isBotOp($this->main->from)){
$list ='No hello to :';
foreach($this->doNotSayHelloTo as $nick){
$list .= ' - '.trim($nick);
}
$this->main->sendPrivMsg($this->main->from, $list);
$list ='Have say hello to :';
foreach($this->haveSayHello as $nick=>$time){
$list .= ' - '.trim($nick).'('.date('Y-m-d H:i:s', $time).')';
}
$this->main->sendPrivMsg($this->main->from, $list);
}
}
}
}
?>
