Skip to content

Commit

Permalink
Implementation of Upstart script
Browse files Browse the repository at this point in the history
  • Loading branch information
matejvelikonja committed Dec 25, 2012
1 parent ad3ed56 commit 1155380
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Classes/Autoloader.php
Expand Up @@ -33,7 +33,7 @@ class Autoloader {
* @author Daniel Siepmann <coding.layne@me.com>
*/
public static function load( $class ) {
$filename = 'Classes/' . str_replace( '\\', '/', $class ) . '.php';
$filename = __DIR__ . '/' . str_replace( '\\', '/', $class ) . '.php';
if (file_exists($filename)) {
return require $filename;
}
Expand Down
82 changes: 52 additions & 30 deletions README.md
@@ -1,41 +1,63 @@
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.
* !join [#channel] - Joins the specified channel.
* !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
-------
<random-user> !say #wildphp hello there
<wildphp-bot> hello there
<random-user> !poke #wildphp random-user
* wildphp-bot pokes random-user
* !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)
13 changes: 13 additions & 0 deletions 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
22 changes: 13 additions & 9 deletions phpbot404.php
Expand Up @@ -15,16 +15,18 @@
* @author Matej Velikonja <matej@velikonja.si>
*/

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' );
Expand All @@ -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();

Expand Down

0 comments on commit 1155380

Please sign in to comment.