Logo classes.scriptsphp.org PHP

go to nav bar

Bot IRC :: CspBot

  • By :: Fab, Tetsuo, mcAllan
  • Date :: 16-08-2006
  • Version :: 0.3
  • Last Updated :: 15-04-2007

Bot IRC - Les scripts



Introduction

Dans ce chapitre nous allons décrire les principaux scripts de configuration et de lancement du bot.

Le fichier bot.conf.php qui contient tous les paramètres nécessaire au bon fonctionnement du bot.
Ce fichier est à compléter soigneusement avant la première utilisation du bot.
Le fichier bot.php qui est le script d'initialisation et lancement du bot. Celui-ci doit être impérativement lancé en mode batch par le shell bot.sh.


Les scripts :

Fichier de configuration

Pour plus de détails se repporter au chapitre : Configuration

Source :

<?php
/**
 * fichier : bot.conf.php : 
 * Paramètres du BOT
 *
 * @package Cspbot
 * @since 2006/08/10
 * @version 0.3
 * @author Fabrice Lezoray - Tetsuo - Alain Nicolas (mcAllan)
 * @copyright See licence.txt
 * 
 */

    /**
     * Bot operators list
     * @var array botOp
     */
    
$botOp = array('Fab`''Tetsuo''mcAllan''Hebus_');
    
/**
     * IRC Server
     * @global string
     */
    
define('IRC_SERVER''irc.planespells.net');
    
/**
     * IRC Server port
     * @global string
     */
    
define('IRC_PORT''6670');
    
/**
     * IRC Chanel
     * @global string
     */
    
define('IRC_CHAN''csp');
    
/**
     * User IP
     * @global string
     */
    
define('MY_IP','127.0.0.1');
    
/**
     * User domain
     * @global string
     */
    
define('MY_DOMAIN''scriptsphp.net');
    
/**
     * User email
     * @global string
     */
    
define('MY_EMAIL''mcallan@csp.org');
    
/**
     * Bot user name
     * @global string
     */
    
define('BOT_UNAME''CspBot');
    
/**
     * Bot Nick
     * @global string
     */
    
define('BOT_NICK''CspBot_03');
    
/**
     * Bot password
     * @global string
     */
    
define('BOT_PWD''glopidou');
    
/**
     * Bot version
     * @global string
     */
    
define('BOT_VERSION''0.3');
    
/**
     * Set chan's logs on/off
     * @global boolean logChan
     */
    
define('LOG_CHAN'TRUE);
    
/**
     * Set bot's logs on/off
     * @global boolean logBot
     */
    
define('LOG_BOT'TRUE);
    
/**
     * Set chan's ststs on/off
     * @global boolean stat_chan
     */
    
define('STAT_CHAN'TRUE);
    
/**
     * Logs directory must end by /
     * @global log_dir
     **/
    
define('LOG_DIR''logs/');
    
/**
     * Set message on join (left empty for no mess.)
     * @global string joinMess
     */
    
define('JOIN_MESS''glop glop');
    
/**
     * Set message on quit (left empty for no mess.)
     * @global string quitMess
     */
    
define('QUIT_MESS''glop pas-glop');
    
    
// MySql Login if necessary for some pluggins
    
    /**
     * MySql Host if used by Pluggin
     * @global string
     */
    
define('MYSQL_HOST' '');
    
/**
     * MySql User if used by Pluggin
     * @global string
     */
    
define('MYSQL_USER' '');
    
/**
     * MySql password if used by Pluggin
     * @global string
     */
    
define('MYSQL_PWD' '');
    
/**
     * MySql DataBase if used by Pluggin
     * @global string
     */
    
define('MYSQL_BASE' '');
    





?>

go to the top

Script bot.php

Dans ce script, on retrouve les deux fonctions d'auto-chargement des classes.
Une instance de la classe IRCMain est créée, ensuite tous les plugins sont initialisés, enfin, le bot est lancé.

Source :

<?php 
/**
 * fichier : bot.php : 
 * Script principal
 *
 * @package Cspbot
 * @since 2006/08/10
 * @version 0.3
 * @author Fabrice Lezoray - Tetsuo - Alain Nicolas (mcAllan)
 * @copyright See licence.txt
 * 
 */

function __autoload($class) {
    
$file1 './classes/class.'.$class.'.php';
    if(
is_readable($file1)) {
        include_once 
$file1;
    }
    
$plugin './plugin/'.$class.'/plug.php';
    if(
is_readable($plugin)) {
        include_once 
$plugin;
    }
}

if(!isset(
$argv)) {
    die (
'Only batch running');
}


require_once(
'./include/bot.conf.php');

# ---------------------------
# Instanciation du bot
# ---------------------------
$MainProc = new IRCMain($server IRC_SERVER$port IRC_PORT$chan '#'.IRC_CHAN$name BOT_NICKMY_IPMY_DOMAIN);

# ---------------------------
# Chargement liste des op autorisés
# ---------------------------
$MainProc -> setOpList($botOp);

# ---------------------------
# Chargement des plugins
# ---------------------------
$MainProc->loadPlugs();

# ---------------------------
# Démarrage du bot
# ---------------------------
$MainProc->run();

?>

go to the top

Le shell de lancement

Le shell tourne en boucle infinie afin de relancer le bot si celui-ci est tué accidentellement.
Sur certains serveurs, il sera nécessaire de préciser le chemin du PHP_CLIENT.
D'autre part, il est impératif d'indiquer le bon chemin vers bot.php.

Source :

#!/bin/sh
#
# fichier : bot.sh :
# Shell de lancement du Bot
#
# @package Cspbot
# @since 2006/08/10
# @version 0.3
# @author Fabrice Lezoray - Tetsuo - Alain Nicolas (mcAllan)
# @copyright See licence.txt

# Chemin vers le client PHP5
# A vérifier impérativement

#Exemple 1
#PHP5_CLI=/usr/bin/php5

#Exemple 2
#PHP5_CLI=/usr/local/php5/bin/php

#Exemple 3
PHP5_CLI=php

#
# boucle infinie qui relance le script si il est tué
while [ 1 ] ; do

$PHP5_CLI -f /chemin_vers/bot.php

done
#

go to the top

Merci de ne pas suivre ce lien emails.

0.2881s | «»
PHP powered