Add Verse API functions for Text Chat

I would love to see subscribable events for messages sent in text chat with the option to cancel the default action.

For example:

MessageSentEvent<public>():listenable(TempMessage : message_payload)

GetPlayspace().MessageSentEvent().Subscribe(HandleMessage)

SplitString(TempString : string, TargetChar : char)<suspends> : [][]string =

        var WorkingString : string = TempString
        var SplitStrings : [][]string = array{}

        loop:
            if(TempIndex := WorkingString.Find[TargetChar]):
                if(SubString := WorkingString.Slice[0, TempIndex]):
                    set SplitStrings = SplitStrings + array{array{SubString}}
                    if(RemainingString := SubString.RemoveFirstElement[TargetChar]):
                        set WorkingString = RemainingString
            else:
                break

            Sleep(0.0)

        return SplitStrings

PlayerSentMessage(TempMessage : message_payload)<suspends> : void =
    SendingPlayer := TempMessage.GetAgent()
    TempStringMessage := TempMessage.GetMessage()

    if(FirstByte := TempStringMessage[0]):
        if(FirstByte = "/"): #Is a text command

             CommandArgs := SplitString(TempStringMessage, " ")

            #Cancel the message from reaching chat
            if(TempMessage.PreventDefaultAction[]):
                Print("Debug: Message was unsent!")
            else:
                Print("Debug: Couldn't unsend message :(.")

            #Handle a / command
            DoPlayerCommand(SendingPlayer, CommandsArgs)

HandleMessage(TempMessage : message_payload) : void =
    spawn:
        PlayerSentMessage(TempMessage)

Some other nice to haves:

ServerWideMessage(ChatMessage : string) #Sends a server wide message to chat
SendPlayerMessage(InPlayer : agent, ChatMessage : string) #Send a message to specific players chat only visible to them

Given the above:
Ability to change the font color
Ability to create a ‘Hyper-Link’ in chat that when clicked triggers an event (More like clickable text really)

For example You send a link to chat that another function has subscribed to the ClickedEvent() and will say open a dialog or teleport or player etc.

@Nman_Pkr Thank you for your feedback. While I cannot guarantee a response, I can confirm that this has been forwarded to the appropriate team.

1 Like