Over the next few months, we will be looking into overhauling the current chat system by adding new functionality, updating the UI, and exposing the underlying systems more to developers. Today, I’m here to release a beta version of this new chat script for the members of the developer forums to test and play around with as they please.
Please do note however, this is not the final product and could potentially change before the final release. Not all features may work as expected (mainly client sided ones).
tl;dr: New really cool chat stuff. Links to try it out at the bottom.
##Main Features
-
New API!
Chat channels, chat bots, speaking permissions, custom data setting, etc. -
New updated UI!
-
Entirely implemented in Lua!
-
Installs like ControlScript and CameraScript!
We wanted this system to be able to be modified like the current ControlScript and CameraScript, so developers could tweak it to their exact liking. For more details, see the installation section.
##Installation / How It Works
There are three components to this new chat system. The server side, the client side, and the chat modules. During runtime, three objects are created and inserted into various places in the datamodel unless pre-existing objects with their specified names are present. This is just like how the ControlScript and CameraScript work.
These objects are:
1. ChatServiceRunner, a Script that will be parented to ServerScriptService.
2. ChatModules, a Folder that will be parented to ServerStorage.
3. ChatScript, a LocalScript that will be parented to StarterPlayerScripts in StarterPlayer.
In addition, ChatServiceRunner will create a folder called ChatEvents to be parented to ReplicatedStorage for RemoteEvent/RemoteFunction communications across client and server.
##Documentation
###ChatService
This is the main singleton object that runs the server sided chat service. It manages both ChatChannels and Speakers.
Methods
ChatChannel AddChannel(string channelName)
void RemoveChannel(string channelName)
ChatChannel GetChannel(string channelName)
Speaker AddSpeaker(string speakerName)
void RemoveSpeaker(string speakerName)
Speaker GetSpeaker(string speakerName)
string[] GetChannelList()
string[] GetAutoJoinChannelList()
void RegisterFilterMessageFunction(string functionId, function func)
void UnregisterFilterMessageFunction(string functionId)
void RegisterProcessCommandsFunction(string functionId, function func)
void UnregisterProcessCommandsFunction(string functionId)
Events
ChannelAdded(string channelName)
ChannelRemoved(string channelName)
SpeakerAdded(string speakerName)
SpeakerRemoved(string speakerName)
###ChatChannel
A ChatChannel is an object that stores data about a single channel that Speakers can chat in. The ChatChannel manages a list of Speakers currently in the channel for relaying messages between them, and also comes with some access permission properties.
Properties
string Name (read-only)
string WelcomeMessage
bool Joinable
bool Leavable
bool AutoJoin
bool Private
Methods
void RegisterFilterMessageFunction(string functionId, function func)
void UnregisterFilterMessageFunction(string functionId)
void RegisterProcessCommandsFunction(string functionId, function func)
void UnregisterProcessCommandsFunction(string functionId)
void KickSpeaker(string speakerName, string reason)
void MuteSpeaker(string speakerName, string reason, int length)
void UnmuteSpeaker(string speakerName)
bool IsSpeakerMuted(string speakerName)
string[] GetSpeakerList()
void SendSystemMessage(string message)
Events
MessagePosted(string fromSpeaker, string message)
SpeakerJoined(string speakerName)
SpeakerLeft(string speakerName)
SpeakerMuted(string speakerName, string reason, int length)
SpeakerUnmuted(string speakerName)
###Speaker
A Speaker object is a representation of one entity that can speak in a ChatChannel. A Speaker can be a Player, or it can be a chat bot that is run and managed by code.
Properties
string Name (read-only)
Methods
void SayMessage(string message, string channelName)
void JoinChannel(string channelName)
void LeaveChannel(string channelName)
string[] GetChannelList()
bool IsInChannel(string channelName)
void SendMessage(string fromSpeaker, string channel, string message)
void SendSystemMessage(string message, string channel)
Player GetPlayerObject() (returns nil for non-player speakers)
void SetExtraData(string key, Variant data)
Variant GetExtraData(string key)
Events
SaidMessage(string message, string channelName)
ReceivedMessage(string fromSpeaker, string channel, string message)
ReceivedSystemMessage(string message, string channel)
ChannelJoined(string channelName, string channelWelcomeMessage)
ChannelLeft(string channelName)
Muted(string channelName, string reason, int length)
Unmuted(string channelName)
ExtraDataUpdated(string key, Variant value)
##All About Chat Modules
Chat Modules are a system in designed to have code interface with the server sided ChatService without having to directly modify the code internally. At runtime, ChatServiceRunner looks through all the children of the ChatModules folder, and for every child that is a ModuleScript, it requires them. These modules are expected to return a single function (not a function call) that will be passed a reference to ChatService for those modules to call methods on. In addition, any child that is later added to this folder during runtime after the initial parse of children will be processed in this way as well.
The idea of implementing chat modules this way, is that developers will not need to overwrite ChatServiceRunner in their game, and updates will be able to be pushed to it when necessary instead of having to let developers know so they can download the new version and then make the appropriate changes to it again to make it work in the way they want it to. Of course, if developers want to create some radically different ChatServiceRunner and ChatService for their game, there is nothing stopping them from doing so and I would not discourage it. ChatModules are to be thought of as Add-Ons to the current system whereas overwriting ChatServiceRunner would be creating your own.
Also, be sure to check out the default chat modules as examples of how to make your own.
##Client Sided Chat Window
The client sided chat window is designed for developers to be able to overwrite and create their own custom look. The main point of interest is the ModuleScript called MessageLabelCreator, where all the logic for parsing text messages into a collection of GuiObjects exist. Developers can easily change the logic in this module to get some pretty cool effects such as buttons in messages that could be clicked to initiate trades with a player, special clan or VIP tags for speakers, color changing text, etc.
##Downloads
Since this is just a developer forum early access test release, this system will not automatically install into places, and you’ll have to insert it yourself. When it goes live, all places will start to have these scripts created in them if they are not found already.
You can find an uncopylocked test place here.
You can download a model file here: NewChat.rbxmx (142.1 KB)
Or you can download a test place file here: New Chat Demo Place.rbxl (53.1 KB)
##Known Issues
- Channel tab names aren’t shortened properly with trailing …'s.
- Chat window doesn’t respect Bubble Chat only settings. (Non issue for this release however)
- Clicking on a player’s name to private message currently does nothing.
- Spam filter / flood check is non-existent.
In addition, some debug text is left in the code, which may be confusing if you go reading through all of it.
Please remember to leave feedback about your experience using this new system. The main reason for this release is to get community feedback on things you liked, things you didn’t like, features you want built in, and anything else really.
Please try to create cool things with it and let us know about any frustrating aspects of doing so. We want to make this system as accessible and easy to use as possible.