12.04.2010, 09:29
==========================================
CoolioBot v 0.1.0 - coded by Matthias Van Eeghem
==========================================
1. Introduction
First off, if you're not familiar with either PHP, MySQL(i) or IRC, I don't recommend this IRC Bot. This IRC Bot is coded in PHP, using a MySQL database and MySQLi to query the database.
A friend of mine, TransporterX made a PHP bot, gave the source to me and let me edit it. I wasn't very good at PHP back then and I learned a lot. Now, about 7 months later, I look at the source of the bot (which works fine) and find it very messy. No comments, stuff that could be done a lot better and it used MySQL.
So I decided to start writing my own bot from scratch.
2. Features
Main features of the bot are:
3. Installation
>> If you're running phpMyAdmin, don't do step 8 and 9 and go to the bottom of this guide.
1. Get a webserver to host the bot on, or download XAMPP
(Note: On free webhosts, you're mostly not allowed to run these kinds of PHP bots)
2. Install PHP
3. Install MySQL
4. Install MySQLi
5. Edit Config.php (the configuration array and the MySQL details).
6. Open Core.php, go to line 130 and edit the channels.
7. Upload all the files to the server.
8. Create the database tables, executing these queries on your database:
9. Run the PHP bot (start CoolioBot.php)
10. (Optional) Add these commands to the command database to make it a little bit easier for you. You can insert these commands using phpMyAdmin or manually make the queries. Note: Edit the MySQL details in the commands!
addcmd:
CoolioBot v 0.1.0 - coded by Matthias Van Eeghem
==========================================
1. Introduction
First off, if you're not familiar with either PHP, MySQL(i) or IRC, I don't recommend this IRC Bot. This IRC Bot is coded in PHP, using a MySQL database and MySQLi to query the database.
A friend of mine, TransporterX made a PHP bot, gave the source to me and let me edit it. I wasn't very good at PHP back then and I learned a lot. Now, about 7 months later, I look at the source of the bot (which works fine) and find it very messy. No comments, stuff that could be done a lot better and it used MySQL.
So I decided to start writing my own bot from scratch.
2. Features
Main features of the bot are:
- MySQL command database.
- Using MySQLi
- Commented everywhere
- Easy to edit the source
- Easy to add/delete commands while running
3. Installation
>> If you're running phpMyAdmin, don't do step 8 and 9 and go to the bottom of this guide.
1. Get a webserver to host the bot on, or download XAMPP
(Note: On free webhosts, you're mostly not allowed to run these kinds of PHP bots)
2. Install PHP
3. Install MySQL
4. Install MySQLi
5. Edit Config.php (the configuration array and the MySQL details).
6. Open Core.php, go to line 130 and edit the channels.
7. Upload all the files to the server.
8. Create the database tables, executing these queries on your database:
Код:
$query = "CREATE TABLE users ( id int(11) not null auto_increment primary key, user varchar(256) not null unique, access tinyint(3) not null default 0)";
Код:
$query = "CREATE TABLE commands ( id int(11) not null auto_increment primary key, command varchar(20) not null unique, code text, access tinyint(3) not null default 0)";
10. (Optional) Add these commands to the command database to make it a little bit easier for you. You can insert these commands using phpMyAdmin or manually make the queries. Note: Edit the MySQL details in the commands!
addcmd:
Код:
$text = explode(' ',$params,3); $MySQLi = new mysqli('localhost', root 'mypass', 'mydb'); if(!strlen($text[2])) return $this->Send("PRIVMSG $target 3Usage: !addcmd [command] [access]delcmd:Код:"); if($this->CommandExist($text[0]) == 1) return $this->Send("PRIVMSG $target 4Error: Command already exists!"); $sCommand = $MySQLi->real_escape_string($text[0]); $iAccess = $MySQLi->real_escape_string($text[1]); $sCode = $MySQLi->real_escape_string($text[2]); $sQuery = "INSERT INTO commands (command, access, code) VALUES ('$sCommand', '$iAcccess', '$sCode')"; $MySQLi->query($sQuery); $this->Send("PRIVMSG $target 3Succes: command added.");
adduser:Код:if(!strlen($params)) return $this->Send("PRIVMSG $target 3Usage: !delcmd [command]"); if($this->CommandExist(trim($params)) == 0) return $this->Send("PRIVMSG $target 4Error: Command doesn't exist!"); $MySQLi = new mysqli('localhost', root 'mypass', 'mydb'); $params = $MySQLi->real_escape_string(trim($params)); $sQuery = "DELETE FROM commands WHERE command = '$params'"; $MySQLi->query($sQuery); $this->Send("PRIVMSG $target 3Succes: command removed.");
deluser:Код:$param = explode(' ', $params, 2); if(!strlen($param[1])) return $this->Send("PRIVMSG $target 3Usage: !adduser [nick!ident@host] [access]"); if($this->UserExist($param[0])) return $this->Send("PRIVMSG $target 4Error: User already exists!"); $this->SaveAccess($param[0], $param[1]); $this->Send("PRIVMSG $target 3Succes: user saved.");
setcmdlevel:Код:if(!strlen($params)) return $this->Send("PRIVMSG $target 3Usage: !deluser [nick!ident@host]"); if($this->UserExist($params) == 0) return $this->Send("PRIVMSG $target 4Error: User doesn't exist!"); $MySQLi = new mysqli('localhost', root 'mypass', 'mydb'); $params = $MySQLi->real_escape_string($params); $params = sha1($params); $sQuery = "DELETE FROM users WHERE user = '$params'"; $MySQLi->query($sQuery); $this->Send("PRIVMSG $target 3Succes: user removed.");
>> This only works when running phpMyAdmin!Код:$text = explode('' '',$params, 2); $MySQLi = new mysqli(''localhost'', ''mydb'', ''mypass'', ''mydb''); if(!strlen($text[1])) return $this->Send("PRIVMSG $target 3Usage: !setcmdlevel [command] [access]"); if($this->CommandExist($text[0]) == 0) return $this->Send("PRIVMSG $target 4Error: Command doesn''t exist!"); $sCommand = $MySQLi->real_escape_string($text[0]); $iAccess = $MySQLi->real_escape_string($text[1]); $sQuery = "UPDATE commands SET access = ''$iAccess'' WHERE command = ''$sCommand''"; $MySQLi->query($sQuery); $this->Send("PRIVMSG $target 3Succes: command level updated.");
- Open up CoolioBot.sql
- Search for (ctrl + h) localhost, and edit it so it's your MySQL server.
- Search for (ctrl + h) root, and edit it so it's your MySQL user.
- Search for (ctrl + h) mypass, and edit it so it's your MySQL pass.
- Search for (ctrl + h) mydb, and edit it so it's your MySQL database.
- import CoolioBot.sql into your database. This wil automatically create the correct tables and insert the 5 above commands.
4. Download
http://files.uploadffs.com/a/c/0ab4ce5a/CoolioBot.zip
http://rapidshare.com/files/37494396...ioBot.zip.html
5. Changelog
12/04/10
- Initial release.
6. Credits
This bot has been entirely coded by me, Matthias. I'd like to thank Wesley Lancel for hosting the bot and helping me learn PHP the past few months.