Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

BOT IRC : GÉNÉRATEURS DE LOGS AU FORMAT MIRC


Information sur la source

Catégorie :Class et Objet ( POO ) Classé sous : irc, bot, php, log Niveau : Initié Date de création : 02/07/2008 Date de mise à jour : 22/10/2008 18:41:40 Vu : 2 219

Note :
8,5 / 10 - par 2 personnes
8,50 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (8)
Ajouter un commentaire et/ou une note

Description

Bot irc en php. Il permet si on le souhaite de générer des logs pour les différents salons où il est loggé.

Encore en phase de test.
 

Source

  • #!/usr/bin/php5
  • <?php
  • class MyException extends Exception {
  • public function __construct($erreur=null, $code=0) {
  • parent::__construct($erreur, $code);
  • }
  • public function echoErreur($exit=false) {
  • echo $this->getMessage();
  • if($exit) {
  • exit;
  • }
  • }
  • }
  • class IrcConnection {
  • protected $cfg_IrcConnexion = array();
  • protected $connection = null;
  • protected function __construct($server, $port) {
  • $this->cfg_IrcConnexion = array(
  • 'server' => $server,
  • 'port' => $port
  • );
  • $this->connection = null;
  • }
  • protected function doConnection() {
  • try {
  • $connection = @fsockopen( $this->cfg_IrcConnexion['server'], $this->cfg_IrcConnexion['port'], $errorId, $errorMessage );
  • if( !$connection ) {
  • throw new MyException('ERREUR : Connexion au serveur impossible. Code ['.$errorId.'] : '.$errorMessage."\r\n");
  • } else {
  • $this->connection = $connection;
  • }
  • } catch (MyException $e) {
  • $e->echoErreur(true);
  • }
  • }
  • }
  • class Bot extends IrcConnection {
  • public $serveur;
  • public $port;
  • public $bold;
  • public $reverse;
  • public $color;
  • private $botConnection;
  • private $stats;
  • public $cfg_bot = array();
  • public $cfg_server = array();
  • public $cfg_channels = array();
  • public $enable_stats;
  • public $cfg_stats = array();
  • public function __construct() {
  • $this->cfg_bot = array(
  • 'nick' => 'MyBot',
  • 'host' => 'MyHost',
  • 'mail' => 'mybot@myhost.tld'
  • );
  • $this->cfg_server = array(
  • 'server' => 'domain.tld',
  • 'port' => 6667
  • );
  • $this->cfg_stats = array(
  • 'enable' => false
  • );
  • $this->cfg_channels = array();
  • $this->botConnection = null;
  • $this->bold = '';
  • $this->reverse = '';
  • $this->color = '';
  • }
  • public function setConfig($type, $name, $value) {
  • if($type=='bot') {
  • $this->cfg_bot[$name] = $value;
  • }
  • if($type=='server') {
  • $this->cfg_server[$name] = $value;
  • }
  • if($type=='stats') {
  • $this->cfg_stats[$name] = $value;
  • }
  • }
  • public function addChannelsToJoin($channels) {
  • $channels = explode(',', $channels);
  • foreach($channels as $channel) {
  • $channel = trim($channel);
  • if(!empty($channel)) {
  • $this->cfg_channels[] = $channel;
  • }
  • }
  • }
  • private function sendIrcMessage($message) {
  • fwrite($this->botConnection, $message);
  • }
  • private function identifyBot() {
  • $this->sendIrcMessage('USER '.$this->cfg_bot['nick'].' '.$this->cfg_bot['mail'].' '.$this->cfg_bot['host'].' :'.$this->cfg_bot['nick']."\r\n");
  • $this->sendIrcMessage('NICK '.$this->cfg_bot['nick']."\r\n");
  • }
  • private function joinChannels() {
  • foreach( $this->cfg_channels as $channel) {
  • $this->sendIrcMessage('JOIN '.$channel."\r\n");
  • }
  • }
  • private function getTime() {
  • return strtolower(date('d/m/y H:i:s', time()));
  • }
  • private function pong($ping) {
  • $this->sendIrcMessage('PONG '.$ping);
  • }
  • public function makeCfgStats($cfg) {
  • $this->cfg_stats = $cfg;
  • }
  • private function analyseLine($line) {
  • static $instance = false;
  • if(preg_match('`^PING`', $line)) {
  • $explode = explode(' ', $line);
  • $this->pong($explode[1]);
  • }
  • else {
  • preg_match("`^:([^!]+)!([^ ]+) *([^ ]+) *([^ ]+) *:`isU", $line, $infos);
  • $texte = str_replace($infos[0], '', $line);
  • if(isset($infos[4])) {
  • $channel = trim($infos[4]);
  • if($channel == 'JOIN') {
  • $channel = trim(array_pop(explode(':', $line)));
  • }
  • if(ereg('!regles', $line) && $infos[1] != $this->cfg_bot['nick']) {
  • $this->giveRegles($infos[1], $channel);
  • }
  • if(ereg('!help2', $line) && $infos[1] != $this->cfg_bot['nick']) {
  • $this->giveHelp2($infos[1], $channel);
  • }
  • elseif(ereg('!help3', $line) && $infos[1] != $this->cfg_bot['nick']) {
  • $this->giveHelp3($infos[1], $channel);
  • }
  • elseif(ereg('!help4', $line) && $infos[1] != $this->cfg_bot['nick']) {
  • $this->giveHelp4($infos[1], $channel);
  • }
  • elseif(ereg('!help5', $line) && $infos[1] != $this->cfg_bot['nick']) {
  • $this->giveHelp5($infos[1], $channel);
  • }
  • elseif(ereg('!help', $line) && $infos[1] != $this->cfg_bot['nick']) {
  • $this->giveHelp($infos[1], $channel);
  • }
  • if(preg_match('`^!calin`', $texte)) {
  • $to = str_replace('!calin', '', $texte);
  • if(trim($to) != '') {
  • $this->sendCalin($infos[1], trim($to), $channel);
  • }
  • }
  • if(preg_match('`^!owned`', $texte)) {
  • $to = str_replace('!owned', '', $texte);
  • if(trim($to) != '') {
  • $this->sendOwned($infos[1], trim($to), $channel);
  • }
  • }
  • if(preg_match('`^!boulet`', $texte)) {
  • $to = str_replace('!boulet', '', $texte);
  • if(trim($to) != '') {
  • $this->sendBoulet($infos[1], trim($to), $channel);
  • }
  • }
  • if(preg_match('`^!taloche`', $texte)) {
  • $to = str_replace('!taloche', '', $texte);
  • if(trim($to) != '') {
  • $this->sendTaloche($infos[1], trim($to), $channel);
  • }
  • }
  • if(preg_match('`^!hache`', $texte)) {
  • $to = str_replace('!hache', '', $texte);
  • if(trim($to) != '') {
  • $this->sendHache($infos[1], trim($to), $channel);
  • }
  • }
  • if(preg_match('`^!apwal`', $texte)) {
  • $to = str_replace('!apwal', '', $texte);
  • if(trim($to) != '') {
  • $this->sendApwal($infos[1], trim($to), $channel);
  • }
  • }
  • if(preg_match('`^!bisous`', $texte)) {
  • $to = str_replace('!bisous', '', $texte);
  • if(trim($to) != '') {
  • $this->sendBisous($infos[1], trim($to), $channel);
  • }
  • }
  • if(preg_match('`^!ange`', $texte)) {
  • $to = str_replace('!ange', '', $texte);
  • if(trim($to) != '') {
  • $this->sendAnge($infos[1], trim($to), $channel);
  • }
  • }
  • if(preg_match('`^!clope`', $texte)) {
  • $to = str_replace('!clope', '', $texte);
  • if(trim($to) != '') {
  • $this->sendClope($infos[1], trim($to), $channel);
  • }
  • }
  • if(preg_match('`^!cafe`', $texte)) {
  • $to = str_replace('!cafe', '', $texte);
  • if(trim($to) != '') {
  • $this->sendCafe($infos[1], trim($to), $channel);
  • }
  • }
  • if(preg_match('`^!boude`', $texte)) {
  • $to = str_replace('!boude', '', $texte);
  • if(trim($to) != '') {
  • $this->sendBoude($infos[1], trim($to), $channel);
  • }
  • }
  • if(preg_match('`^!taggle`', $texte)) {
  • $to = str_replace('!taggle', '', $texte);
  • if(trim($to) != '') {
  • $this->sendTaggle($infos[1], trim($to), $channel);
  • }
  • }
  • if(preg_match('`^!love`', $texte)) {
  • $to = str_replace('!love', '', $texte);
  • if(trim($to) != '') {
  • $this->sendLove($infos[1], trim($to), $channel);
  • }
  • }
  • if(preg_match('`^!hate`', $texte)) {
  • $to = str_replace('!hate', '', $texte);
  • if(trim($to) != '') {
  • $this->sendHate($infos[1], trim($to), $channel);
  • }
  • }
  • if(preg_match('`^!ame`', $texte)) {
  • $to = str_replace('!ame', '', $texte);
  • if(trim($to) != '') {
  • $this->sendAme($infos[1], trim($to), $channel);
  • }
  • }
  • if(preg_match('`^!cux`', $texte)) {
  • $to = str_replace('!cux', '', $texte);
  • if(trim($to) != '') {
  • $this->sendCux($infos[1], trim($to), $channel);
  • }
  • }
  • if(preg_match('`^!nutella`', $texte)) {
  • $to = str_replace('!nutella', '', $texte);
  • if(trim($to) != '') {
  • $this->sendNutella($infos[1], trim($to), $channel);
  • }
  • }
  • if(preg_match('`^!tupues`', $texte)) {
  • $to = str_replace('!tupues', '', $texte);
  • if(trim($to) != '') {
  • $this->sendTupues($infos[1], trim($to), $channel);
  • }
  • }
  • if(preg_match('`^!prout`', $texte)) {
  • $to = str_replace('!prout', '', $texte);
  • $this->sendProut($infos[1], trim($to), $channel);
  • }
  • if(preg_match('`^!sarko`', $texte)) {
  • $to = str_replace('!sarko', '', $texte);
  • if(trim($to) != '') {
  • $this->sendSarko($infos[1], trim($to), $channel);
  • }
  • }
  • if(preg_match('`^!donner`', $texte)) {
  • $to = str_replace('!donner', '', $texte);
  • if(trim($to) != '') {
  • while(substr_count($to, ' ')) {
  • $to = str_replace(' ', ' ', $to);
  • }
  • $ex = explode(' ', trim($to));
  • if(count($ex) > 1) {
  • $to = trim($ex[0]);
  • unset($ex[0]);
  • $quoi = implode(' ', $ex);
  • $this->sendDonner($infos[1], $to, $quoi, $channel);
  • }
  • }
  • }
  • if(ereg(' JOIN ', $line) && $infos[1] != $this->cfg_bot['nick']) {
  • $this->giveJoinInfos($infos[1]);
  • }
  • if( $this->cfg_stats['enable'] ) {
  • if(ereg('!stats', $line) && $infos[1] != $this->cfg_bot['nick']) {
  • $this->giveStatsUrl($channel);
  • }
  • if(!$instance) {
  • $instance = new BotStats($this->cfg_stats, $this->cfg_server['server'], $this->cfg_channels) ;
  • }
  • $instance->updateLogs($this->getTime().' '.$line, $channel);
  • }
  • }
  • }
  • }
  • public function connectBot() {
  • parent::__construct($this->cfg_server['server'], $this->cfg_server['port']);
  • $this->doConnection();
  • $this->botConnection = $this->connection;
  • $this->identifyBot();
  • $this->joinChannels();
  • while (!feof($this->botConnection)) {
  • $line = fgets($this->botConnection, 1024);
  • $this->analyseLine($line);
  • }
  • }
  • private function giveJoinInfos($nick) {
  • $this->sendIrcMessage('NOTICE '.$nick.' Bienvenue sur le chan de Deblan.fr !'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Simmstein est le seul intervenant pour les reclamations vis a vis de l\'equipe de moderation'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Les regles sont accessibles via !regles'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Retrouves les stats du chan en tappant !stats'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Tapes !help pour avoir la liste des commandes utilisees pour DebStats'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' Amuse-toi bien ;)'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  • }
  • private function giveRegles($nick) {
  • $this->sendIrcMessage('NOTICE '.$nick.' Regles du chan irc :'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Pas d\'insultes qui blaissent. Vive le second degre'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Evite le flood'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - En cas de probleme : simon@deblan.fr ou en prive'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Les operateurs font leur taf, ne remet pas en cause leurs sanctions'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  • }
  • private function giveHelp($nick) {
  • $this->sendIrcMessage('NOTICE '.$nick.' Liste des commandes utilisees pour DebStats (partie 1) :'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - LE RESTE DES COMMANDES : !help2, !help3, !help4, !help5'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Les regles du chan sont dispos via : !regles'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Retrouver les stats du chan : !stats'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Faire un gros calin : !calin <destinataire>'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Faire des bisous : !bisous <destinataire>'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Fait savoir que tu aimes une personnes... : !love <destinataire>'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  • }
  • private function giveHelp2($nick) {
  • $this->sendIrcMessage('NOTICE '.$nick.' Liste des commandes utilisees pour DebStats (partie 2) :'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - LE RESTE DES COMMANDES : !help, !help3, !help4, !help5'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Frapper quelqu\'un (a) : !taloche <destinataire>'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Oh quel ange :o : !ange <destinataire>'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Donner une clope : !clope <destinataire>'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Servir un cafe : !cafe <destinataire>'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Donner quelque chose : !donner <destinataire> <la chose>'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  • }
  • private function giveHelp3($nick) {
  • $this->sendIrcMessage('NOTICE '.$nick.' Liste des commandes utilisees pour DebStats (partie 3) :'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - LE RESTE DES COMMANDES : !help, !help2, !help4, !help5'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Une envie soudaine qu\'il/elle ferme saggle ? : !taggle <destinataire>'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Tu veux bouder quelqu\'un ? : !boude <destinataire>'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Dis lui de se mettre a pwal !! : !apwal <destinataire>'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Paix a son ame... : !ame <destinataire>'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Prepare toi a bucheronner quelqu\'un avec une hache... : !hache <destinataire>'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  • }
  • private function giveHelp4($nick) {
  • $this->sendIrcMessage('NOTICE '.$nick.' Liste des commandes utilisees pour DebStats (partie 4) :'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - LE RESTE DES COMMANDES : !help, !help2, !help3, !help5'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Tu hais quelqu\'un ? : !hate <destinataire>'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Tartiner une personne avec du nutella : !nutella <destinataire>'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Tu veux lui pincer les fesses ? : !cux <destinataire>'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Elle/il pue ? Dis lui : !tupues <destinataire>'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Arf, tu viens de peter... : !proute'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  • }
  • private function giveHelp5($nick) {
  • $this->sendIrcMessage('NOTICE '.$nick.' Liste des commandes utilisees pour DebStats (partie 5) :'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - LE RESTE DES COMMANDES : !help, !help2, !help3, !help4'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - On a besoin d\'un karcher... : !sarko <destinataire>'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Mais quel boulet... : !boulet <destinataire>'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' - Il l\'a owned :D : !owned <destinataire>'."\r\n");
  • $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  • }
  • private function giveStatsUrl($channel) {
  • $file = $this->cfg_stats['pisg_html_page_dir'].$this->cfg_server['server'].'.'.str_replace('#', '', $channel).'.html';
  • if( file_exists($file) ) {
  • $ftime = filemtime($file);
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'10 Url : http://irc.deblan.fr/stats.php?chan='.$this->cfg_server['server'].'.'.str_replace('#', '', $channel).' - Derniere mise a jour il y a '.$this->bold.date('i',
  • time()-$ftime)." minute(s) et ".date('s', time()-$ftime)." seconde(s)\r\n");
  • }
  • }
  • private function giveInfos() {
  • $this->sendIrcMessage('PRIVMSG '.$channel.' Je suis le bot qui s\'occupe de generer des logs pour le chan. Merci de ne pas me faire chier !'."\r\n");
  • }
  • private function sendCalin($from, $to, $channel) {
  • if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
  • else
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 fait un groooOOOooos calin a '.$this->color.'13'.$to.$this->color.'4 <3<3<3<3<3<3<3'."\r\n");
  • }
  • private function sendTaloche($from, $to, $channel) {
  • if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
  • else
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 balance une grosse taloche dans la gueule a '.$this->color.'13'.$to.$this->color.'4 !!!'."\r\n");
  • }
  • private function sendHache($from, $to, $channel) {
  • if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
  • else
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 aiguise sa hache en regardant '.$this->color.'13'.$to.$this->color.'10 tel un bucheron devant un vieux chene...'."\r\n");
  • }
  • private function sendBisous($from, $to, $channel) {
  • if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
  • else
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 fait tout plein de gros bisous a '.$this->color.'13'.$to.$this->color.'4 <3<3<3'."\r\n");
  • }
  • private function sendBoude($from, $to, $channel) {
  • if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
  • else
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 detourne la tete et boude '.$this->color.'13'.$to.$this->color.'10 =('."\r\n");
  • }
  • private function sendLove($from, $to, $channel) {
  • if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
  • else
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$to.$this->color.'10 ? Y\'a '.$this->color.'13'.$from.$this->color.'10 qui t\'aime...'.$this->color.'4 <3<3<3'."\r\n");
  • }
  • private function sendHate($from, $to, $channel) {
  • if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
  • else
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$to.$this->color.'10 ? '.$this->color.'13'.$from.$this->color.'10 te fait savoir qu\'il a envie de te pendre avec tes tripes'.$this->color.'4 :@'."\r\n");
  • }
  • private function sendBoulet($from, $to, $channel) {
  • if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
  • else
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'10Bordel...'.$this->color.'13'.$to.$this->color.'10...C\'est vraiment qu\'un boulet ><'."\r\n");
  • }
  • private function sendAme($from, $to, $channel) {
  • if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
  • else
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'10Paix a ton ame '.$this->color.'13'.$to.$this->color.'10...'.$this->bold.$this->color.'1 +'."\r\n");
  • }
  • private function sendTupues($from, $to, $channel) {
  • if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
  • else
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$to.$this->color.'10 TUPUES !!!'."\r\n");
  • }
  • private function sendProut($from, $to, $channel) {
  • if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
  • else
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 est ignoble, il vient de peter...'.$this->bold.$this->color.'3 :s'."\r\n");
  • }
  • private function sendNutella($from, $to, $channel) {
  • if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
  • else
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 tartineuh '.$this->color.'13'.$to.$this->color.'10 avec amoureuh ^^'."\r\n");
  • }
  • private function sendCux($from, $to, $channel) {
  • if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
  • else
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 pince les fesses de '.$this->color.'13'.$to.$this->color.'10 Owi !!!'."\r\n");
  • }
  • private function sendClope($from, $to, $channel) {
  • if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
  • else
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 offre une clope a '.$this->color.'13'.$to."\r\n");
  • }
  • private function sendSarko($from, $to, $channel) {
  • if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
  • else
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$to.$this->color.'10, va chercher le karcher...y\'a des racailles ici'."\r\n");
  • }
  • private function sendCafe($from, $to, $channel) {
  • if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
  • else
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 sert un bon cafe a '.$this->color.'13'.$to."\r\n");
  • }
  • private function sendAnge($from, $to, $channel) {
  • if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
  • else
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$to.$this->color.'10 est un vrai ange ^^ '.$this->bold.$this->color.'8O'.$this->color.'7:)'."\r\n");
  • }
  • private function sendTaggle($from, $to, $channel) {
  • if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
  • else
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 propose a '.$this->color.'13'.$to.$this->color.'10 de '.$this->color.'4fermer sa grande gueule '.$this->color.'10XD'."\r\n");
  • }
  • private function sendApwal($from, $to, $channel) {
  • if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
  • else
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 voudrait bien que '.$this->color.'13'.$to.$this->color.'10 se '.$this->color.'4foutte a APWAL !!! '."\r\n");
  • }
  • private function sendDonner($from, $to, $quoi, $channel) {
  • if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
  • else
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 donne '.$this->color.'4'.$quoi.$this->color.'10 a '.$this->color.'13'.$to."\r\n");
  • }
  • private function sendSkyzo($nick) {
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'10Oh putain !! '.$this->color.'13'.$nick.$this->color.'10 est sckyzo !!'."\r\n");
  • }
  • private function sendOwned($from, $to, $channel) {
  • $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'10Mouahahahahahaha comment il t\'a owned '.$this->color.'13'.$to.$this->color.'10 /o/'."\r\n");
  • }
  • }
  • class BotStats extends Bot {
  • protected $cfg;
  • protected $server;
  • private $logs_files_names;
  • private $flog_files;
  • private $channels = array();
  • public function __construct($cfg_stats, $server, $channels) {
  • $this->flog_files = array();
  • $this->logs_files_names = array();
  • $this->channels = $channels;
  • $this->server = $server;
  • try {
  • if( $this->canUseBotStats() ) {
  • $this->makeConfiguration($cfg_stats);
  • $this->make_logs_files_names($channels);
  • $this->openLogsFiles();
  • } else {
  • throw new MyException('Impossible d\'utiliser les stats ! Fonction(s) php manquante(s) ou inactive(s)');
  • }
  • } catch (Exception $e) {
  • $e->echoErreur(true);
  • }
  • }
  • private function makeConfiguration($cfg_stats) {
  • $this->cfg = array(
  • 'log_file_dir' => '',
  • 'max_log_line' => 1000,
  • 'pisg_html_page_dir' => '',
  • 'stats' => false
  • );
  • foreach($cfg_stats as $key => $_cfg) {
  • if(isset( $this->cfg[$key] )) {
  • $this->cfg[$key] = $_cfg;
  • }
  • }
  • }
  • private function canUseBotStats() {
  • $possible = true;
  • if(!function_exists('fsockopen')) $possible = false;
  • if(!function_exists('fwrite')) $possible = false;
  • if(!function_exists('feof')) $possible = false;
  • if(!function_exists('fgets')) $possible = false;
  • return $possible;
  • }
  • private function get_log_file_name($channel) {
  • if(isset( $this->cfg[$channel] ) ) {
  • return $this->cfg[$channel];
  • } else {
  • return false;
  • }
  • }
  • private function getNumberLogLine($channel) {
  • if(file_exists($this->get_log_file_name($channel))) {
  • if(is_readable($this->get_log_file_name($channel))) {
  • return count(file($this->get_log_file_name($channel)));
  • } else {
  • return 0;
  • }
  • } else {
  • return 0;
  • }
  • }
  • private function make_logs_files_names() {
  • foreach($this->channels as $channel) {
  • $this->logs_files_names[$channel] = $this->cfg['log_file_dir'].$this->server.'.'.str_replace(array('"', '#'), '', $channel).'.log';
  • }
  • }
  • private function openLogsFiles() {
  • $ok = true;
  • foreach( $this->logs_files_names as $file) {
  • if( file_exists($file)) {
  • if(!is_readable($file)) {
  • $erreur.= 'ERREUR : Le fichier de log "'.$file.'" n\'est pas lisible !'."\r\n";
  • $ok = false;
  • }
  • }
  • }
  • try {
  • if(!$ok) {
  • throw new MyException($erreur);
  • }
  • } catch (Exception $e) {
  • $e->echoErreur(true);
  • }
  • try {
  • foreach( $this->logs_files_names as $key => $file) {
  • $this->flog_files[$key] = $this->openFile($file);
  • }
  • } catch (Exception $e) {
  • $e->echoErreur(true);
  • }
  • }
  • private function openFile($file) {
  • try {
  • if(!$open = @fopen($file, 'a+')) {
  • throw new MyException('ERREUR : impossible d\'ouvrir : '.$file."\r\n");
  • }
  • return $open;
  • } catch (Exception $e) {
  • $e->echoErreur(true);
  • }
  • }
  • public function updateLogs($log_line, $channel) {
  • try {
  • if(!$write = @fwrite($this->flog_files[$channel], $log_line)) {
  • throw new MyException('ERREUR : Impossible d\'ecrire dans le fichier de log ('.$this->get_log_file_name($channel).')'."\r\n");
  • }
  • } catch (MyException $e) {
  • $e->echoErreur(false);
  • }
  • }
  • }
  • function makeGet() {
  • global $argv;
  • unset($argv[0]);
  • $get = array();
  • $c = count($argv);
  • if($c > 0) {
  • if($c%2 == 0) {
  • foreach($argv as $key=>$vl) {
  • if($key%2==1) {
  • $get[$vl] = $argv[$key+1];
  • }
  • }
  • }
  • }
  • return $get;
  • }
  • $get = makeGet();
  • $bot = new Bot();
  • $bot->setConfig('server', 'server', 'deblan.fr');
  • $bot->setConfig('server', 'port', 6667);
  • $bot->setConfig('stats', 'enable', true);
  • if(isset($get['-serveur'])) $bot->setConfig('server', 'server', $get['-serveur']);
  • if(isset($get['-port'])) $bot->setConfig('server', 'port', $get['-port']);
  • if(isset($get['-channels'])) $bot->addChannelsToJoin($get['-channels']);
  • if(isset($get['-nick'])) $bot->setConfig('bot', 'nick', $get['-nick']);
  • if(isset($get['-host'])) $bot->setConfig('bot', 'host', $get['-host']);
  • if(isset($get['-mail'])) $bot->setConfig('bot', 'mail', $get['-mail']);
  • if(isset($get['-log_file_dir'])) $bot->setConfig('stats', 'log_file_dir', $get['-log_file_dir']);
  • if(isset($get['-max_log_line'])) $bot->setConfig('stats', 'max_log_line', $get['-max_log_line']);
  • if(isset($get['-pisg_html_page_dir'])) $bot->setConfig('stats', 'pisg_html_page_dir', $get['-pisg_html_page_dir']);
  • if(isset($get['-enable_stats'])) {
  • if($get['-enable_stats'] == 'on') {
  • $bot->setConfig('stats', 'enable', true);
  • }
  • if($get['-enable_stats'] == 'off') {
  • $bot->setConfig('stats', 'enable', false);
  • }
  • }
  • $bot->connectBot();
