summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--depends.txt1
-rw-r--r--init.lua121
2 files changed, 71 insertions, 51 deletions
diff --git a/depends.txt b/depends.txt
index 20efb18..e69de29 100644
--- a/depends.txt
+++ b/depends.txt
@@ -1 +0,0 @@
-irc?
diff --git a/init.lua b/init.lua
index 4b6cccf..f6a2fda 100644
--- a/init.lua
+++ b/init.lua
@@ -1,3 +1,8 @@
+chat6 = {}
+chat6.message_normal = "normal"
+chat6.message_action = "action"
+chat6.message_private = "private"
+
local nick_colors = {
"#4E9A06", --19
"#CC0000", --20
@@ -19,49 +24,77 @@ local function get_nick_color(nick)
return(nick_colors[color+1])
end
-minetest.register_on_chat_message(function(fromname,msg)
- local outgoingnick = minetest.setting_get("chat6.outgoing_nick_color") or "#CC0000"
- local outgoingmsg = minetest.setting_get("chat6.outgoing_message_color") or "#CCCCCC"
- local highlight = minetest.setting_get("chat6.highlight_color") or "#4E9A06"
- local players = minetest.get_connected_players()
- for _,player in pairs(players) do
- local toname = player:get_player_name()
- if toname == fromname then
- local colorednick = minetest.colorize(outgoingnick,fromname)
- local coloredmessage = minetest.colorize(outgoingmsg,msg)
- minetest.chat_send_player(toname,string.format("<%s> %s",colorednick,coloredmessage))
- elseif string.find(msg,toname) then
- local colorednick = minetest.colorize(highlight,fromname)
- local coloredmessage = minetest.colorize(highlight,msg)
- minetest.chat_send_player(toname,string.format("<%s> %s",colorednick,coloredmessage))
- else
- local colorednick = minetest.colorize(get_nick_color(fromname),fromname)
- minetest.chat_send_player(toname,string.format("<%s> %s",colorednick,msg))
+function chat6.send_colored_message(fromname,msg,toname,msgtype)
+ if msgtype == chat6.message_private then
+ local highlight = minetest.setting_get("chat6.highlight_color") or "#4E9A06"
+ if (not toname) or (not msg) then
+ minetest.chat_send_player(fromname,minetest.colorize("#FF0000","Error")..": Player name or message missing")
+ return false
+ end
+ if not minetest.get_player_by_name(toname) then
+ minetest.chat_send_player(fromname,minetest.colorize("#FF0000","Error")..": Target player is not online")
+ return false
+ end
+ local colorednick = minetest.colorize(highlight,fromname)
+ local coloredmessage = minetest.colorize(highlight,message)
+ minetest.chat_send_player(fromname,"Message sent.")
+ minetest.chat_send_player(toname,string.format("PM from %s: %s",fromname,coloredmessage))
+ elseif msgtype == chat6.message_action then
+ local outgoingnick = minetest.setting_get("chat6.outgoing_nick_color") or "#CC0000"
+ local outgoingmsg = minetest.setting_get("chat6.outgoing_message_color") or "#CCCCCC"
+ local highlight = minetest.setting_get("chat6.highlight_color") or "#4E9A06"
+ local players = minetest.get_connected_players()
+ for _,player in pairs(players) do
+ local toname = player:get_player_name()
+ if toname == fromname then
+ local colorednick = minetest.colorize(outgoingnick,fromname)
+ local coloredmessage = minetest.colorize(outgoingmsg,msg)
+ minetest.chat_send_player(toname,string.format("* %s %s",colorednick,coloredmessage))
+ elseif string.find(msg,toname) then
+ local colorednick = minetest.colorize(highlight,fromname)
+ local coloredmessage = minetest.colorize(highlight,msg)
+ minetest.chat_send_player(toname,string.format("* %s %s",colorednick,coloredmessage))
+ else
+ local colorednick = minetest.colorize(get_nick_color(fromname),fromname)
+ minetest.chat_send_player(toname,string.format("* %s %s",colorednick,msg))
+ end
+ end
+ else
+ local outgoingnick = minetest.setting_get("chat6.outgoing_nick_color") or "#CC0000"
+ local outgoingmsg = minetest.setting_get("chat6.outgoing_message_color") or "#CCCCCC"
+ local highlight = minetest.setting_get("chat6.highlight_color") or "#4E9A06"
+ local players = minetest.get_connected_players()
+ for _,player in pairs(players) do
+ local toname = player:get_player_name()
+ if toname == fromname then
+ local colorednick = minetest.colorize(outgoingnick,fromname)
+ local coloredmessage = minetest.colorize(outgoingmsg,msg)
+ minetest.chat_send_player(toname,string.format("<%s> %s",colorednick,coloredmessage))
+ elseif string.find(msg,toname) then
+ local colorednick = minetest.colorize(highlight,fromname)
+ local coloredmessage = minetest.colorize(highlight,msg)
+ minetest.chat_send_player(toname,string.format("<%s> %s",colorednick,coloredmessage))
+ else
+ local colorednick = minetest.colorize(get_nick_color(fromname),fromname)
+ minetest.chat_send_player(toname,string.format("<%s> %s",colorednick,msg))
+ end
end
end
+end
+
+minetest.register_on_chat_message(function(fromname,msg)
+ if string.sub(msg,1,1) == "/" then
+ return false
+ end
+ chat6.send_colored_message(fromname,msg,nil,chat6.message_normal)
+ if minetest.get_modpath("irc") then
+ irc:say(string.format("<%s> %s",fromname,msg))
+ end
return true
end)
minetest.override_chatcommand("me",{func=function(fromname,msg)
- local outgoingnick = minetest.setting_get("chat6.outgoing_nick_color") or "#CC0000"
- local outgoingmsg = minetest.setting_get("chat6.outgoing_message_color") or "#CCCCCC"
- local highlight = minetest.setting_get("chat6.highlight_color") or "#4E9A06"
- local players = minetest.get_connected_players()
- for _,player in pairs(players) do
- local toname = player:get_player_name()
- if toname == fromname then
- local colorednick = minetest.colorize(outgoingnick,fromname)
- local coloredmessage = minetest.colorize(outgoingmsg,msg)
- minetest.chat_send_player(toname,string.format("* %s %s",colorednick,coloredmessage))
- elseif string.find(msg,toname) then
- local colorednick = minetest.colorize(highlight,fromname)
- local coloredmessage = minetest.colorize(highlight,msg)
- minetest.chat_send_player(toname,string.format("* %s %s",colorednick,coloredmessage))
- else
- local colorednick = minetest.colorize(get_nick_color(fromname),fromname)
- minetest.chat_send_player(toname,string.format("* %s %s",colorednick,msg))
- end
- end
+ chat6.send_colored_message(fromname,msg,nil,chat6.message_action)
if minetest.get_modpath("irc") then
irc:say(string.format("* %s %s",fromname,msg))
end
@@ -69,19 +102,7 @@ minetest.override_chatcommand("me",{func=function(fromname,msg)
end})
minetest.override_chatcommand("msg",{func=function(fromname,msg)
- local highlight = minetest.setting_get("chat6.highlight_color") or "#4E9A06"
local toname, message = msg:match("^(%S+)%s(.+)$")
- if (not toname) or (not msg) then
- minetest.chat_send_player(fromname,minetest.colorize("#FF0000","Error")..": Player name or message missing")
- return false
- end
- if not minetest.get_player_by_name(toname) then
- minetest.chat_send_player(fromname,minetest.colorize("#FF0000","Error")..": Target player is not online")
- return false
- end
- local colorednick = minetest.colorize(highlight,fromname)
- local coloredmessage = minetest.colorize(highlight,message)
- minetest.chat_send_player(fromname,"Message sent.")
- minetest.chat_send_player(toname,string.format("PM from %s: %s",fromname,coloredmessage))
+ chat6.send_colored_message(fromname,message,toname,chat6.message_private)
return true
end})