From 1155380d9ec792635285938f1cc0f9c6ab974359 Mon Sep 17 00:00:00 2001 From: Matej Velikonja Date: Tue, 25 Dec 2012 17:09:09 +0100 Subject: [PATCH] Implementation of Upstart script --- Classes/Autoloader.php | 2 +- README.md | 82 ++++++++++++++++++++++++++---------------- bin/phpbot404.conf | 13 +++++++ phpbot404.php | 22 +++++++----- 4 files changed, 79 insertions(+), 40 deletions(-) create mode 100644 bin/phpbot404.conf diff --git a/Classes/Autoloader.php b/Classes/Autoloader.php index f25fe45..fc227f7 100644 --- a/Classes/Autoloader.php +++ b/Classes/Autoloader.php @@ -33,7 +33,7 @@ class Autoloader { * @author Daniel Siepmann */ public static function load( $class ) { - $filename = 'Classes/' . str_replace( '\\', '/', $class ) . '.php'; + $filename = __DIR__ . '/' . str_replace( '\\', '/', $class ) . '.php'; if (file_exists($filename)) { return require $filename; } diff --git a/README.md b/README.md index d3a0486..2686ef7 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,19 @@ -IRC-BOT -============= -A basic IRC Bot built in PHP (using sockets) with wonderful OOP. +# PHP BOT 404 +A IRC Bot built in PHP (using sockets) with OOP. Designed to run off a local LAMP, WAMP, or MAMP stack. +With a custom [Upstart](http://upstart.ubuntu.com/) script to run as Linux daemon. -Web -------- -* [Our Official Website](http://wildphp.com) -* [The Source Code](https://github.com/pogosheep/IRC-Bot) +## Web +* [Source] (https://github.com/matejvelikonja/IRC-Bot-404) -Collaborators -------- -* [Super3](http://super3.org) - Frontend -* [Pogosheep](https://plus.google.com/108868126361135455230/about) - Backend +## Features and Functions + +### Commands + +* !weather [location] - Returns weather data for location +* !joke - Returns random joke. Fetched from [ICNDb.com](http://www.icndb.com/). +* !ip - Returns IP of a user. -Features and Functions -------- * !say [#channel] [message] - Says message in the specified IRC channel. * !say [username] [message] - Says message in the specified IRC user. * !poke [#channel] [username] - Pokes the specified IRC user. @@ -22,20 +21,43 @@ Features and Functions * !part [#channel] - Parts the specified channel. * !timeout [seconds] - Bot leaves for the specified number of seconds. * !restart - Quits and restarts the script. -* !quit - Quits and stops the script. - -Install and Run -------- -1. Place the IRC-Bot folder in your server directory or htdocs. -2. Create or edit a config file with your details - (layne_bot.php and wild_bot.php are two working examples). -3. Open your config file in your browser, or a command line. -4. The bot will run as long as the command line or browser is open. -5. Have fun! - -Sample Usage and Output -------- - !say #wildphp hello there - hello there - !poke #wildphp random-user - * wildphp-bot pokes random-user \ No newline at end of file +* !quit - Quits and stops the script. + +### Listeners + +Implements listener, that listen to changes in channels. + +* Joins - greets users when they join the channel. + +## Install + +### Config + +Copy configuration file and customize its content. + + cp config.php config.local.php + +Copy Upstart script to folder and make appropriate changes. + + sudo cp bin/phpbot404.conf /etc/init/ + +### Run + +Run as PHP + + php phpbot404.php + +or Upstart service + + start phpbot404 + +Restart + + restart phpbot404 + +Stop + + stop phpbot404 + +## Forked from + [Pogosheep/IRC-BOT](https://github.com/pogosheep/IRC-Bot) \ No newline at end of file diff --git a/bin/phpbot404.conf b/bin/phpbot404.conf new file mode 100644 index 0000000..f08f607 --- /dev/null +++ b/bin/phpbot404.conf @@ -0,0 +1,13 @@ +env USER="www-data" +env SCRIPT_DIR="/var/www/private/IRC-Bot-404" +env LOG_FILE="/var/log/phpbot404.log" + +description "PHP Bot 404 startup script" +author "matejvelikonja" + +start on startup +stop on shutdown + +script + exec /usr/bin/sudo -u $USER /usr/bin/php $SCRIPT_DIR/phpbot404.php >> $LOG_FILE +end script \ No newline at end of file diff --git a/phpbot404.php b/phpbot404.php index b7637fc..e9795cf 100644 --- a/phpbot404.php +++ b/phpbot404.php @@ -15,16 +15,18 @@ * @author Matej Velikonja */ + define('ROOT_DIR', __DIR__); + // Configure PHP //ini_set( 'display_errors', 'on' ); // Make autoload working require 'Classes/Autoloader.php'; - if (file_exists('config.local.php')) { - $config = include_once('config.local.php'); + if (file_exists(ROOT_DIR . '/config.local.php')) { + $config = include_once(ROOT_DIR . '/config.local.php'); } else { - $config = include_once('config.php'); + $config = include_once(ROOT_DIR . '/config.php'); } spl_autoload_register( 'Autoloader::load' ); @@ -50,14 +52,16 @@ $bot->addCommand($command); } - foreach ($config['listeners'] as $listenerName => $args) { - $reflector = new ReflectionClass($listenerName); - - $listener = $reflector->newInstanceArgs($args); - - $bot->addListener($listener); + foreach ($config['listeners'] as $listenerName => $args) { + $reflector = new ReflectionClass($listenerName); + + $listener = $reflector->newInstanceArgs($args); + + $bot->addListener($listener); } + + // Connect to the server. $bot->connectToServer();