Techy5's new colored chat CSM

teenspirit
Member
 
Posts: 154
Joined: Wed Apr 05, 2017 11:47
In-game: darianbrown

Techy5's new colored chat CSM

by teenspirit » Fri Dec 01, 2017 06:16

I am writing about Techy5's new colored chat CSM for him. He made it for my request, so least i could do. It allows you to set custom colors for certain players chat. You can set a custom color with .setcolor username color (hex or standard color names like red, pink, purple, etc.) You can remove someone's custom color with .delcolor playername. You can see a list of all the people you have added colors for and their colors with .listcolors. He did an awesome job so far, though he says it is still WIP, and may have bugs. here is his code so far for the CSM:
Code: Select all
local data = minetest.get_mod_storage()
local dColor = "#00FF00"
 
local chatSource = function(msg) -- Find out who was talking to us
    if string.sub(msg, 1, 1) == "<" then -- Normal messages
        local parts = string.split(msg, ">") -- Split it at the closing >
        return string.sub(parts[1], 2, string.len(parts[1])) -- Return the first part minus the first character
    elseif string.sub(msg, 1, 2) == "* " then -- /me messages
        local parts = string.split(msg, " ") -- Split the message before and after the name
        return parts[2] -- Return the name (this one is easy)
    end
    return false -- If nothing else returned, return false
end
 
minetest.register_chatcommand("setcolor", { -- Assign a colour to chat messages from a specific person
    params = "<name> <color>",
    description = "Colourize a specified player's chat messages",
    func = function(param)
        local args = string.split(param, " ") -- Split up the arguments
        local setName = "player_" .. args[1] -- The setting name to set
        local color = args[2]
        if not color then -- If a color was not specified, use the default color.
            color = dColor
        end
        data:set_string(setName, color)
        minetest.display_chat_message("Player color set sucessfully!")
    end
})
 
minetest.register_chatcommand("delcolor", {
    params = "<name>",
    description = "Set a specified player's chat messages to the default colour",
    func = function(param)
        local setName = "player_" .. param
        data:set_string(setName, nil) -- Set the color as blank
        minetest.display_chat_message("Player color set sucessfully!")
    end
})
 
minetest.register_chatcommand("listcolors", {
    params = "",
    description = "List player/colour pairs",
    func = function(param)
        local list = data:to_table().fields
        for key,value in pairs(list) do
            if string.sub(key, 1, 7) == "player_" then
                key = string.sub(key, 8, string.len(key))
            end
            minetest.display_chat_message(key .. ", " .. minetest.colorize(value, value))
        end
    end
})
 
minetest.register_on_connect(function()
    minetest.register_on_receiving_chat_messages(function(message)
        local msgPlain = minetest.strip_colors(message)
        local source = chatSource(msgPlain)
       
        if not source then -- If the chat was not from a player, return
            return
        end
       
        local playerSet = "player_" .. source -- The setting name
        local color = data:get_string(playerSet) -- Get the desired color
        if color == "" then -- If no color, return
            return
        end
       
        message = minetest.colorize(color, msgPlain)
        minetest.display_chat_message(message)
        return true
    end)
end)


He is definitely open to help and suggestions, and would greatly appreciate the bug finders and fixers who might want to help out.

To install a CSM, you should navigate to you minetest directory, create a folder called "clientmods", create a second folder within that is called "colored_chat", and also in the clientmods directory, create a mods.conf file, and make line 1 say "load_mod_colored_chat = true", and line 2 say "load_mod_preview = false". Save this file as mods.conf. Then go into your colored_chat directory within the clientmods directory, and make a file called "init.lua". Copy and paste the code into it, and save it. Then go to settings, search "client", you will see "Client modding", set that to Enabled. After that you are all set to have custom colored chat!
 

User avatar
philipbenr
Member
 
Posts: 1688
Joined: Fri Jun 14, 2013 01:56
Location: United States
GitHub: philipbenr
IRC: philipbenr
In-game: robinspi

Re: Techy5's new colored chat CSM

by philipbenr » Fri Dec 01, 2017 07:01

I believe that you might want to have posted this in this subforum: viewforum.php?f=53

If you want to make a request to move it, go ahead and write post in this thread: viewtopic.php?f=11&t=10418

Edit: It might be a good idea to ask him what license he wants to give to his work too.
 

User avatar
rubenwardy
Moderator
 
Posts: 5455
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Techy5's new colored chat CSM

by rubenwardy » Fri Dec 01, 2017 09:28

Very nice! What license?

A note to Techy5: if you wanted to post this topic instead, I can change the owner of this topic
 

teenspirit
Member
 
Posts: 154
Joined: Wed Apr 05, 2017 11:47
In-game: darianbrown

Re: Techy5's new colored chat CSM

by teenspirit » Fri Dec 01, 2017 13:33

Techy5 prefers anonymity, he only sent me the code via pastebucket because it was anonymous. He is looking at the forum, but he will not join with an account i don't think. As for license, I will ask him next time i see him how he wants to license the CSM.
 

User avatar
sorcerykid
Member
 
Posts: 835
Joined: Fri Aug 26, 2016 15:36
Location: Illinois, USA
GitHub: sorcerykid
In-game: Nemo

Re: Techy5's new colored chat CSM

by sorcerykid » Sun Dec 10, 2017 14:43

rubenwardy wrote:Very nice! What license?

A note to Techy5: if you wanted to post this topic instead, I can change the owner of this topic


???

For the past 12 months I've been submitting questions (even PMing moderators) requesting a change to the author of my server topic, since maikerumine transferred ownership to me last December. My requests have always gone unanswered. And other users have said it simply can't be done. How come now it is suddenly possible?
 

User avatar
rubenwardy
Moderator
 
Posts: 5455
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Techy5's new colored chat CSM

by rubenwardy » Sun Dec 10, 2017 14:56

sorcerykid wrote:For the past 12 months I've been submitting questions (even PMing moderators) requesting a change to the author of my server topic, since maikerumine transferred ownership to me last December. My requests have always gone unanswered. And other users have said it simply can't be done. How come now it is suddenly possible?


Have you tried reporting the opening post you want to change, with some proof that maikerumine transferred ownership?

It's also possible that the moderator that saw your requests didn't know it was possible
 


Return to Client-side modding



Who is online

Users browsing this forum: No registered users and 1 guest