From 25696a8e9a40fdb9b9cff5e16d37bd33d0406259 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Mon, 26 Aug 2013 13:25:06 -0400 Subject: [PATCH] Add better support for multiple servers and remove format_in/format_out --- README.txt | 32 ------------------------------- src/callback.lua | 3 ++- src/config.lua | 8 -------- src/hooks.lua | 49 +++++++++++++++++++++++++++++------------------- src/messages.lua | 7 +++---- 5 files changed, 35 insertions(+), 64 deletions(-) diff --git a/README.txt b/README.txt index 619ad36..647fcf2 100644 --- a/README.txt +++ b/README.txt @@ -88,38 +88,6 @@ All settings are changed in 'minetest.conf'. If any of these settings irc.SASLUser (string, default irc.nick) The SASL username. This should normaly be set to your main NickServ account name. - irc.format_out (string, default "<$(name)> $(message)") - This specifies how to send the messages from in-game to IRC. - The strings can contain "macros" (or variable substitutions), which - are specified as "$(macro_name)". - Currently, these macros are supported: - $(name) The name of the player sending the message. - $(message) The actual message text. - Any unrecognized macro will be left in the message verbatim. - For example, if a user named "mtuser" is saying "Hello!", then: - "<$(name)> $(message)" - ...will yield... - " Hello!" - ...and... - "$(name): $(message) $(xyz)" - ...will yield... - "mtuser: Hello! $(xyz)" - - irc.format_in (string, - default "<$(name)@IRC> $(message)") - This specifies how the messages gotten from the IRC channel are - displayed in-game. - The strings can contain "macros" (or variable substitutions), which - are specified as "$(macro_name)". - Currently, these macros are supported: - $(name) The nickname of the user sending the message. - $(message) The actual message text. - $(server) The IRC server. - $(port) The IRC server port. - $(channel) The IRC channel. - In the default configuration, this will yield: - Hello! - irc.debug (boolean, default false) Whether to output debug information. diff --git a/src/callback.lua b/src/callback.lua index 4a0d2ab..0104f7a 100644 --- a/src/callback.lua +++ b/src/callback.lua @@ -25,7 +25,8 @@ minetest.register_on_chat_message(function(name, message) or (not minetest.check_player_privs(name, {shout=true})) then return end - mt_irc:queueMsg(mt_irc.msgs.playerMessage(mt_irc.config.channel, name, message)) + mt_irc:queueMsg(mt_irc.msgs.playerMessage( + mt_irc.config.channel, name, message)) end) diff --git a/src/config.lua b/src/config.lua index 0dd5bf8..0860608 100644 --- a/src/config.lua +++ b/src/config.lua @@ -54,14 +54,6 @@ config.timeout = tonumber(minetest.setting_get("irc.timeout")) or 60.0 config.command_prefix = minetest.setting_get("irc.command_prefix") or '!' config.command_prefix = config.command_prefix:sub(1, 1) --- The format of messages sent to IRC server (string, default "<$(name)> $(message)") --- See `README.txt' for the macros supported here. -config.format_out = minetest.setting_get("irc.format_out") or "<$(name)> $(message)" - --- The format of messages sent to IRC server (string, default "<$(name)@IRC> $(message)") --- See `README.txt' for the macros supported here. -config.format_in = minetest.setting_get("irc.format_in") or "<$(name)@IRC> $(message)" - -- Enable debug output (boolean, default false) config.debug = minetest.setting_getbool("irc.debug") diff --git a/src/hooks.lua b/src/hooks.lua index e5e3bca..c14b2de 100644 --- a/src/hooks.lua +++ b/src/hooks.lua @@ -55,16 +55,34 @@ end function mt_irc.hooks.channelChat(user, channel, message) - local t = { - access=user.access, - name=user.nick, - message=message, - server=mt_irc.conn.host, - port=mt_irc.conn.port, - channel=channel - } - local text = mt_irc.config.format_in:expandvars(t) - mt_irc:sendLocal(text) + -- Support multiple servers in a channel better by converting: + -- " message" into " message" + -- " *** player joined/left the game" into "*** player@server joined/left the game" + -- and " * player orders a pizza" into "* player@server orders a pizza" + local foundchat, _, chatnick, chatmessage + = message:find("^<([^>]+)> (.*)$") + local foundjoin, _, joinnick + = message:find("^%*%*%* ([^%s]+) joined the game$") + local foundleave, _, leavenick + = message:find("^%*%*%* ([^%s]+) left the game$") + local foundaction, _, actionnick, actionmessage + = message:find("^%* ([^%s]+) (.*)$") + + if foundchat then + mt_irc:sendLocal(("<%s@%s> %s") + :format(chatnick, user.nick, chatmessage)) + elseif foundjoin then + mt_irc:sendLocal(("*** %s@%s joined the game") + :format(joinnick, user.nick)) + elseif foundleave then + mt_irc:sendLocal(("*** %s@%s left the game") + :format(leavenick, user.nick)) + elseif foundaction then + mt_irc:sendLocal(("* %s@%s %s") + :format(actionnick, user.nick, actionmessage)) + else + mt_irc:sendLocal(("<%s@IRC> %s"):format(user.nick, message)) + end end @@ -80,15 +98,8 @@ function mt_irc.hooks.pm(user, message) mt_irc:say(user.nick, "User '"..player_to.."' is not in the game.") return end - local t = { - name=user.nick, - message=message, - server=mt_irc.server, - port=mt_irc.port, - channel=mt_irc.channel - } - local text = mt_irc.config.format_in:expandvars(t) - minetest.chat_send_player(player_to, "PM: "..text, false) + minetest.chat_send_player(player_to, + "PM from "..user.nick.."@IRC: "..message, false) mt_irc:say(user.nick, "Message sent!") elseif message:sub(1, 1) == "!" then mt_irc:bot_command(user, message:sub(2)) diff --git a/src/messages.lua b/src/messages.lua index 4e01b83..b37ac2a 100644 --- a/src/messages.lua +++ b/src/messages.lua @@ -32,9 +32,8 @@ function mt_irc.msgs.action(to, message) end function mt_irc.msgs.playerMessage(to, name, message) - local t = {name=name, message=message} - local text = mt_irc.config.format_out:expandvars(t) - return mt_irc.msgs.privmsg(to, text) + return mt_irc.msgs.privmsg(to, ("<%s> %s"):format(name, message)) end + -- TODO Add more message types --- +