#!/usr/bin/php5
<?php
class MyException extends Exception  { 
    public function __construct($erreur=null, $code=0)  { 
        parent::__construct($erreur, $code); 
    } 
     
    public function echoErreur($exit=false)  { 
      echo $this->getMessage(); 
      if($exit) {
        exit;
      }
    } 
} 


class IrcConnection {
  protected $cfg_IrcConnexion = array();
  protected $connection       = null;
  
  protected function __construct($server, $port) {
    $this->cfg_IrcConnexion = array(
      'server' => $server,
      'port'   => $port
    );
    $this->connection = null;
  }
  
  protected function doConnection() {
    try {
      $connection = @fsockopen( $this->cfg_IrcConnexion['server'], $this->cfg_IrcConnexion['port'], $errorId, $errorMessage );
      if( !$connection ) {
        throw new MyException('ERREUR : Connexion au serveur impossible. Code ['.$errorId.'] : '.$errorMessage."\r\n");
      }  else {
        $this->connection = $connection;
      }
    } catch (MyException $e) {
      $e->echoErreur(true);
    }
  }
}

class Bot extends IrcConnection {

  public $serveur;
  public $port;
  
  public $bold;
  public $reverse;
  public $color; 
  
  private $botConnection;
  private $stats;
  
  public $cfg_bot      = array(); 
  public $cfg_server   = array(); 
  public $cfg_channels = array();
  
