Accueil > > > BOT IRC : GÉNÉRATEURS DE LOGS AU FORMAT MIRC
BOT IRC : GÉNÉRATEURS DE LOGS AU FORMAT MIRC
Information sur la source
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...
Sources de la même categorie
Commentaires et avis
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<?$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à j'ai un problème sur mon serveur avec Apache et PHP ! J'ai souvent cette erreur et sa me fait planté mon serveur !!!! //
faire un bot en php [ par lunetoile ]
salut à tous, j'aimerais réaliser un bot simple en php mais suis débutant...j'aimerais qu'il y ai un espace pour parler, et
Les sockets php [ par PtitKev ]
Bonjour à toutes et a tous.Voila je test un bot socket en php. Je me suis rendu compte que les variables é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-ê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
|
Derniers Blogs
GESTION D'EXCEPTION AVEC LES TASKSGESTION D'EXCEPTION AVEC LES TASKS par richardc
Nous avons vu dans un précédent article comment utiliser Task pour effectuer des opérations dans un autre thread.
Malheureusement, comme tout le monde n'est pas parfait, il se peut que cette exécution se passe mal et qu'une exception se produise.
La...
Cliquez pour lire la suite de l'article par richardc DéMARRONS AVEC LES TASKSDéMARRONS AVEC LES TASKS par richardc
Que vous le vouliez ou non, le développement multi-tâche est maintenant une obligation pour toute nouvelle application. Il est donc vital d'en comprendre les mécanismes et de s'y mettre le plus tôt possible.
En attendant le .NET Framework 4.5 avec le...
Cliquez pour lire la suite de l'article par richardc SLIDE & DéMO TECHDAYS 2012 - FAST & FURIOUS XAML APPSSLIDE & DéMO TECHDAYS 2012 - FAST & FURIOUS XAML APPS par Vko
Retrouvez les slides et les démo de ma session Fast & Furious XAML Apps. A ceux qui se posent la question : "est-ce que le code de la DataGrid est disponible?", je vous répondrais "pas encore". Je vais mettre en place un projet codeplex pour part...
Cliquez pour lire la suite de l'article par Vko XNA IS DEAD!XNA IS DEAD! par richardc
Depuis la semaine dernière (et grâce aux TechDays 2012), je me penche activement sur la nouvelle version de Windows, aka Windows 8. Vous me direz, il était temps puisque la première preview date de Septembre dernier.
OK. Remarquez, on n'en est qu'aux...
Cliquez pour lire la suite de l'article par richardc TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 !TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 ! par ROMELARD Fabrice
Speakers: Fabrice Meillon et Stanislas Quastana Cette session est basée entièrement sur celle donnée lors de la BUILD cet hiver. Il n'y a pas d'ajout d'information en rapport avec cet évènement passé. Windows 8 Server sera intégralem...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|