Skip to content

Mod channel descriptions

Philip Nicolcev edited this page Jul 1, 2014 · 3 revisions

Add the following code to the end of js/custom.js and then reload your chat.

Of course, you can replace "Welcome to channel x" with whatever you want and you can add as many channels as you want by using the same format.
The channelIDs will depend on your installation. You can put html code in the channel messages.

//Override the handleInfoMessage function for welcome messages
ajaxChat.handleInfoMessage = function(infoType, infoData) {
	switch(infoType) {
		case 'channelSwitch':
			this.clearChatList();
			this.clearOnlineUsersList();
			this.setSelectedChannel(infoData);
			this.channelName = infoData;
			this.channelSwitch = true;
			break;
		case 'channelName':
			this.setSelectedChannel(infoData);
			this.channelName = infoData;
			break;
		case 'channelID':
			this.channelID = infoData;
			//Welcome message for channels goes here
			if (this.channelID == 0)
				this.addChatBotMessageToChatList('Welcome to channel 0. Please follow the rules.');
			if (this.channelID == 1)
				this.addChatBotMessageToChatList('Welcome to channel 1. Nobody follows the rules here!');
			//That's it.
			break;
		case 'userID':
			this.userID = infoData;
			break;
		case 'userName':
			this.userName = infoData;
			this.encodedUserName = this.scriptLinkEncode(this.userName);
			this.userNodeString = null;
			break;
		case 'userRole':
			this.userRole = infoData;
			break;
		case 'logout':
			this.handleLogout(infoData);
			return;
		case 'socketRegistrationID':
			this.socketRegistrationID = infoData;
			this.socketRegister();
		default:
			this.handleCustomInfoMessage(infoType, infoData);
	}
}

Version 0.8.8 +

In version 0.8.8 the handleCustomInfoMessage function has been changed to make this mod easier. If you are using AJAX Chat 0.8.8 or above you should put this code in your custom.js instead of the code above.

// Announce Channel Information
// Return true to override built-in info message processing, return false to use your override and skip the built in handler
ajaxChat.handleCustomInfoMessage = function(infoType, infoData) {
	switch(infoType) {
		case 'channelID':
			this.channelID = infoData;
			if (this.channelID == 0)
				this.addChatBotMessageToChatList('Welcome to channel 0. Please follow the rules.');
			if (this.channelID == 1)
				this.addChatBotMessageToChatList('Welcome to channel 1. Nobody follows the rules here!');
			return true;
		default:
			return false;
	}
}
Clone this wiki locally