Skip to content
Olli edited this page Mar 1, 2022 · 3 revisions

This modification adds the command /takeover which allows users (or only admins and mods) to make the chatbot say things.
Open lib/class/customAJAXChat.php
Before the last } add the following code:

// Add custom commands
function parseCustomCommands($text, $textParts) {
    switch($textParts[0]) {
        case '/takeover':
        $this->insertChatBotMessage( $this->getChannel(), $textParts[1] );
        return true;
        default:
        return false;
    }
}

Open js/custom.js and add this to the end of the file:

ajaxChat.replaceCustomCommands = function(text, textParts) {
	switch(textParts[0]) {
		case '/takeover':
		text=text.replace('/takeover', ' ');
		return '<span class="chatBotMessage">' + textParts[1] + '</span>';
		default:
		return text;
	}
}

This will give all users the ability to use the /takeover command.

Allow for Admins and Moderators Only

If you want to only allow this command for administrators and moderators, you should put the following in customAJAXChat.php instead of the first part of the code provided above. Notice that there is an added "if" statement:

// Add custom commands
function parseCustomCommands($text, $textParts) {
	if($this->getUserRole() == AJAX_CHAT_ADMIN || $this->getUserRole() == AJAX_CHAT_MODERATOR) {
		switch($textParts[0]) {
			case '/takeover':
			$this->insertChatBotMessage( $this->getChannel(), $textParts[1] );
			return true;
			default:
			return false;
		}
	}
}

Thank you to KID52 for help with this mod

Make the Messages Global

If you want to make the takeover command appear for everyone in all chat rooms (not just the one you're in) you can use this modified version provided by FireWire. Do the same modification to js/custom.js as described above, but use this inside lib/class/customAJAXChat.php

// Add custom commands
function parseCustomCommands($text, $textParts) {
    if($this->getUserRole() == AJAX_CHAT_ADMIN) {
        switch($textParts[0]) {
            case '/takeover':
                // send the message to everyone!
                unset($userID);
                unset($privateMessageID);
                foreach($this->getOnlineUserIDs() as $userID) {
                    $privateMessageID = $userID + $this->getConfig('privateMessageDiff');
                    $this->insertChatBotMessage($privateMessageID, $textParts[1]);
                }
                unset($userID);
                unset($privateMessageID);
            return true;
            default:
            return false;
        }
    }
}