View on GitHub

Anonymousv2

Anonymous V2

Download this project as a .zip file Download this project as a tar.gz file

Introduction

Anonymous is an IRC bot.

Current To Do list

Commands

Other Features

Plenty other features and commands left to move, but this is the current GitHub issue list, the GitHub issue list will be added to once all current issues are completed.

Suggestions

Please posts suggestions on KCNR's forums

Bugs

Please report bugs on KCNR's forums.

Module example

<?php
/**
 * Function: addModule
 * Required Parameter: modulename - Must be equal to Classname and filename.
 * Optional Parameter: IRC Events to attach to - Insert null if not needed.
 * Optional Parameter: IRC Commands - Insert null if not needed.
 * Optional Parameter: Ingame Commands - Insert Null if not needed.
 * Optional Parameter: Ingame Words - Insert null if not needed. Looks for specific word in specific position in IRC Messages it receives.
 */
addModule('TestModule',['PRIVMSG','ON_CONNECT'],['test' => ['trigger' => '!','level' => 0, 'help' => "First command."]],['test' => ['trigger' => '&', 'level' => 0, 'help' => "First Ingame Command"]], ['robbery' => ['position' => 3]]);

/**
 * Class name, class should extend AbstractObserver
 */
class TestModule extends AbstractObserver {
    /**
     * Variable instantation, the comments above the variables are for autocomplete in the IDE.
     */

    /** @var Logger $logger */
    private $logger;
    /**@var AbstractSubject|IrcMessageStringHandler|IrcMessageNumericHandler $subject*/
    private $subject;
    /**@var IRC $irc*/
    private $irc;

    /**
     * Constructor, set the logger and IRC variable here.
     *
     * @param $irc
     */
    public function TestModule($irc) {
        global $logger;
        $this->logger = $logger;
        $this->irc = $irc;
    }

    /** This function is called when data changes elsewhere. E.g. commands/events.
     *
     * @param AbstractSubject $subject_in
     * @param                 $hook
     */
    function update(AbstractSubject $subject_in, $hook) {
        $this->subject = $subject_in;

        /**
         * Switch between the different values that $hook can have.
        */
        switch($hook) {
            case "PRIVMSG":
                /**
                 * If $hook is PRIVMSG, execute the function on_privmsg();.
                 */
                $this->on_privmsg();
                break;
            case "ON_CONNECT":
                /**
                 * if $hook is ON_CONNECT, execute the function on_connect();.
                 */
                $this->on_connect();
                break;
            case "IRC_TEST":
                /**
                 * if $hook is TEST (which is a command), execute the function command();.
                 */
                $this->command();
                break;
            case "IG_TEST":
                /**
                 * if $hook is TEST (which is a command), execute the function command();.
                 */
                $this->command();
                break;
            case "robbery":
                $this->onFindRobbery();
                break;
        }
    }
    /**
     * on_privmsg implementation. Get the object and then send a message to IRC.
    */
    private function on_privmsg() {
        /**@var IrcMessage $ircobject*/
        $ircobject = $this->subject->getPrivmsgobject();
        //$this->irc->irc_say($ircobject->getChannel(),$ircobject->getMessage());
    }
    /**
     * on_connect implementation, log that the on_connect hook works fine.
    */
    private function on_connect() {
        /**@var DB $db*/
        global $db;
        $this->logger->log("On_connect hook works.");

        /**
         * Finding data from database table, creating row in database, change data in database and remove data in database.
         */
        $db->find("stats",['what','text'],[['rowid' => ['operator' => '=', 'check' => '1']], ['rowid' => ['operator' => 'OR', 'comparison' => '=', 'check' => '2']]],['rowid' => 'ASC'], ['start' => 0, 'stop' => 10]);
        $db->create("test",["id","name"],["1","test"]);
        $db->change("test",["name"],["name" => "test2"],[['id' => ['operator' => '=', 'check' => '1']]]);
        $db->remove("test",[['id' => ['operator' => '=', 'check' => '1']]]);
    }
    /**
     * command implementation, because test is used for both ingame and irc command, we check which one it really is.
    */
    private function command() {
        /**
         * Retrieve the object containing the data for the IRC Command.
         * @var IrcCmdMessage $ircobject
         */
        $ircobject = $this->subject->getIrccmdobject("test");
        /**
         * Retrieve the object containing the data for the Ingame Command.
         * @var IgCmdMessage $igobject
         */
        $igobject = $this->subject->getIgcmdobject("test");
        /**
         * If it's the one used from IRC, we send a message with "Command executed." to IRC.
        */
        if(!is_null($ircobject)) {
            $this->irc->irc_say($ircobject->getChannel(), "Command executed.");
        }
        /**
         * If it's the one used from ingame, we send a message with all kinds of information to IRC.
         */
        if(!is_null($igobject)) {
            $this->irc->irc_say($igobject->getChannel(), $igobject->getUser()." ".$igobject->getClass()." ".$igobject->getUid()." ".$igobject->getCmd()." - ".implode(" ",$igobject->getMessage()));
        }
    }

    /**
     * On find word implementation, shows a message on IRC when that specific word is found.
     */
    private function onFindRobbery() {
        /**
         * Retrieve the object containing the data for the Ingame Command.
         * @var IrcMessage $igobject
         */
        $igobject = $this->subject->getIngameWordFoundobject();
        $this->irc->irc_say($igobject->getChannel(),$igobject->getMessage()." - Reply from onFindRobbery().");

    }
}

?>