  public $enable_stats;
  public $cfg_stats     = array();

  public function __construct() {
    $this->cfg_bot = array(
      'nick'               => 'MyBot',
      'host'               => 'MyHost',
      'mail'               => 'mybot@myhost.tld'
    );
    
    $this->cfg_server = array(
      'server'             => 'domain.tld',
      'port'               => 6667
    );
    
    $this->cfg_stats = array(
      'enable'              => false
    );
    
    $this->cfg_channels  = array();
    $this->botConnection = null;
    $this->bold = '';
    $this->reverse = '';
    $this->color = '';
  }
  
  public function setConfig($type, $name, $value) {
    if($type=='bot') {
      $this->cfg_bot[$name] = $value;
    }
    if($type=='server') {
      $this->cfg_server[$name] = $value;
    }
    if($type=='stats') {
      $this->cfg_stats[$name] = $value;
    }
  }
      
  public function addChannelsToJoin($channels) {
    $channels = explode(',', $channels);
    foreach($channels as $channel) {
      $channel = trim($channel);
      if(!empty($channel)) {
        $this->cfg_channels[] = $channel;
      }
    }
  }
  
  private function sendIrcMessage($message) {
    fwrite($this->botConnection, $message);
  }
  
  private function identifyBot() {
    $this->sendIrcMessage('USER '.$this->cfg_bot['nick'].' '.$this->cfg_bot['mail'].' '.$this->cfg_bot['host'].' :'.$this->cfg_bot['nick']."\r\n");
    $this->sendIrcMessage('NICK '.$this->cfg_bot['nick']."\r\n");
  }
  
