Skip to content
Philip Nicolcev edited this page Jan 7, 2014 · 4 revisions

There are currently two versions of the away (afk) command created as modifications for AJAX Chat. Both versions allow users to type the command "/afk" and will change their name in the chat list to indicate this status by adding a tag of some kind.

Version 1: Automatically remove status.
This version will remove the afk status of a user the next time the user types a message (or private message).
Open lib/class/CustomAJAXChat.php and add the following before the last closing bracket } at the end of the file:

function parseCustomCommands($text, $textParts) {
	switch($textParts[0]) {
		// Away from keyboard message:
		case '/afk':
			// Set the userName:
			$this->setUserName('<AFK>_'.$this->getUserName());
			// Update the online user table:
			$this->updateOnlineList();
			// Add info message to update the client-side stored userName:
			$this->addInfoMessage($this->getUserName(), 'userName');
			// Store AFK status as session variable:
			$this->setSessionVar('AwayFromKeyboard', true);
			return true;
		default:
			return false;
	}
}

function onNewMessage($text) {
	// Reset AFK status on first inserted message:
	if($this->getSessionVar('AwayFromKeyboard')) {
		$this->setUserName($this->subString($this->getUserName(), 6));
		$this->updateOnlineList();
		$this->addInfoMessage($this->getUserName(), 'userName');
		$this->setSessionVar('AwayFromKeyboard', false);
	}
	return true;
}

Version 2: Wait for /online.

This version will remove the afk status of a user only when the user types /online.

Open lib/class/CustomAJAXChat.php and add the following inside the function parseCustomCommands:

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':
		$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;

Credit for the second version to KID52.