Skip to first unread message

D

unread,
Sep 16, 2016, 7:23:57 AM9/16/16
to AJAX-chat
Hi,
I was wondering how I would go about adding custom commands such as:
When I type /me it would show up in chat as (Username Bot:)
I would also like if possible to use this script to make variations of the command such as when I type: /(something) It will come up as whatever Ive programmed the command to say. 
Im only a Beginner to Intermediate programmer so Try and keep it as simple as possible. 
Thanks

Banjo Fox

unread,
Sep 16, 2016, 9:49:05 AM9/16/16
to AJAX-chat
Hi D,

Custom commands can be added to the lib/class/CustomAJAXChat.php file.

All of the overrides need to go BETWEEN

class CustomAJAXChat extends AJAXChat {

and the closing bracket at the bottom of the file

}

The block of code below is what I have on my site. It adds the /away /online functionality from the GitHub Wiki, as well as some custom commands /slap and /status.
If you look at /slap and /status I think that will get you closer to what you are looking for.


    // This is where we can start adding custom commands
    function parseCustomCommands($text, $textParts) {
        switch($textParts[0]) {
        // Away from keyboard message:
        case '/away':
            $this->insertChatBotMessage($this->getChannel(), $this->getLoginUserName().' has set their status to Away');
            $this->setUserName($this->getLoginUserName().'[Away]');
            $this->updateOnlineList();
            $this->addInfoMessage($this->getUserName(), 'userName');
            return true;
        case '/online':
        case '/back':
            $this->insertChatBotMessage($this->getChannel(), $this->getLoginUserName().' has set their status to Online');
            $this->setUserName($this->getLoginUserName());
            $this->updateOnlineList();
            $this->addInfoMessage($this->getUserName(), 'userName');
            return true;
        case '/trout':
        case '/slap':
        $this->insertChatBotMessage($this->getChannel(), $this->getLoginUserName().' slaps '.implode(' ', array_slice($textParts, 1)).' with a wet trout');
            return true;
        case '/status':
            $this->insertChatBotMessage($this->getChannel(), $this->getLoginUserName().' has set their status to '.implode(' ', array_slice($textParts, 1)));
            $this->setUserName($this->getLoginUserName().'['.implode(' ', array_slice($textParts, 1)).']');
            $this->updateOnlineList();
            $this->addInfoMessage($this->getUserName(), 'userName');
            return true;


        } // End of switch
    } // End of parseCustomCommands
Reply all
Reply to author
Forward
0 new messages