a script for mudlet to setup channel specific chat modes

in #programming4 years ago

This script allows you to change where your command text is sent based on defined channels (it works really well with a tabbed chat window)

local Chats = {
  "New",
  "Pub",
  "OOC",
  "Auction",
  "Update"
}
SelectedMode = "None"
changeCMDInput = false
--capture chat line and prepend channel to beginning
function controlInput(_, command)
    if changeCMDInput and SelectedMode ~= "None" then
        changeCMDInput = false --set this if check to false to it doesn't occur every input
        --Also set the bool check BEFORE any send() functions within a sysDataSendRequest function
        send(SelectedMode .. " " .. command, false) --Duplicate and unknown command
        denyCurrentSend() --Deny the original command, not the commands sent with sendAll.
        changeCMDInput = true
    end
end
--remove the chat redirection
function UnregisterChatHandler()
    killAnonymousEventHandler(myevent)
end
--enable speaking only in selected channel mode
function SetChatMode(ModeToSet)
    if (table.contains(Chats, ModeToSet)) then
        SelectedMode = ModeToSet
    else
        SelectedMode = "None"
    end
    changeCMDInput = true
end
--setup the chat
function SetupChatMode()
    --generate aliases for all enabled chats
    for k, v in pairs(Chats) do
        local realCode = 'SetChatMode("' .. v .. '")'
        local StringToCheck = "^" .. "SetChatModeTo" .. v .. "$"
        tempAlias(StringToCheck, realCode)
    end
    --setup the disable and removal aliases
    tempAlias("^setChatModeToNone$", [[SetChatMode("None")]])
    tempAlias("^RemoveChatMode$", [[UnregisterChatHandler()]])
    --register the chat redirection event
    myevent = myevent or registerAnonymousEventHandler("sysDataSendRequest", "controlInput")
end
Sort:  

Great works man. Thanks for sharing

Your post has been submitted to be manually curated by @gitplait community account because this is the kind of publications we like to see in our community.

Join our Community on Hive and Chat with us on Discord.

[Gitplait-Team]

What suprised me the most was that I was able to "construct" regex strings manually before passing them to the function