  private function joinChannels() {
    foreach( $this->cfg_channels as $channel) {
      $this->sendIrcMessage('JOIN '.$channel."\r\n");
    }
  }
  
  private function getTime() {
    return strtolower(date('d/m/y H:i:s', time()));
  }
  
  private function pong($ping) {
    $this->sendIrcMessage('PONG '.$ping);
  }
  
  public function makeCfgStats($cfg) {
    $this->cfg_stats = $cfg;
  }
  
  private function analyseLine($line) {
    static $instance = false;
    if(preg_match('`^PING`', $line)) {
      $explode = explode(' ', $line);
      $this->pong($explode[1]);
    }
    
    else {
      preg_match("`^:([^!]+)!([^ ]+) *([^ ]+) *([^ ]+) *:`isU", $line, $infos);
      $texte = str_replace($infos[0], '', $line);
      
      
      if(isset($infos[4])) {
        $channel = trim($infos[4]);
        if($channel == 'JOIN') {
          $channel = trim(array_pop(explode(':', $line)));
        }
      
        if(ereg('!regles', $line) && $infos[1] != $this->cfg_bot['nick']) {
          $this->giveRegles($infos[1], $channel);
        }
        if(ereg('!help2', $line) && $infos[1] != $this->cfg_bot['nick']) {
          $this->giveHelp2($infos[1], $channel);
        }
        elseif(ereg('!help3', $line) && $infos[1] != $this->cfg_bot['nick']) {
          $this->giveHelp3($infos[1], $channel);
        }
        elseif(ereg('!help4', $line) && $infos[1] != $this->cfg_bot['nick']) {
          $this->giveHelp4($infos[1], $channel);
        }
        elseif(ereg('!help5', $line) && $infos[1] != $this->cfg_bot['nick']) {
          $this->giveHelp5($infos[1], $channel);
        }
        elseif(ereg('!help', $line) && $infos[1] != $this->cfg_bot['nick']) {
          $this->giveHelp($infos[1], $channel);
        }

        if(preg_match('`^!calin`', $texte)) {
          $to = str_replace('!calin', '', $texte);
          if(trim($to) != '') {
            $this->sendCalin($infos[1], trim($to), $channel);
          }
        }
      
        if(preg_match('`^!owned`', $texte)) {
          $to = str_replace('!owned', '', $texte);
          if(trim($to) != '') {
            $this->sendOwned($infos[1], trim($to), $channel);
          }
        }
      
        if(preg_match('`^!boulet`', $texte)) {
          $to = str_replace('!boulet', '', $texte);
          if(trim($to) != '') {
            $this->sendBoulet($infos[1], trim($to), $channel);
          }
        }
      
        if(preg_match('`^!taloche`', $texte)) {
          $to = str_replace('!taloche', '', $texte);
          if(trim($to) != '') {
            $this->sendTaloche($infos[1], trim($to), $channel);
          }
        }      
       
        if(preg_match('`^!hache`', $texte)) {
          $to = str_replace('!hache', '', $texte);
          if(trim($to) != '') {
            $this->sendHache($infos[1], trim($to), $channel);
          }
        }      

        if(preg_match('`^!apwal`', $texte)) {
          $to = str_replace('!apwal', '', $texte);
          if(trim($to) != '') {
            $this->sendApwal($infos[1], trim($to), $channel);
          }
        }    
      
        if(preg_match('`^!bisous`', $texte)) {
          $to = str_replace('!bisous', '', $texte);
          if(trim($to) != '') {
            $this->sendBisous($infos[1], trim($to), $channel);
          }
        }      
      
        if(preg_match('`^!ange`', $texte)) {
          $to = str_replace('!ange', '', $texte);
          if(trim($to) != '') {
            $this->sendAnge($infos[1], trim($to), $channel);
          }
        }    
      
        if(preg_match('`^!clope`', $texte)) {
          $to = str_replace('!clope', '', $texte);
          if(trim($to) != '') {
            $this->sendClope($infos[1], trim($to), $channel);
          }
        }    

        if(preg_match('`^!cafe`', $texte)) {
          $to = str_replace('!cafe', '', $texte);
          if(trim($to) != '') {
            $this->sendCafe($infos[1], trim($to), $channel);
          }
        }    

        if(preg_match('`^!boude`', $texte)) {
          $to = str_replace('!boude', '', $texte);
          if(trim($to) != '') {
            $this->sendBoude($infos[1], trim($to), $channel);
          }
        }    

        if(preg_match('`^!taggle`', $texte)) {
          $to = str_replace('!taggle', '', $texte);
          if(trim($to) != '') {
            $this->sendTaggle($infos[1], trim($to), $channel);
          }
        }    
    
        if(preg_match('`^!love`', $texte)) {
          $to = str_replace('!love', '', $texte);
          if(trim($to) != '') {
            $this->sendLove($infos[1], trim($to), $channel);
          }
        }        
      

        if(preg_match('`^!hate`', $texte)) {
          $to = str_replace('!hate', '', $texte);
          if(trim($to) != '') {
            $this->sendHate($infos[1], trim($to), $channel);
          }
        }        
      
        if(preg_match('`^!ame`', $texte)) {
          $to = str_replace('!ame', '', $texte);
          if(trim($to) != '') {
            $this->sendAme($infos[1], trim($to), $channel);
          }
        }    
      
        if(preg_match('`^!cux`', $texte)) {
          $to = str_replace('!cux', '', $texte);
          if(trim($to) != '') {
            $this->sendCux($infos[1], trim($to), $channel);
          }
        }    
      
        if(preg_match('`^!nutella`', $texte)) {
          $to = str_replace('!nutella', '', $texte);
          if(trim($to) != '') {
            $this->sendNutella($infos[1], trim($to), $channel);
          }
        }    

        if(preg_match('`^!tupues`', $texte)) {
          $to = str_replace('!tupues', '', $texte);
          if(trim($to) != '') {
            $this->sendTupues($infos[1], trim($to), $channel);
          }
        }    
      
        if(preg_match('`^!prout`', $texte)) {
          $to = str_replace('!prout', '', $texte);
            $this->sendProut($infos[1], trim($to), $channel);
        }    
      
        if(preg_match('`^!sarko`', $texte)) {
          $to = str_replace('!sarko', '', $texte);
          if(trim($to) != '') {
            $this->sendSarko($infos[1], trim($to), $channel);
          }
        }    

        if(preg_match('`^!donner`', $texte)) {
          $to = str_replace('!donner', '', $texte);
          if(trim($to) != '') {
            while(substr_count($to, '  ')) {
              $to = str_replace('  ', ' ', $to);
            }
            $ex = explode(' ', trim($to));
            if(count($ex) > 1) {
              $to = trim($ex[0]);
              unset($ex[0]);
              $quoi = implode(' ', $ex);
              $this->sendDonner($infos[1], $to, $quoi, $channel);
            }
          }
        }    
            
        if(ereg(' JOIN ', $line) && $infos[1] != $this->cfg_bot['nick']) {
          $this->giveJoinInfos($infos[1]);
        }
    
        
        if( $this->cfg_stats['enable'] ) {
          if(ereg('!stats', $line) && $infos[1] != $this->cfg_bot['nick']) {
            $this->giveStatsUrl($channel);
          }
          if(!$instance) {
            $instance = new BotStats($this->cfg_stats, $this->cfg_server['server'], $this->cfg_channels) ;
          }
          $instance->updateLogs($this->getTime().' '.$line, $channel);
        }    
      }
    }
  }
  
