super3 / IRC-Bot

A very little basic IRCBot that will get improved over the next time.
http://www.wildphp.com
102 stars 47 forks source link

Database Implementation #23

Open ShadowMage121 opened 11 years ago

ShadowMage121 commented 11 years ago

A database implementation would be nice to have for if the bot sits in multiple channelse and other various things.

super3 commented 11 years ago

Issue #22 Includes some of our discussion about logged features. Right now the current goal is to get raw text file logging first, and then add database logging later. When we do go about implementing database logging, is there any particular one you would be interested in?

FutileFreedom commented 11 years ago

For me, this wouldn't be for logging purposes. I tend to manage channels in an access-list sort of way. So just a wrapper for accessing in commands to check say, if they have access to even use the command, or are allowed into a channel. Also good for giving auto-operator, voice etc if someone doesn't know how to do so via XOP

super3 commented 11 years ago

What both of you are suggesting falls more under the feature sets rather than, pure database. You want the ability to add custom permission and settings for a bot. We could use something like a flatfile database to be able to store this information without adding the additional dependence of a real database(ie we want you to be able just to run the script).

I had made some progress on rough drafting a web admin panel in the web-exp branch. This would allow you to do the features you listed above.

Any ideas on how to specifically implement this, and what we should focus on first would be appreciated.

FutileFreedom commented 11 years ago

I originally made this on the wrong account. No clue why I have that other one. Use a config option as to whether or not use the database. If the config option is not true, or yes, then use flatfile.

oliveratgithub commented 9 years ago

This is how I added DB-support to the PHP IRC-Bot (it's a dirty hack, but works):

1) In config.php I defined new variables for my MySQL connection:

return array(
//[...]
    'db_server'      => 'localhost',
    'db_name'        => 'mydatabase',
    'db_user'        => 'root',
    'db_pass'        => 'root',
//[...]

2) In a custom Command.php, I was now able establishing a MySQL-connection using these config-vars as follows:

public function command() {
    if(!$db = mysqli_connect(
        $this->bot->db_server,
        $this->bot->db_user,
        $this->bot->db_pass,
        $this->bot->db_name)
    ){
        die('Unable to connect to database');
    } else {
        // do all the DB-queries and stuff here
        mysqli_close($db);
    }
}

3) Alternatively I think one can also simply include the (existing) MySQL-Class via the "config.php" like

require_once('../includes/mysql.inc.php');

There are far better ways, I am sure. I.e. copying a MySQL-Handler Class to the root of the "Classes/" directory?

NanoSector commented 9 years ago

Just some food for thought, if we are going to be logging everything to a database server, we should probably buffer the incoming entries in some way because in a busy channel this could otherwise lead to high I/O and possibly massive lag on the bots side. For settings and such it shouldn't be a problem.

I could work on a simple abstraction layer and a layer for MySQLi, if needed.