From 9abe5998c3ea013f71d1c9c2c4cd2692029e5139 Mon Sep 17 00:00:00 2001 From: cheapie Date: Mon, 27 Mar 2017 13:49:42 -0500 Subject: Add timestamp support --- init.lua | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/init.lua b/init.lua index e6f4c1f..0abd7b8 100644 --- a/init.lua +++ b/init.lua @@ -2,6 +2,7 @@ local player_name = "cheapie" local highlight_color = "#4E9A06" local send_nick_color = "#A40000" local send_message_color = "#888A85" +local timestamps = true local nick_colors = { "#4E9A06", --19 @@ -30,6 +31,11 @@ minetest.register_on_receiving_chat_messages(function(message) local msgtype local user local text + local timestamp = "" + if timestamps then + local date = os.date("*t",os.time()) + timestamp = string.format("[%02d:%02d:%02d] ",date.hour,date.min,date.sec) + end if string.sub(message,1,1) == "<" then msgtype = "channel" user,text = string.match(message,"^<(%g*)> (.*)$") @@ -64,31 +70,31 @@ minetest.register_on_receiving_chat_messages(function(message) text = message end if msgtype == "special" then - minetest.display_chat_message(text) + minetest.display_chat_message(timestamp..text) elseif msgtype == "joined" then local coloredmsg = minetest.colorize("#CE5C00",string.format("* %s has joined",user)) - minetest.display_chat_message(coloredmsg) + minetest.display_chat_message(timestamp..coloredmsg) elseif msgtype == "left" then local coloredmsg = minetest.colorize("#C4A000",string.format("* %s has quit %s",user,text)) - minetest.display_chat_message(coloredmsg) + minetest.display_chat_message(timestamp..coloredmsg) elseif msgtype == "channel" then local colorednick = minetest.colorize(get_nick_color(user),user) - minetest.display_chat_message(string.format("<%s> %s",colorednick,text)) + minetest.display_chat_message(timestamp..string.format("<%s> %s",colorednick,text)) elseif msgtype == "action" then local colorednick = minetest.colorize(get_nick_color(user),user) - minetest.display_chat_message(string.format("* %s %s",colorednick,text)) + minetest.display_chat_message(timestamp..string.format("* %s %s",colorednick,text)) elseif msgtype == "sent_channel" then local colorednick = minetest.colorize(send_nick_color,user) local coloredtext = minetest.colorize(send_message_color,text) - minetest.display_chat_message(string.format("<%s> %s",colorednick,coloredtext)) + minetest.display_chat_message(timestamp..string.format("<%s> %s",colorednick,coloredtext)) elseif msgtype == "sent_action" then local colorednick = minetest.colorize(send_nick_color,user) local coloredtext = minetest.colorize(send_message_color,text) - minetest.display_chat_message(string.format("* %s %s",colorednick,coloredtext)) + minetest.display_chat_message(timestamp..string.format("* %s %s",colorednick,coloredtext)) elseif msgtype == "highlight_channel" then - minetest.display_chat_message(minetest.colorize(highlight_color,string.format("<%s> %s",user,text))) + minetest.display_chat_message(timestamp..minetest.colorize(highlight_color,string.format("<%s> %s",user,text))) elseif msgtype == "highlight_action" then - minetest.display_chat_message(minetest.colorize(highlight_color,string.format("* %s %s",user,text))) + minetest.display_chat_message(timestamp..minetest.colorize(highlight_color,string.format("* %s %s",user,text))) end return true end) -- cgit v1.2.3