  public function connectBot() {
    parent::__construct($this->cfg_server['server'], $this->cfg_server['port']);
    $this->doConnection();
    $this->botConnection = $this->connection;
    $this->identifyBot();
    $this->joinChannels();

    while (!feof($this->botConnection)) {
      $line = fgets($this->botConnection, 1024);
      $this->analyseLine($line);
    }
  }
  
  
  private function giveJoinInfos($nick) {
    $this->sendIrcMessage('NOTICE '.$nick.' Bienvenue sur le chan de Deblan.fr !'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Simmstein est le seul intervenant pour les reclamations vis a vis de l\'equipe de moderation'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Les regles sont accessibles via !regles'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Retrouves les stats du chan en tappant !stats'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Tapes !help pour avoir la liste des commandes utilisees pour DebStats'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' Amuse-toi bien ;)'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  }
  
  private function giveRegles($nick) {
    $this->sendIrcMessage('NOTICE '.$nick.' Regles du chan irc :'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Pas d\'insultes qui blaissent. Vive le second degre'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Evite le flood'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - En cas de probleme : simon@deblan.fr ou en prive'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Les operateurs font leur taf, ne remet pas en cause leurs sanctions'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  }
  
  private function giveHelp($nick) {
    $this->sendIrcMessage('NOTICE '.$nick.' Liste des commandes utilisees pour DebStats (partie 1) :'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - LE RESTE DES COMMANDES : !help2, !help3, !help4, !help5'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Les regles du chan sont dispos via : !regles'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Retrouver les stats du chan : !stats'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Faire un gros calin : !calin <destinataire>'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Faire des bisous : !bisous <destinataire>'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Fait savoir que tu aimes une personnes... : !love <destinataire>'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  }
  
  private function giveHelp2($nick) {
    $this->sendIrcMessage('NOTICE '.$nick.' Liste des commandes utilisees pour DebStats (partie 2) :'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - LE RESTE DES COMMANDES : !help, !help3, !help4, !help5'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Frapper quelqu\'un (a) : !taloche <destinataire>'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Oh quel ange :o : !ange <destinataire>'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Donner une clope : !clope <destinataire>'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Servir un cafe : !cafe <destinataire>'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Donner quelque chose : !donner <destinataire> <la chose>'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  }

  private function giveHelp3($nick) {
    $this->sendIrcMessage('NOTICE '.$nick.' Liste des commandes utilisees pour DebStats (partie 3) :'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - LE RESTE DES COMMANDES : !help, !help2, !help4, !help5'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Une envie soudaine qu\'il/elle ferme saggle ? : !taggle <destinataire>'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Tu veux bouder quelqu\'un ? : !boude <destinataire>'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Dis lui de se mettre a pwal !! : !apwal <destinataire>'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Paix a son ame... : !ame <destinataire>'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Prepare toi a bucheronner quelqu\'un avec une hache... : !hache <destinataire>'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  }

  private function giveHelp4($nick) {
    $this->sendIrcMessage('NOTICE '.$nick.' Liste des commandes utilisees pour DebStats (partie 4) :'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - LE RESTE DES COMMANDES : !help, !help2, !help3, !help5'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Tu hais quelqu\'un ? : !hate <destinataire>'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Tartiner une personne avec du nutella : !nutella <destinataire>'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Tu veux lui pincer les fesses ? : !cux <destinataire>'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Elle/il pue ? Dis lui  : !tupues <destinataire>'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Arf, tu viens de peter... : !proute'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  }

  private function giveHelp5($nick) {
    $this->sendIrcMessage('NOTICE '.$nick.' Liste des commandes utilisees pour DebStats (partie 5) :'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - LE RESTE DES COMMANDES : !help, !help2, !help3, !help4'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - On a besoin d\'un karcher... : !sarko <destinataire>'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Mais quel boulet... : !boulet <destinataire>'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' - Il l\'a owned :D : !owned <destinataire>'."\r\n");
    $this->sendIrcMessage('NOTICE '.$nick.' -----------------------------------------------------------------------'."\r\n");
  }

  private function giveStatsUrl($channel) {
    $file = $this->cfg_stats['pisg_html_page_dir'].$this->cfg_server['server'].'.'.str_replace('#', '', $channel).'.html';
    if( file_exists($file) ) {
      $ftime = filemtime($file);
      $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'10 Url : http://irc.deblan.fr/stats.php?chan='.$this->cfg_server['server'].'.'.str_replace('#', '', $channel).' - Derniere mise a jour il y a '.$this->bold.date('i', 
time()-$ftime)." minute(s) et ".date('s', time()-$ftime)." seconde(s)\r\n");
    }
  }

  private function giveInfos() {
    $this->sendIrcMessage('PRIVMSG '.$channel.' Je suis le bot qui s\'occupe de generer des logs pour le chan. Merci de ne pas me faire chier !'."\r\n");
  }
  
  private function sendCalin($from, $to, $channel) {
    if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
    else
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 fait un groooOOOooos calin a '.$this->color.'13'.$to.$this->color.'4 <3<3<3<3<3<3<3'."\r\n");
  }
  
  private function sendTaloche($from, $to, $channel) {
    if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
    else
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 balance une grosse taloche dans la gueule a '.$this->color.'13'.$to.$this->color.'4 !!!'."\r\n");

  }  
  
  private function sendHache($from, $to, $channel) {
    if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
    else
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 aiguise sa hache en regardant '.$this->color.'13'.$to.$this->color.'10 tel un bucheron devant un vieux chene...'."\r\n");
  }  
  
  private function sendBisous($from, $to, $channel) {
    if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
    else
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 fait tout plein de gros bisous a '.$this->color.'13'.$to.$this->color.'4 <3<3<3'."\r\n");
  } 
 
  private function sendBoude($from, $to, $channel) {
    if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
    else
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 detourne la tete et boude '.$this->color.'13'.$to.$this->color.'10 =('."\r\n");
  } 
 
  private function sendLove($from, $to, $channel) {
    if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
    else
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$to.$this->color.'10 ? Y\'a '.$this->color.'13'.$from.$this->color.'10 qui t\'aime...'.$this->color.'4 <3<3<3'."\r\n");
  } 
 
  private function sendHate($from, $to, $channel) {
    if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
    else
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$to.$this->color.'10 ? '.$this->color.'13'.$from.$this->color.'10 te fait savoir qu\'il a envie de te pendre avec tes tripes'.$this->color.'4 :@'."\r\n");
  } 
  
  private function sendBoulet($from, $to, $channel) {
    if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
    else
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'10Bordel...'.$this->color.'13'.$to.$this->color.'10...C\'est vraiment qu\'un boulet ><'."\r\n");
  }
  
  private function sendAme($from, $to, $channel) {
    if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
    else
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'10Paix a ton ame '.$this->color.'13'.$to.$this->color.'10...'.$this->bold.$this->color.'1 +'."\r\n");
  } 
  
  private function sendTupues($from, $to, $channel) {
    if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
    else
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$to.$this->color.'10 TUPUES !!!'."\r\n");
  } 
  
  private function sendProut($from, $to, $channel) {
    if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
    else
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 est ignoble, il vient de peter...'.$this->bold.$this->color.'3 :s'."\r\n");
  } 
  
  private function sendNutella($from, $to, $channel) {
    if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
    else
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 tartineuh '.$this->color.'13'.$to.$this->color.'10 avec amoureuh ^^'."\r\n");
  } 
  
  private function sendCux($from, $to, $channel) {
    if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
    else
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 pince les fesses de '.$this->color.'13'.$to.$this->color.'10 Owi !!!'."\r\n");
  }
  
  private function sendClope($from, $to, $channel) {
    if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
    else
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 offre une clope a '.$this->color.'13'.$to."\r\n");
  }   
  
  private function sendSarko($from, $to, $channel) {
    if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
    else
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$to.$this->color.'10, va chercher le karcher...y\'a des racailles ici'."\r\n");
  } 
  
  private function sendCafe($from, $to, $channel) {
    if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
    else
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 sert un bon cafe a '.$this->color.'13'.$to."\r\n");
  }  
  
 
  private function sendAnge($from, $to, $channel) {
    if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
    else
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$to.$this->color.'10 est un vrai ange ^^ '.$this->bold.$this->color.'8O'.$this->color.'7:)'."\r\n");
  } 
  
  private function sendTaggle($from, $to, $channel) {
    if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
    else
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 propose a '.$this->color.'13'.$to.$this->color.'10 de '.$this->color.'4fermer sa grande gueule '.$this->color.'10XD'."\r\n");
  }  
  
  private function sendApwal($from, $to, $channel) {
    if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
    else
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 voudrait bien que '.$this->color.'13'.$to.$this->color.'10 se '.$this->color.'4foutte a APWAL !!! '."\r\n");
  }    
  
  private function sendDonner($from, $to, $quoi, $channel) {
    if(strtolower($from) == strtolower($to)) $this->sendSkyzo($from);
    else
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'13'.$from.$this->color.'10 donne '.$this->color.'4'.$quoi.$this->color.'10 a '.$this->color.'13'.$to."\r\n");
  }
  
  private function sendSkyzo($nick) {
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'10Oh putain !! '.$this->color.'13'.$nick.$this->color.'10 est sckyzo !!'."\r\n");
  }
  
  private function sendOwned($from, $to, $channel) {
    $this->sendIrcMessage('PRIVMSG '.$channel.' '.$this->color.'10Mouahahahahahaha comment il t\'a owned '.$this->color.'13'.$to.$this->color.'10 /o/'."\r\n");
  } 
}

class BotStats extends Bot {
  protected $cfg;
  protected $server;
  private $logs_files_names;
  private $flog_files;
  private $channels = array();
  
  public function __construct($cfg_stats, $server, $channels) {
    $this->flog_files    = array(); 
    $this->logs_files_names = array();  
    $this->channels = $channels;
    $this->server = $server;
    
    try {
      if( $this->canUseBotStats() ) {
         $this->makeConfiguration($cfg_stats);
         $this->make_logs_files_names($channels);
         $this->openLogsFiles();
         
      } else {
        throw new MyException('Impossible d\'utiliser les stats ! Fonction(s) php manquante(s) ou inactive(s)');
      }
    } catch (Exception $e) {
      $e->echoErreur(true);
    }
  }
  
  
  private function makeConfiguration($cfg_stats) {
    $this->cfg = array(
      'log_file_dir'       => '', 
      'max_log_line'       => 1000,
      'pisg_html_page_dir' => '',
      'stats'              => false
    );
    
    foreach($cfg_stats as $key => $_cfg) {
      if(isset( $this->cfg[$key] )) {
        $this->cfg[$key] = $_cfg;
       }
    }
  }
  
  private function canUseBotStats() {
    $possible = true;
    if(!function_exists('fsockopen')) $possible = false;
    if(!function_exists('fwrite'))    $possible = false;
    if(!function_exists('feof'))      $possible = false;
    if(!function_exists('fgets'))     $possible = false;
    return $possible;
  }
  
  private function get_log_file_name($channel) {
    if(isset( $this->cfg[$channel] ) ) {
      return $this->cfg[$channel];
    } else {
      return false;
    }
  }  
  
  private function getNumberLogLine($channel) {
    if(file_exists($this->get_log_file_name($channel))) {
      if(is_readable($this->get_log_file_name($channel))) {
        return count(file($this->get_log_file_name($channel)));
      } else {
        return 0;
      }
    } else {
      return 0;
    }
  }
  
  private function make_logs_files_names() {
    foreach($this->channels as $channel) {
      $this->logs_files_names[$channel] = $this->cfg['log_file_dir'].$this->server.'.'.str_replace(array('"', '#'), '', $channel).'.log';
    }    
  }
  
  private function openLogsFiles() {
    $ok = true;
    foreach( $this->logs_files_names as $file) {
      if( file_exists($file)) {
        if(!is_readable($file)) {
          $erreur.= 'ERREUR : Le fichier de log "'.$file.'" n\'est pas lisible !'."\r\n";
          $ok = false;
        }
      }
    }

    try {
      if(!$ok) {
        throw new MyException($erreur);
      }
    } catch (Exception $e) {
       $e->echoErreur(true);
    }
    try { 
      foreach( $this->logs_files_names as $key => $file) {
        $this->flog_files[$key] = $this->openFile($file);
      }
    } catch (Exception $e) {
      $e->echoErreur(true);
    }
  }  
  
  private function openFile($file) {
    try {
      if(!$open = @fopen($file, 'a+')) {
        throw new MyException('ERREUR : impossible d\'ouvrir : '.$file."\r\n");
      }
      return $open;
    } catch (Exception $e) {
      $e->echoErreur(true);
    }
  }
  
  public function updateLogs($log_line, $channel) {
    try { 
      if(!$write = @fwrite($this->flog_files[$channel], $log_line)) {
        throw new MyException('ERREUR : Impossible d\'ecrire dans le fichier de log ('.$this->get_log_file_name($channel).')'."\r\n");
      }
    } catch (MyException $e) {
      $e->echoErreur(false);
    }
  }  
}

function makeGet() {
  global $argv;
  unset($argv[0]);
  $get = array();
  $c = count($argv);
  if($c > 0) {
    if($c%2 == 0) {
      foreach($argv as $key=>$vl) {
        if($key%2==1) {
          $get[$vl] = $argv[$key+1];
        }
      }
    }
  }
  return $get;
}

$get = makeGet();

$bot = new Bot();

$bot->setConfig('server', 'server', 'deblan.fr');
$bot->setConfig('server', 'port', 6667);
$bot->setConfig('stats', 'enable', true);

if(isset($get['-serveur']))  $bot->setConfig('server', 'server', $get['-serveur']);
if(isset($get['-port']))     $bot->setConfig('server', 'port', $get['-port']);
if(isset($get['-channels'])) $bot->addChannelsToJoin($get['-channels']);

if(isset($get['-nick']))  $bot->setConfig('bot', 'nick', $get['-nick']);
if(isset($get['-host']))  $bot->setConfig('bot', 'host', $get['-host']);
if(isset($get['-mail']))  $bot->setConfig('bot', 'mail', $get['-mail']);

if(isset($get['-log_file_dir'])) $bot->setConfig('stats', 'log_file_dir', $get['-log_file_dir']);
if(isset($get['-max_log_line'])) $bot->setConfig('stats', 'max_log_line', $get['-max_log_line']);
if(isset($get['-pisg_html_page_dir'])) $bot->setConfig('stats', 'pisg_html_page_dir', $get['-pisg_html_page_dir']);

if(isset($get['-enable_stats'])) {
  if($get['-enable_stats'] == 'on') {
    $bot->setConfig('stats', 'enable', true);
  }
  if($get['-enable_stats'] == 'off') {
    $bot->setConfig('stats', 'enable', false);
  }
}

$bot->connectBot();

Conclusion

Évidemment, il est largement améliorable ^^

Critiques constructives demandées (positives ou pas hein :p) ^^
 

Historique

02 juillet 2008 12:15:52 :
- Changement de constructeur - Déclaration des méthodes __set et __get - modification de la méthode ping
02 juillet 2008 12:26:43 :
- Mise ne page
02 juillet 2008 13:26:33 :
- Ajout de la méthode sendNotice
02 juillet 2008 13:28:29 :
None
22 octobre 2008 08:43:21 :
Refonte du code : - class de gestion d'exception - class qui gère la connexion au serveur - class qui gère le bot, ses actions... - class qui gère la partie stats Ce n'est plus de format irc, mais le format brute retournée pas le serveur irc. Encore en phase de test.
22 octobre 2008 18:35:46 :
Correction d'un bug au niveau de l'écriture des stats. Il manquait la date et l'heure.
22 octobre 2008 18:41:40 :
Encore pour l'histoire des dates...

Commentaires et avis

signaler à un administrateur
Commentaire de codefalse le 02/07/2008 10:22:49 administrateur CS

J'aime bien le principe perso, c'est un truc tout simple mais qui est bien pensé :)

Sinon au niveau des remarques, je trouve bizar que ton constructeur propose des variables à modifier tel que server ou port, et pas d'autres, tel que nick, host, mail. C'est incohérent. Par ailleur, en php5 la syntaxe conseillée pour le constructeur est __construct. On garde généralement le nom de la classe en tant que fonction pour les compatibilité descendantes avec les anciennes versions de php mais dans ton cas, l'usage des propriétés public/privée/protegée ne rendront pas ton code compatible avec php4 donc ...

Pour ce qui est des setters et des getters, je te conseille aussi d'utiliser les méthodes magiques __set et __get, et de mettre toutes tes variables "propriétés" dans un tableau, comme ca dans tes setters/getters, tu n'a qu'à tester si l'entrée du tableau existe et agir en conséquence, c'est plus simple.

Parce qu'en fait là tu ne peux modifier que les trois entrées que tu n'a pas pu mettre dans le constructeur. Du coup avec l'idée des méthodes magiques, tu peux tout modifier ou non.

Du coup dans ton constructeur tu ne met que l'essentiel, du genre le serveur, le port, l'host, et éventuellement le nom et l'email du bot. Le reste tu attribue des valeurs prédéfinies.

L'utilisateur pourra modifier ce qu'il veux ensuite grace aux méthodes magiques.

Ensuite j'ai pas regardé attentivement toutes tes méthodes, mais la méthode pong m'interpelle. Tu teste dans analyseLine si la requete est "PING", si oui tu appele la méthode pong qui RE-teste si la requete est PING. Pourquoi le faire deux fois ? tu fait tous tes tests dans analyseLine et dans la méthode pong, tu ne fait que fwrite($this->connexion, 'PONG '.$line[1]);

Ma derniere remarque portera sur quelque chose de plus inutile mais à envisager si tu a le temps et la motivation. C'est au niveau conception POO. Tu définit un instance de Irc_Log, et dans cette instance, tu gère les informations concernant le bot (nom, mail, etc).
Normallement, tu devrait faire une classe IrcBot ou tu indique les informations concernant le bot, que tu passe à une classe Irc (par exemple, qui se chargera de la connection) et tu instancie IrcLog (avec les informations qu'il faut) que tu passera aussi à la classe Irc.
Tu sépare ainsi la gestion de la communication sur le serveur, de ton utilisateur (ici le bot) et d'un service d'enregistrement d'évenement (ici le log). Bon apres ca c'est l'extra bonus ! :)

Courage pour la suite ! :)

signaler à un administrateur
Commentaire de Morphinof le 02/07/2008 10:35:48

C'est simple et efficace, je rajouterai rien CodeFalse à déjà relevé tout ce à quoi j'ai pensé. Ah non ! Il à oublié une petite chose ! :D
try { ... }catch (Exception $e) {
die(...);
}
Comment sa die?? ^^ Tu devrais faire ta propre gestion des exception et enlever ces horribles die ;)
Bonne continuation !

signaler à un administrateur
Commentaire de simonviei le 02/07/2008 11:44:35

J'ai longtemps codé en php4 et j'essaye de tout passer mes script en php5 et comme je suis autodidacte...enfin bref commençons :p :

codefalse :
- Pour le constructeur, je suis débile car en plus je le fais sur d'autres scripts, donc je vais vite corriger ça *se tape sur la main*
- En ce qui concerne les setters/getters, je vais vite me documenter après ce message pour mettre ça en place !
- Pour ping c'est en effet un peu débile...je corrige ça vite aussi :p
- Pour la dernière remarque, je vais voir ce que je peux faire :) Je ne promet rien ^^

Morphinof
- Pourquoi mais j'ai encore des flous dans ma tête concernant les exceptions, j'attends de comprendre à peu plus le sujet pour éventuellement faire ma propre gestion des exceptions :p

/me part coder

Je met à jour le code dès que j'ai convenablement avancé.

signaler à un administrateur
Commentaire de codefalse le 02/07/2008 12:06:51 administrateur CS

De là à dire que tu es "débile", quand même ! :p J'en serai presque à supprimer ton post pour non respect de ... toi même ;)

Si tu passe tes scripts de php4 à 5, c'est forcément sur que tu oublie des choses, tu peux pas penser à tout ! Tes erreurs sont justifiées et ton acte est louable (enfin un qui comprends le fait de ne plus utiliser php4 !).

Tu verra, __get et __set, c'est que du bonheur !

Mes remarques ne sont pas très lourdes, ton code est corrigeable en une heure (sauf la dernière partie).

Bonne recherches :) n'hésite pas si tu bloque

signaler à un administrateur
Commentaire de Morphinof le 02/07/2008 12:16:33

En fait c'est pas très compliqué, comme tu as pu le voir le bloc try{ ... }catch(Exception $e){ ... } est fait pour "attraper" les exceptions qui seraient "jetées" par ton application.
Tu dois identifier les erreurs qui peuvent survenir, pennons l'exemple de ta fonction connexion, une exception évidente serait : on n'as pas réussi à ouvrir notre socket parce que par exemple le serveur n'existe pas ou encore le port est bloqué, il te faudra donc tester le $errno de fsockopen et selon sa valeur tu va jeter une exception correspondant au type d'erreur et tu peu même incorporer dans le message de ton exception $errstr, exemple :

throw new UnknowServerException('Exception : '.$errstr);
throw new PortException('Exception : '.$errstr);
(Ce ne sont que deux rapides exemples)

Bien évidement tu vas devoir créer les classes correspondant aux exceptions en les faisant hériter de la classe Exception et ensuite dès que tu va faire appel à ta fonction connexion c'est la que tu met ton bloc try{}catch(){} :)

Pour une meilleure explication : http://classes.scriptsphp.org/article.PHP-5-et-les-exceptions

signaler à un administrateur
Commentaire de malalam le 02/07/2008 22:32:03 administrateur CS 7/10

Hello,

je ne vais pas redire ce qui a été dit; donc, j'ajouterais juste que je trouve ça pas mal comme code : c'est propre, clair, pas mal codé...pour un  débutant en PHP5, c'est très bien :-)

signaler à un administrateur
Commentaire de simonviei le 22/10/2008 08:49:43

Après avoir ajouté diverses focntion à mon bot, mais qui se trouvaient dans la class Irc_log elle même, j'ai décidé de refaire tout le code :
Une mini gestion des erreurs, une class de connexion, une class pour le bot, une class pour les stats.

J'ai encore des bugs, mais pour l'instant, rien de méchant, je me met dessus cette après midi.

signaler à un administrateur
Commentaire de coucou747 le 23/10/2008 16:02:52 10/10

j'aime bien le concept.

idealement, t'aurais du faire une interface genre IrcReader avec des methodes genre :
OnPrivMsg
OnNotice
etc...

Ajouter un commentaire

Discussions en rapport avec ce code source dans le forum

IRC avec PHP AIDE [ par picsoumax ] Salut j'ai testé le listing de chan avec le source du site mais un petit problème j'ai du male à piger son fonctionnement car il y a peut de commentai Retour session [ par DarkSchneider ] Salut tout le monde.Cette fois, ce sont les sessions qui m'amènent ici. Voilà mon problème. Je dispose de 3 pages, disons index.php, 1.php et 2. phpSu pb avec les sessions. [ par Zebra1928 ] bonjour,plz j'ai besoin d'aide, j'ai 1 vrai pb avec les sessions, je m'explique:j le fichier suivant:log.php&lt;?$host="localhost";$user="root";$passw Futurscripts.com :: Scripts IRC, Php, Javascripts, kits graphiques, tutoriaux... [ par Neoziro ] Si vous cherchez des scripts en php, javascript, IRC et des kits-graphiques mais aussi de nombreux tutoriaux sur le php et photoshop, c'est sur Futurs Affichage de graphique [ par nbenoist ] sur RedHat 7.2 J'ai une page php qui lit un fichier de log. Ma page php me affiche 2 camenbert suivant les informations du fichier log. J'ai mis les Error PHP [ par Dfx4 ] Hello, Voil&#224; j'ai un probl&#232;me sur mon serveur avec Apache et PHP ! J'ai souvent cette erreur et sa me fait plant&#233; mon serveur !!!! // faire un bot en php [ par lunetoile ] salut &#224; tous, j'aimerais r&#233;aliser un bot simple&nbsp;en php &nbsp;mais suis d&#233;butant...j'aimerais qu'il y ai un espace pour parler, et Les sockets php [ par PtitKev ] Bonjour&nbsp;&#224; toutes et a tous.Voila je test un bot socket en php. Je me suis rendu compte que les variables &#233;taient propre a une page donc Requetes sur un forum pour IRC [ par BiGOuF ] Bonjour, Tout d'abord,je voudrais vous dire que je ne vaux rien en PHP, ce qui pourrait expliquer que la question que je vais poser est peut-&#234;tre connection a site [ par deck_bsd ] Bonjour, voila, je n'est pas bcp de connaissances en PHP, mon seul but est de faire un lien vers un site (comme en HTML sauf que ici c'est en php). V


Nos sponsors

Sondage...

CalendriCode

Juillet 2009
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
2728293031  

Consulter la suite du CalendriCode

Téléchargements

Logiciels à télécharger sur le même thème :

Comparez les prix Nouvelle version

Photothèque Nouveau !



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 1,061 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.